my project light-sensitive automatic opening , closing curtains..stepper motor not stop after 90 degrees
code: [select]
// arduino example demonstrates bidirectional operation of
// 28byj-48, using uln2003 interface board drive stepper.
// 28byj-48 motor 4-phase, 8-beat motor, geared down by
// factor of 68. 1 bipolar winding on motor pins 1 & 3 and
// other on motor pins 2 & 4. step angle 5.625/64 ,
// operating frequency 100pps. current draw 92ma.
////////////////////////////////////////////////
//declare variables motor pins
int motorpin1 = 2; // blue - 28byj48 pin 1
int motorpin2 = 4; // pink - 28byj48 pin 2
int motorpin3 = 3; // yellow - 28byj48 pin 3
int motorpin4 = 5; // orange - 28byj48 pin 4
int sayi;
int sayii; // red - 28byj48 pin 5 (vcc)
int ldr = 0;
int ldr_value = 10;
int motorspeed = 1200; //variable set stepper speed
int count = 0; // count of steps made
int countsperrev = 256; // number of steps per full revolution
int lookup[8] = {b01000, b01100, b00100, b00110, b00010, b00011, b00001, b01001};
//////////////////////////////////////////////////////////////////////////////
void setup() {
//declare motor pins outputs
pinmode(motorpin1, output);
pinmode(motorpin2, output);
pinmode(motorpin3, output);
pinmode(motorpin4, output);
serial.begin(9600);
}
//////////////////////////////////////////////////////////////////////////////
void loop(){
if(ldr_value = analogread(ldr))
{
serial.println(ldr_value); //prints ldr values serial monitor
delay(10);
clockwise();
}
else if (count == countsperrev * 2)
{
count = 0;}
else{
anticlockwise();
count++;
}
}
//////////////////////////////////////////////////////////////////////////////
//set pins uln2003 high in sequence 1 4
//delay "motorspeed" between each pin setting (to determine speed)
void anticlockwise()
{
for(int = 0; < 8; i++)
{
setoutput(i);
delaymicroseconds(motorspeed);
}
}
void clockwise()
{
for(int = 7; >= 0; i--)
{
setoutput(i);
delaymicroseconds(motorspeed);
}
}
void setoutput(int out)
{
digitalwrite(motorpin1, bitread(lookup[out], 0));
digitalwrite(motorpin2, bitread(lookup[out], 1));
digitalwrite(motorpin3, bitread(lookup[out], 2));
digitalwrite(motorpin4, bitread(lookup[out], 3));
}
i recommend using motor shield
and af_motor library
and depending on how many steps stepper.
most steppers 48 steps
(48 steps = 360 degrees = 1 turn)
so 12 steps 90 degrees
try it, best way precisely control
and af_motor library
and depending on how many steps stepper.
most steppers 48 steps
(48 steps = 360 degrees = 1 turn)
so 12 steps 90 degrees
try it, best way precisely control
Arduino Forum > Using Arduino > Motors, Mechanics, and Power (Moderator: fabioc84) > stepper motor help me
arduino
Comments
Post a Comment