ok the motor code works fine now, but now i added, some of the 2-10cm infrared sensors ,and the code just drives forward, as if it doesnt see the infrared? any help would be appreciateted ,here is the code
int infra=3;
int value = 0 ;
int infra2=4;
int val2= 0;
void setup()
{
Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode (11,OUTPUT);
pinMode (10,OUTPUT);
pinMode (3,INPUT);
pinMode (infra,INPUT);
}
NEW: the first 2 parts work the third doesnt
void loop()
{
if (digitalRead(infra)==HIGH)
{
driveforward() ;
}
else if (digitalRead(infra)==LOW)
{ stopmot ();
delay (500);
right();
delay(1000);
}
THIS doesnt work
else if (digitalRead (infra2)==LOW)
{ stopmot ();
delay (500);
left();
delay(1000);
void driveforward()
{
digitalWrite(13,HIGH);
digitalWrite(10,HIGH);
digitalWrite (11,LOW);
digitalWrite (12,LOW);
}
void stopmot()
{
digitalWrite(13,LOW);
digitalWrite(12,LOW);
digitalWrite(11,LOW);
digitalWrite(10,LOW);
}
void reverse()
{
digitalWrite(12,HIGH);
digitalWrite(11,HIGH);
digitalWrite (13,LOW);
digitalWrite (10,LOW);
}
void right()
{
digitalWrite (10,HIGH);
digitalWrite (13,LOW);
digitalWrite (12,LOW);
digitalWrite (11,LOW);
}
void left()
{
digitalWrite (12,HIGH);
digitalWrite (11,LOW);
digitalWrite (13,LOW);
digitalWrite (10,LOW);
}