A little stepper motor

I want to make a rotating 3D-printed head-on-a-spring for my podcast in a box (obviously). Last week I had a play with a tiny servo motor that Richard Sewell had given me ages ago, and discovered the difference between steppers, servos and DC motors. Servos can be modified to go all the way round – they don’t usually, as I found out last week – but modifying the 9g looked a bit hard. Meanwhile John Honniball kindly gave me a little Switec type stepper motor and some excellent links.

Getting it to work didn’t take too long – the code’s below, and there’s a simple Arduino library to make it work (on github) and some instructions to wire it up, including tips on getting the wires attached. I had to prise it apart to make it rotate continuously, but that was easy in this case (the one I had didn’t even have screws, just clips). I haven’t got a 3D-printed head yet, just a bit of wire, foil and foam sheet in its place (on a spring though).

Exciting video: https://www.flickr.com/photos/nicecupoftea/16759666917/

stepper

#include <SwitecX25.h>
 
// standard X25.168 range 315 degrees at 1/3 degree steps
#define STEPS (315*3)

SwitecX25 motor(STEPS, 4,5,6,7); 
int nLoops = 10;
int currentStep = 0;
int count = 0;
int state = 1;

void setup(void)
{
  Serial.begin(9600);
}
void loop() {
   char c = Serial.read();
   if(c == '0'){
     state = 0;
     Serial.println("stopped");
   }
   if(c == '1'){
     state = 1;
     Serial.println("started");
   }
   if(state == 1){
     motor.currentStep = 0;         // reset origin on each rotation 
     motor.setPosition(STEPS*2);    // set target to way past end of rotation
     while (motor.currentStep<STEPS-1){
       motor.update();  // turn until rotation is complete
     }
   }
}