Hello to all,I am not a hardcore programer. I have just started basic programming with the help of Google. i would like some programming support to make my line follower operational . I am using arduino UNO with 5 sensors(digital HIGH/LOW output) for the line follower. The code i have written is very simple, with the below code the motors run:
int S1 = 2;
int S2 = 3;
int S3 = 4;
int S4 = 5;
int IN1 = 6;
int IN2 = 7;
int IN3 = 8;
int IN4 = 9;
int EN1 = 10;
int EN2 = 11;
int S5 = 12;
void setup()
{
// declare the LED pins as outputs
pinMode(S1, INPUT) ;// SENSOR1
pinMode(S2, INPUT) ;// SENSOR2
pinMode(S3, INPUT) ;// SENSOR3
pinMode(S4, INPUT) ;// SENSOR4
pinMode(S5, INPUT) ;// SENSOR5
pinMode(IN1,OUTPUT); //input 1
pinMode(IN2,OUTPUT); //input 2
pinMode(IN3,OUTPUT); //input 3
pinMode(IN4,OUTPUT); //input 4
pinMode(EN1,OUTPUT); //pwm en 3,4
pinMode(EN2,OUTPUT); //pwm en 1,2
pinMode(13,OUTPUT);
}
void loop()
{
if (digitalRead(S1) == LOW )
{
analogWrite(EN1, 255);
analogWrite(EN2, 255);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
delay(500);
}
if (digitalRead(S1) == HIGH )
{
analogWrite(EN1, 255);
analogWrite(EN2, 255);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
delay(500);
}
}
but when i change the code it doesn't do any thing
void loop()
{
if (digitalRead(S1) == LOW && digitalRead(S2) == LOW && digitalRead(S3) == HIGH && digitalRead(S4) == LOW && digitalRead(S5) == LOW)
{
analogWrite(EN1, 255);
analogWrite(EN2, 255);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
delay(500);
}
else if (digitalRead(S1) == HIGH )
{
analogWrite(EN1, 255);
analogWrite(EN2, 255);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
delay(500);
}
the code verifies without any errors but nothing happens, Any advices.
Thanks