IR receiver receives one input but not any more

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.

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Turn on compiler warnings in the IDE, File, Preferences and re-compile. Note the warnings.

You get some of these:

sketch_may04e.ino:37:10: warning: large integer implicitly truncated to unsigned type [-Woverflow]
case play_button:
^~~~
because
unsigned int value = output.value;
is the wrong data type. It should be:
unsigned long value = output.value;

Then, if you have the latest version of the IRremote library installed you will see:

warning: 'bool IRrecv::decode(decode_results*)' is deprecated: Please use IrReceiver.decode() without a parameter and IrReceiver.decodedIRData. . [-Wdeprecated-declarations]
if (receiver.decode(&output))
^
because you are running code written for the old version of the IDE. See the IRremote GitHub page to see how to fix older code to run with the new version.

Fixing the warnings may or may not fix the code but it needs to be done.

we are working on a school project and our IR sensor is only receiving 0. we have two servo wheels and a servo in the back for a sling shot. When we use the IR remote the IR receiver gets the first one, but then it spams 0's in teh serial moniter. We are using this code:

#include <IRremote.h>      //including the remote library
#define button2 3877175040  // forward
#define button8 16730805  // back
#define button4 16716015  // left
#define button6 16734885 //right
#define button5 3810328320 //stop  
const int IR_RECEIVE_PIN = 7;
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


void setup() {
  Serial.begin(9600);
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
  pinMode(left_motor1, OUTPUT);
  pinMode(left_motor2, OUTPUT);
  pinMode(right_motor1, OUTPUT);
  pinMode(right_motor2, OUTPUT);
}

void loop() {
 if (IrReceiver.decode()) {


  Serial.println(IrReceiver.decodedIRData.decodedRawData);

    switch(IrReceiver.decodedIRData.decodedRawData) {
      case button2:
           Serial.println ("play");
           digitalWrite(left_motor1,LOW);
           digitalWrite(left_motor2,HIGH);
           digitalWrite(right_motor1,HIGH);
           digitalWrite(right_motor2,LOW);
           break;
      case button8:
           Serial.println("previous");
           digitalWrite(left_motor1,HIGH);
           digitalWrite(left_motor2,LOW);
           digitalWrite(right_motor1,LOW);
           digitalWrite(right_motor2,HIGH);
           break;
      case button4:
           digitalWrite(left_motor1,LOW);
           digitalWrite(left_motor2,HIGH);
           digitalWrite(right_motor1,HIGH);
           digitalWrite(right_motor2,HIGH);
           break;
      case button6:
           digitalWrite(left_motor1,HIGH);
           digitalWrite(left_motor2,HIGH);
           digitalWrite(right_motor1,HIGH);
           digitalWrite(right_motor2,LOW);
           break;
      case button5:
           digitalWrite(left_motor1,LOW);
           digitalWrite(left_motor2,LOW);
           digitalWrite(right_motor1,LOW);
           digitalWrite(right_motor2,LOW);
           break;
    }
    IrReceiver.resume();
  }
}

any advice would be great.

Post your sketches using code tags.

Note: An RX repeat code may be the problem.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.