Paso 1: Diagrama y esquema schetch
He utilizado dia dibujar diagrama y fritzing para esquemas
Y es este schetch de Arduino:
#define dxg 11<br>#define dxb 10 #define dxv 9 #define dxr 8 #define sxg 5 #define sxv 4 #define sxb 3 #define sxr 2
void setup() { pinMode(dxg,OUTPUT); pinMode(dxb,OUTPUT); pinMode(dxv,OUTPUT); pinMode(dxr,OUTPUT); pinMode(sxg,OUTPUT); pinMode(sxv,OUTPUT); pinMode(sxb,OUTPUT); pinMode(sxr,OUTPUT); pinMode(6,INPUT); pinMode(7,INPUT); }
void loop() { // dynamic line follower code int lsensor=digitalRead(6); int rsensor=digitalRead(7); if((lsensor==LOW)&&(rsensor==LOW)) { //both sensors on white // go forward digitalWrite(dxg,HIGH); digitalWrite(dxb,HIGH); digitalWrite(dxv,LOW); digitalWrite(dxr,LOW); digitalWrite(sxg,HIGH); digitalWrite(sxv,HIGH); digitalWrite(sxb,LOW); digitalWrite(sxr,LOW); } else if((lsensor==HIGH)&& (rsensor==LOW)) { //right sensor on black line // turn right digitalWrite(dxg,LOW); digitalWrite(dxb,LOW); digitalWrite(dxv,HIGH); digitalWrite(dxr,HIGH); digitalWrite(sxg,HIGH); digitalWrite(sxv,HIGH); digitalWrite(sxb,LOW); digitalWrite(sxr,LOW); } else if((lsensor==LOW)&&(rsensor==HIGH)) { //left sensor on black line // turn left digitalWrite(dxg,HIGH); digitalWrite(dxb,HIGH); digitalWrite(dxv,LOW); digitalWrite(dxr,LOW); digitalWrite(sxg,LOW); digitalWrite(sxv,LOW); digitalWrite(sxb,HIGH); digitalWrite(sxr,HIGH); } else { digitalWrite(dxg,LOW); digitalWrite(dxb,LOW); digitalWrite(dxv,LOW); digitalWrite(dxr,LOW); digitalWrite(sxg,LOW); digitalWrite(sxv,LOW); digitalWrite(sxb,LOW); digitalWrite(sxr,LOW); } }