HI,
I am new to c programming and arduino. I am building a project where I am required to synch a digital clock seconds with stepper motor. I am using a 28BYJ with driver board.
Is there anyone help me guide in right direction. I will be using a microswitch as a stepper home position. My question is, how do I integrate the stepper to synch with digital seconds. My digital seconds variable is tm_Seconds. So during the start up, I want the motor to find the home position which will be at 12 o clock mark. Then if should start stepping every certain number of steps per seconds in line with digital clock seconds.
According to my research this stepper should step 34.133 steps every seconds. i.e total of around 2048 steps in a minute.
Thank you heaps for your reply. So far I have the following code which makes the motor tick every seconds. It roughly does 60 ticks in 60 seconds. But i can always play around with number of steps to correct it.
Can you please have a look at the code and tell me how do I integrate a microswitch in it to find a home position every time i start the device. I will use a microswitch with a lever. Every time the seconds arm reaches 60 sec mark it will activate the microswitch lever there closing the switch. please ignore timer part of the code, I am just trying to generate 0 to 60 seconds to synch the motor. I have already code the digital clock code which works and i will integrate this motor code on it once it all starts working fine.
I have grayed out the home position part that I am not sure how to get it to work with this code yet.
#include <Stepper.h>
unsigned long time;
int seconds;
/-----( Declare Constants, Pin Numbers )-----/ #define STEPS 32 //Number of steps per revolution
Stepper small_stepper(STEPS, 11,9 , 10, 8);
int Steps2Take = 0;
int microswitch = 22; //pin for microswitch
int microswitchState;
seconds = time/1000;
Serial.print("seconds: ");
time = millis();
//prints time since program started
Serial.println(seconds);
// wait a second so as not to send massive amounts of data
delay(1000);
small_stepper.setSpeed(1000);
//Steps2Take = 34.133; // take 34.133 steps in one sec
if (seconds == 1)
Steps2Take = 36;
//if (seconds ==2)
//Steps2Take = 34;
//if (seconds == 3)
//Steps2Take = 34;
small_stepper.step(Steps2Take);
//delay(200);
}
/*void findHomePos() {//function to find home position of stepper motor
while(microswitchState == 0)
I didn't use code tag in previous post. so posting the code again.
thanks
Sarwan
Hi MarkT
Thank you heaps for your reply. So far I have the following code which makes the motor tick every seconds. It roughly does 60 ticks in 60 seconds. But i can always play around with number of steps to correct it.
Can you please have a look at the code and tell me how do I integrate a microswitch in it to find a home position every time i start the device. I will use a microswitch with a lever. Every time the seconds arm reaches 60 sec mark it will activate the microswitch lever there closing the switch. please ignore timer part of the code, I am just trying to generate 0 to 60 seconds to synch the motor. I have already code the digital clock code which works and i will integrate this motor code on it once it all starts working fine.
I have grayed out the home position part that I am not sure how to get it to work with this code yet.
#include <Stepper.h>
unsigned long time;
int seconds;
/*-----( Declare Constants, Pin Numbers )-----*/
#define STEPS 32 //Number of steps per revolution
Stepper small_stepper(STEPS, 11,9 , 10, 8);
int Steps2Take = 0;
int microswitch = 22; //pin for microswitch
int microswitchState;
void setup(){
Serial.begin(9600);
microswitchState = digitalRead(microswitch);
}
void loop()
{
seconds = time/1000;
Serial.print("seconds: ");
time = millis();
//prints time since program started
Serial.println(seconds);
// wait a second so as not to send massive amounts of data
delay(1000);
small_stepper.setSpeed(1000);
//Steps2Take = 34.133; // take 34.133 steps in one sec
if (seconds == 1)
Steps2Take = 36;
//if (seconds ==2)
//Steps2Take = 34;
//if (seconds == 3)
//Steps2Take = 34;
small_stepper.step(Steps2Take);
//delay(200);
}
/*void findHomePos() {//function to find home position of stepper motor
while(microswitchState == 0)
Steps2Take=2048;
small_stepper.step(Steps2Take);
Serial.println(microswitchState);
delay (2);
}*/