Go Down

### Topic: 28BYJ-48 stepper home position for clock sec arm (Read 87 times)previous topic - next topic

#### sarwan

##### May 18, 2017, 04:20 pm
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.

Hope to hear back with help.

thanks

#### MarkT

#1
##### May 18, 2017, 05:58 pm
Those motors are not exactly 2048 steps per revolution - google around and check this:
https://grahamwideman.wikispaces.com/Motors-+28BYJ-48+Stepper+motor+notes

Anyway, assuming a motor is N steps per revolution and you want it to turn once per minute, moving
every second:

Code: [Select]
`int diff = 0 ;void every_second (){  diff += N ;  while (diff > 0)  {    diff -= 60 ;    step_once () ;    delay (5) ; // allow time for motor  }}`
Which will work when N is not a multiple of 60
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

#### sarwan

#2
##### May 19, 2017, 02:01 am
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, ;
int  Steps2Take = 0;
int microswitch = 22; //pin for microswitch
int microswitchState;

void setup(){
Serial.begin(9600);
}
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);
}*/

#### sarwan

#3
##### May 19, 2017, 02:10 am
sorry MarkT,

I didn't use code tag in previous post. so posting the code again.

thanks
Sarwan
Code: [Select]
`Hi MarkTThank 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 revolutionStepper small_stepper(STEPS, 11,9 , 10, 8);int  Steps2Take = 0;int microswitch = 22; //pin for microswitchint 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);  }*/`

#### MarkT

#4
##### May 20, 2017, 06:10 pm
Ask the forum as a whole, not one particular member...
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up