Week 10

Machine Building & End Effectors

Converting rotational motion to linear actuation: Building a wireless smart lock with stepper motors.

Why Stepper Motors?

Unlike standard DC motors, stepper motors move in precise, discrete steps. This allows for high holding torque and excellent positional accuracy without external feedback sensors—perfect for 3D printers, CNCs, and precision actuators.

01

Basic Control & Acceleration

Testing the DRV8834 Driver

Driver Circuit

DRV8834 Wiring Diagram

AccelStepper.ino

#include <AccelStepper.h>

const int stepPin = 13;
const int dirPin = 12;

// Init AccelStepper for 2-wire board
AccelStepper stepper(1, stepPin, dirPin); 

void loop() {
    if (stepper.distanceToGo() == 0) {
        // Randomize movement profile
        delay(1000);
        stepper.moveTo(rand() % 1000);
        stepper.setMaxSpeed((rand() % 1000) + 1);
        stepper.setAcceleration((rand() % 1000) + 1);
    }
    stepper.run();
}
                    

Mechanism Research

To build a door lock (deadbolt), I needed to convert the stepper's rotational motion into linear motion. I evaluated several mechanical linkages:

Slider Crank

Slider Crank

Scotch Yoke

Scotch Yoke

Crank & Slotted

Slotted Lever

Cam & Follower

Cam & Follower

Rack & Pinion

Rack & Pinion

Chosen Mechanism: Cam & Follower for its simplicity, strength, and precise locking action.

02

Project: IoT Smart Lock

Wireless Deadbolt Actuator

Fabrication

I 3D printed a custom cam follower and mounted the stepper assembly onto a base plate.

3D Print Mounting

Calibration & Logic

Steps Per Revolution: Through experimentation, I found that 180 steps yielded the optimal linear throw for the deadbolt.

Homing: On startup, the motor moves 220 steps to ensure the lock defaults to an open/safe state in case of power loss.


// Full Rotation (360 degrees) loop
for (int i = 0; i < 800; i++) {
    digitalWrite(stepPin, LOW);
    delay(1);
    digitalWrite(stepPin, HIGH); 
    delay(1);
}
                    

Homing Sequence

Lock Actuation

Full IoT Integration

Connecting back to the previous IoT unit, I integrated the lock with a web interface and the SMS alert system. This allows me to view the security camera feed and remotely lock/unlock the door via text message links.