Hello,
I'm trying to control a motor with an IR receptor, i use a l293d to control the motor. When i send my signal to start the motor, it works but if i try to stop it it doesn't, the arduino seems to receive no signal. Any explanations ?
Here is my code :
#include <IRremote.h>
#include <Servo.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
Servo myservo;
int moteurAvant=3;
int etalonDroit=108;
int etalonGauche=48;
int etalonMilieu=78;
void setup()
{
myservo.attach(9);
Serial.begin(9600);
irrecv.enableIRIn(); // Initialise le recepteur
}
void loop() {
if (irrecv.decode(&results)) {
if(results.value == 16748655){// +
analogWrite(moteurAvant, 255);
Serial.println("vitesse=1");
}
else if(results.value == 16754775){// -
analogWrite(moteurAvant, 0);
Serial.println("vitesse=0");
}
else if(results.value == 16761405){// droite
Serial.println("droite");
if(myservo.read()==etalonGauche){
auMlieu();
}
else{
aDroite();
}
}
else if(results.value == 16712445){// gauche
Serial.println("gauche");
if(myservo.read()==etalonDroit){
auMlieu();
}
else{
aGauche();
}
}
irrecv.resume(); // Recoit la valeur suivante
}
}
void aDroite(){
myservo.write(etalonDroit);
}
void aGauche(){
myservo.write(etalonGauche);
}
void auMlieu(){
myservo.write(etalonMilieu);
}
For the motor wiring, i use something like this : http://api.ning.com/files/jFhR10F2nKDm5cJ0p2jcpgHpKd4hNPz01QgMS8OF6QUh82aIgvr-dp1uzQSopb*PQgSlhFEgj5ALhek3X56Zq6xDZuw-9vwD/l293dmontagem.jpeg
Thanks,
Jocelyn