Stepper motors are the third option for generating rotational movement. They produce finely-stepped incremental rotations, typically 1.5º or less per step, which means if you count the number of steps to move, you can determine with reasonable accuracy just how much the output shaft has turned.
This is the type of motor used in almost all 3D printers today.
There are caveats: since steppers do not have position feedback, they may over/undershoot, especially when the load on the stepper is too great, or when inertia on a large flywheel stops it from braking properly. As such use steppers with this in mind, or implement some way to ‘reset’ the position – this is often called ‘homing’.
Speaking further into the foundation of stepper motor control will be beyond the scope of this studio. I suggest using the stepper in our studio as a very simple way of building slow-rotating contraptions that can spin in either direction.
Learn basics about stepper motors here.
For more general information on steppers refer to the Curated Links page.
In this recipe, designed specifically for the Photon, take extra caution with the power supplies. We need 12V to power the stepper circuit – a 8xAA battery pack will do, or better yet, get a wall-wart transformer to supply the 12V from the wall outlet. You NEVER want to connect this 12V into your Photon’s VIN/3V3, you will instantly destroy your Photon.
The same rules apply – check twice before testing your circuit.
In this example we are using a single pushbutton to trigger the stepper motor. The code is kept simple – each time the button is pushed, it calculates a randomised point from which to rotate the stepper position to.
Consider how this can be driven by external data, instead of the button push.
Don’t have buttons? Just two wires touching each other can simulate a button ‘press’, with the right code written for them. This should also give you some ideas on making your own simple ‘button’ sensors!
(learn how to import them in the Build IDE):