My first Stepper motor sketch

I’m new in the use of the Arduino Uno Microcontroller. I got the Uno talking to my computer after a few tries, and went to the Blink sketch to blink the onboard Led, it worked. I tried other self written sketches and they worked as will. I know that there are stepper motor control sketches in the Arduino library but I needed something a little different. What I’m doing is rotating an object 36º and stopping for X time delay, the time delay is set by an analog input on A0. I connected a 10 turn 2k pot across the onboard 5v pin. I did a map to get 0 to above 13 sec time delay. I can’t believe it works. I set it up to line printout of the I/O bits (0-1023) and the delay time, that worked also. I connected the four stepper drive pins to Leds and they work. Now I’m started to build the unipolor stepper motor drive circuit. I will keep you up-to-date on my progress and post my sketch. I'm enjoying working with the Uno. First time user. John Mc. Mims, Fl

/* Stepper motor 200 pluses per rev. The stepper motoer wiil run for 36 Degs and stop for 5 seconds Turns on a coil for 25 milis , then off for 25 milis, repeatedly. I used the Blink shetch to run the stepper motor and the analog input shetch to get the delay time. john Mims, Fl. */ int sensorPin = A0; int STP1 = 8; // stepper 1 coil output int STP2 = 9; // stepper 2 coil output int STP3 = 10; // stepper 3 coil output int STP4 = 11; // stepper 4 coil output int sensorValue = 0; int mappedValue;

// the setup routine runs once when you press reset:

void setup() { // initialize the digital pin as an output. pinMode(STP1, OUTPUT); pinMode(STP2, OUTPUT); pinMode(STP3, OUTPUT); pinMode(STP4, OUTPUT); // initialize the serial port: Serial.begin(9600); }

void loop(){ //start the spepper motor turning to 36 deg. digitalWrite(STP1, HIGH); // turn the LED on (HIGH is the voltage level) delay(25); // wait for 25 milisecond digitalWrite(STP1, LOW); // turn the LED off by making the voltage LOW delay(25); // wait for 25 milisecond digitalWrite(STP2, HIGH); // turn the LED on (HIGH is the voltage level) delay(25); // wait for 25 milisecond digitalWrite(STP2, LOW); // turn the LED off by making the voltage LOW delay(25); // wait for 25 milisecond digitalWrite(STP3, HIGH); // turn the LED on (HIGH is the voltage level) delay(25); // wait for 25 milisecond digitalWrite(STP3, LOW); // turn the LED off by making the voltage LOW delay(25); // wait for 25 milisecond digitalWrite(STP4, HIGH); // turn the LED on (HIGH is the voltage level) delay(25); // wait for 25 milisecond digitalWrite(STP4, LOW); // turn the LED off by making the voltage LOW delay(25); // wait for 25 milisecond digitalWrite(STP4, HIGH); // turn the LED on (HIGH is the voltage level) delay(25); // wait for 25 milisecond digitalWrite(STP4, LOW); // turn the LED off by making the voltage LOW delay(25); // wait for 25 milisecond

I do the above 20 times to get 36 degs rotation.

sensorValue = analogRead(sensorPin); Serial.print("Time in 0 to 1023, bits, " ); Serial.println(sensorValue); mappedValue = map(sensorValue, 0, 1023, 0, 6000); mappedValue = (mappedValue*2); Serial.print("Time in milisec " ); Serial.println(mappedValue); delay(mappedValue); //Stop Stepper Motoer val time. }

Well done, the arduino is such a nice environment that things often work first time.