we are making a battle bot in class and when we use the IR remote it will take one input but then does not take anymore. I can see that when we put in an input it is received but the servos won't move. we are using this code:
//Controlling DC Motors using Arduino and IR Remote
#include <IRremote.h> //including the remote library
#define play_button 16718055 // code received from next button
#define Prev_button 16730805 // code received from previous button
#define left_button 16716015 // code received from left button
#define right_button 16734885 // code received from right button
#define Stop_button 16726215 // code received from stop button
int receiver_pin = 7; //output pin of IR receiver to pin 2 of arduino
//initializing the pins for leds
int left_motor1 = 9; //pin 6 of arduino to pin 7 of l293d
int left_motor2 = 10; //pin 7 of arduino to pin 2 of l293d
int right_motor1 =6; //pin 5 of arduino to pin 10 of l293d
int right_motor2 = 5; //pin 4 of arduino to pin 15 of l293d
IRrecv receiver(receiver_pin); //Arduino will take output of IR receiver from pin 2
decode_results output;
void setup() {
Serial.begin(9600);
receiver.enableIRIn(); // Start to take the output from IR receiver
//initializing all the pins where we have connected the led's as output pins
pinMode(left_motor1, OUTPUT);
pinMode(left_motor2, OUTPUT);
pinMode(right_motor1, OUTPUT);
pinMode(right_motor2, OUTPUT);
}
void loop() {
if (receiver.decode(&output)) {
unsigned int value = output.value;
switch(value) {
case play_button:
Serial.println ("play");
digitalWrite(left_motor1,LOW);
digitalWrite(left_motor2,HIGH);
digitalWrite(right_motor1,HIGH);
digitalWrite(right_motor2,LOW);
break;
case Prev_button:
Serial.println("previous");
digitalWrite(left_motor1,HIGH);
digitalWrite(left_motor2,LOW);
digitalWrite(right_motor1,LOW);
digitalWrite(right_motor2,HIGH);
break;
case left_button:
digitalWrite(left_motor1,LOW);
digitalWrite(left_motor2,HIGH);
digitalWrite(right_motor1,HIGH);
digitalWrite(right_motor2,HIGH);
break;
case right_button:
digitalWrite(left_motor1,HIGH);
digitalWrite(left_motor2,HIGH);
digitalWrite(right_motor1,HIGH);
digitalWrite(right_motor2,LOW);
break;
case Stop_button:
digitalWrite(left_motor1,LOW);
digitalWrite(left_motor2,LOW);
digitalWrite(right_motor1,LOW);
digitalWrite(right_motor2,LOW);
break;
}
receiver.resume();
}
}
Any advice would be helpful.