IR Remote with robot.

hello all,
I am working on a mini project to build a robot using an Arduino Uno, 2 small dc motors, L298N motor driver (H-Bridge), and an Keyes IR remote. i found and instructables.com link to build one but for some reason it is not working right. I built it as shown in the link below (from instructables) and the first button i press work but then any button a press after that does not work. for example, i have it set do that when i press the 1 (one) button it turns counter-clockwise, and that works, but if after pressing that button, i press the OK button to stop it, it doesn’t stop. here is the link to the website. http://www.instructables.com/id/Tracked-Robot-IR-Remote-Control-by-Arduino/?ALLSTEPS
and i got the IRremote.h library from github, then went to the Arduino IDE, sketch, include library, contributed library, and IRremote (not robot ir remote).

here is the each buttons hexadecimal value:

    case 0xFF629D: Serial.println(" FORWARD"); break;
    case 0xFF22DD: Serial.println(" LEFT");    break;
    case 0xFF02FD: Serial.println(" -OK-");    break;
    case 0xFFC23D: Serial.println(" RIGHT");   break;
    case 0xFFA857: Serial.println(" REVERSE"); break;
    case 0xFF6897: Serial.println(" 1");    break;
    case 0xFF9867: Serial.println(" 2");    break;
    case 0xFFB04F: Serial.println(" 3");    break;
    case 0xFF30CF: Serial.println(" 4");    break;
    case 0xFF18E7: Serial.println(" 5");    break;
    case 0xFF7A85: Serial.println(" 6");    break;
    case 0xFF10EF: Serial.println(" 7");    break;
    case 0xFF38C7: Serial.println(" 8");    break;
    case 0xFF5AA5: Serial.println(" 9");    break;
    case 0xFF42BD: Serial.println(" *");    break;
    case 0xFF4AB5: Serial.println(" 0");    break;
    case 0xFF52AD: Serial.println(" #");    break;

and here is the code i am using (it has been edited from instructables to work with my hex values)

#include <boarddefs.h>
#include <ir_Lego_PF_BitStreamEncoder.h>
#include <IRremote.h>
#include <IRremoteInt.h>



int RECV_PIN = 11;

int statusled = 13;

IRrecv irrecv(RECV_PIN);

decode_results results;


// connect motor controller pins to Arduino digital pins
// motor A
int enA = 10;
int in1 = 9;
int in2 = 8;
// motor B
int enB = 5;
int in3 = 7;
int in4 = 6;


void setup()

{

  irrecv.enableIRIn();

  pinMode(statusled, OUTPUT);

  digitalWrite(statusled, LOW);

  // set all the motor control pins to outputs
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);


}

void loop() {

  if (irrecv.decode(&results)) {

    digitalWrite(statusled, HIGH);

    irrecv.resume();

    if (results.value == 0xFF629D)  // forward robot control
    {
      // this function will run the motors in both directions at a fixed speed
      // turn on motor A
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      // set speed to 200 out of possible range 0~255
      analogWrite(enA, 100);
      // turn on motor B
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
      // set speed to 200 out of possible range 0~255
      analogWrite(enB, 100);
    }
     
    else if (results.value == 0xFF22DD)  // turn left robot control

    {
      // this function will run motor A in forward directions  motor B stop
      // turn on motor A
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      // set speed to 200 out of possible range 0~255
      analogWrite(enA, 100);
      // turn on motor B
      digitalWrite(in3, LOW);
      digitalWrite(in4, LOW);
      // set speed to 200 out of possible range 0~255
      analogWrite(enB, 100);
    }

    
    else if (results.value == 0xFF6897)  // type button 1 rotate left robot control

    {
      // this function will run motor A in forward directions  motor B in backward directions
      // turn on motor A
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      // set speed to 200 out of possible range 0~255
      analogWrite(enA, 100);
      // turn on motor B
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);
      // set speed to 200 out of possible range 0~255
      analogWrite(enB, 100);
    } 
    
    else if (results.value == 0xFFC23D)  // turn right robot control

    {  // this function will  stop motor A  run motor B in forward directions
      // turn on motor A
      digitalWrite(in1, LOW);
      digitalWrite(in2, LOW);
      // set speed to 200 out of possible range 0~255
      analogWrite(enA, 100);
      // turn on motor B
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
      // set speed to 200 out of possible range 0~255
      analogWrite(enB, 100);

    } else if (results.value == 0xFFB04F) { // type button 3 rotate right robot control

      // this function will run motor A  in backward directions  motor B in forward directions
      // turn on motor A
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      // set speed to 200 out of possible range 0~255
      analogWrite(enA, 100);
      // turn on motor B
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
      // set speed to 200 out of possible range 0~255
      analogWrite(enB, 100);

    } else if (results.value == 0xFFA857) { // backward robot control

      // this function will run motor A and motor B in backward directions
      // turn on motor A
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      // set speed to 200 out of possible range 0~255
      analogWrite(enA, 100);
      // turn on motor B
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);
      // set speed to 200 out of possible range 0~255
      analogWrite(enB, 100);



    } else if (results.value == 0xFF02FD) { // stop robot control


      // this function will stop both motor A and motor B
      // turn on motor A
      digitalWrite(in1, LOW);
      digitalWrite(in2, LOW);
      // set speed to 200 out of possible range 0~255
      analogWrite(enA, 100);
      // turn on motor B
      digitalWrite(in3, LOW);
      digitalWrite(in4, LOW);
      // set speed to 200 out of possible range 0~255
      analogWrite(enB, 100);



    }

  }

}

i think there is a problem with my loop and it is not continuously checking to check the ir receiver.

any and all help is greatly appreciated.

Add some Serial.println() statements to get some debug output in the Serial Monitor.

Hi, working code for that remote and L298N controlled robot HERE

terryking228:
Hi, working code for that remote and L298N controlled robot HERE

how would I do this with a regular Arduino Uno and not the RoboRED Arduino Uno?

how would I do this with a regular Arduino Uno and not the RoboRED Arduino Uno?

Hi, The RoboRED is completely UNO compatible; the difference is the roboRED has all I/O brought out to 3-pin connectors. So making the connections is a little harder with the UNO.

See THIS Comparison..