Hii everyone,
I am making a Grid solver which will move to the exact same coordinate as specified in the program on 5x5 grid. The grid is made up of black line on white background.I am using two DC motors for navigation, two IR photo detector diodes for node detection and other two for the black line.The sensors are connected to analog pins of arduino.
I am able to move the robot on the line i.e it does not escapes from the line, but the problem i am facing is that it does not take
Full 90 degree Turns on the intersections i.e @ nodes. It senses the presence of node but is unable to rotate 90 degrees. I don't want to use encoders and instead want to do this by programming only .
here's the whole code i am using..
int LMen=5;//enable of LEFT motor
int RMen=6;//enable of Right motor
int LM1=3;//direction pin1 of first motor
int LM2=4;//direction pin2 of first motor
int RM1=7;//direction pin1 of right motor
int RM2=8;//direction pin1 of right motor
int N1=A7;//node detector1
int N2=A4;//node detector2
int T1=A6;//tracing sensor1
int T3=A5;//tracing sensor2
int LED=13;//arduino LED
int sensitivity=400;//threshold for sensors
void setup()
{
pinMode(LED,OUTPUT);
pinMode(LMen, OUTPUT);
pinMode(RMen, OUTPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
pinMode(N1,INPUT);
pinMode(N2,INPUT);
pinMode(T1,INPUT);
pinMode(T3,INPUT);
digitalWrite(LM1, LOW);//direction forward
digitalWrite(LM2, HIGH);//direction forward
digitalWrite(RM1, HIGH);//direction forward
digitalWrite(RM2, LOW);//direction forward
digitalWrite(LMen, LOW);
digitalWrite(RMen, LOW);
Serial.begin(9600);
}
void loop()
{
if(analogRead(N1)>sensitivity && analogRead(N2)>sensitivity && analogRead(T1)>sensitivity && analogRead(T3)>sensitivity )
{
digitalWrite(LED,HIGH);
right90();
}
else
{
followline();
digitalWrite(LED,LOW);
}
}
void followline()
{
if(analogRead(T1)>sensitivity && analogRead(T3)<sensitivity)
{
left();
}
else if(analogRead(T1)<sensitivity && analogRead(T3)>sensitivity)
{
right();
}
else
{
straight();
}
}
void straight()
{
digitalWrite(LMen,HIGH);
digitalWrite(RMen,HIGH);
}
void left()
{
digitalWrite(LMen,LOW);
digitalWrite(RMen,HIGH);
}
void right()
{
digitalWrite(LMen,HIGH);
digitalWrite(RMen,LOW);
}
void right90()
{
int i=1;
right();
straight();
while(analogRead(N1)<sensitivity && analogRead(N2)<sensitivity && i==1)
{
right();
if(analogRead(T1)>sensitivity && analogRead(T3)>sensitivity)
{
i++;//loop break condition
}
}
}
.
need help, can anyone tell me where am i going wrong,??