Buongiorno a tutti, devo portare per l'esame di maturità un robot line follow ma ho un piccolo problema:
ho montato tre foto-resistenze su una lastra di alluminio e leggendo su Internet consigliavano di "schermare" le foto-resistenze,così ho creato una struttura che potesse proteggere le foto-resistenze dalla luce esterna; ma il problema è che quando cerco di inserire un led all'interno della struttura per fare luce sulla linea da seguire la macchina non fa altro che girare su se stessa, invece, se utilizzo una normale torcia, segue la line senza nessun problema. Vi posto il codice e alcune immagini:
#include <AFMotor.h>
AF_DCMotor right_motor(2, MOTOR12_64KHZ);
AF_DCMotor left_motor(1, MOTOR12_64KHZ);
#define leftSensor 3
#define centerSensor 5
#define rightSensor 4
#define led 9
#define buttonPin 2
int valoreD=0;
int valoreC=0;
int valoreS=0;
int val=0;
int vecchio_val=0;
int stato=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led,OUTPUT);
pinMode(buttonPin,INPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
pinMode(3,OUTPUT);
right_motor.setSpeed(200);
left_motor.setSpeed(200);
}
void loop() {
// put your main code here, to run repeatedly:
val=digitalRead(buttonPin);
if((val==HIGH)&&(vecchio_val==LOW)){
stato=1-stato;
delay(15);
}
vecchio_val=val;
if(stato==0){
digitalWrite(led,HIGH);
valoreS=analogRead(leftSensor);
valoreD=analogRead(rightSensor);
valoreC=analogRead(centerSensor);
if((valoreS>valoreC)&&(valoreD>valoreC)){
right_motor.run(FORWARD);
left_motor.run(FORWARD);
}
if((valoreS<valoreC)&&(valoreS<valoreD)){
right_motor.run(FORWARD);
left_motor.run(RELEASE);
}
if((valoreD<valoreC)&&(valoreD<valoreS)){
right_motor.run(RELEASE);
left_motor.run(FORWARD);
}
delay(15);
}else{
digitalWrite(led,LOW);
right_motor.run(RELEASE);
left_motor.run(RELEASE);
}
}
P.S: Sapete dirmi qual é la distanza ideale tra la fotoresistenza e la linea da seguire?


