Hello everybody
i am seeking your help
my project is solar tracking system so my code working in the 4 direction west ,east,south ,north ,but the problem i face once the sun during the afternoon time it mean will be perpendicular on my robot so the problem i can not move the robot to the center position and stop ...looking for your help in how i can move the motor to center and stop .
Thank you ....
Here i attached my code
#include <Stepper.h>
// change this to the number of steps on your motor
#define STEPS 100
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
// the previous reading from the analog input
int pos1=0;
int pos2=0;
int east=0;
int west=0;
int south=0;
int north=0;
int centre=0;
int ldr1=0;
int ldr2=1;
int ldr3=2;
int ldr4=4;
int ldr5=5;
void setup()
{
// set the speed of the motor to 30 RPMs
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop()
{
// get the sensor value
int east= analogRead(ldr1);
int west= analogRead(ldr2);
int centre= analogRead(ldr3);
int south= analogRead(ldr4);
int north= analogRead(ldr5);
// move a number of steps equal to the change in the
// sensor reading
//for conrol of vertical i.e. (east-west) position
if (east>centre && west<centre)
{
digitalWrite(8, HIGH);
delay(10);
digitalWrite(8, LOW);
delay(10);
}
else if (west>centre && east<centre)
{
digitalWrite(9, HIGH);
delay(10);
digitalWrite(9, LOW);
delay(10);
}
else
{
digitalWrite(8, LOW);
delay(10);
digitalWrite(9, HIGH);
delay(10);
}
//for control of horizontal i.e.right-left (south-north) position
if (south>centre && north<centre)
{
digitalWrite(10, HIGH);
delay(10);
digitalWrite(10, LOW);
delay(10);
}
else if (north>centre && south<centre)
{
digitalWrite(11, HIGH);
delay(10);
digitalWrite(11, LOW);
delay(10);
}
else
{
digitalWrite(10, LOW);
delay(10);
digitalWrite(11, LOW);
delay(10);
}
}
Moderator edit: Code tags. Why is it so hard to read a few simple rules?