line follower robot ...

Posts: 1
View Profile
Email
Personal Message (Online)
this is my code ... i m used 2 IR sensor and motor shield . ..is that right code??/..

#include <AFMotor.h>

AF_DCMotor motor1(3, MOTOR12_1KHZ);
AF_DCMotor motor2(4, MOTOR12_1KHZ);

void setup()
{
Serial.begin(9600);
}

void loop()
{
int S1 = digitalRead(A1);
int S2 = digitalRead(A2);
Serial.println(S1);
Serial.println(S2);

if(S1==HIGH && S2== HIGH )
{
motor1.setSpeed(255);
motor2.setSpeed(255);
motor1.run(FORWARD);
motor2.run(FORWARD);
delay(1000);
}

if(S1==LOW && S2== HIGH )
{
motor1.setSpeed(0);
motor2.setSpeed(255);
motor1.run(RELEASE);
motor2.run(FORWARD);
delay(1000);
}

if(S1==HIGH && S2== LOW )
{
motor1.setSpeed(255);
motor2.setSpeed(0);
motor1.run(FORWARD);
motor2.run(RELEASE);
delay(1000);
}

if(S1==LOW && S2== LOW )
{
motor1.setSpeed(255);
motor2.setSpeed(0);
motor1.run(FORWARD);
motor2.run(RELEASE);
delay(1000);
}
}

Its the same code you (badly) cross-posted in "guidance", now deleted.
Does it compile?
Does it do what you want?
If so, it is the right code.

actually my robot will work but at the time right turn it wiil not take right turn ,,i dnt know what is problem..

Could it be something to do with the digital reads of analogue pins?
What do the debug prints tell you is happening?

in serial terminal right sensor value show as 1 ...i think connection is not proper ....is that necessary to give 5v beoz i m giving 3.3v to right sensor

Your question is impossible to answer with the information given.
Please, read the posting guidelines at the top of this section of the forum.