Using IR remote to change car mode

Hello all, I am new here and sorry in advance if I didn't post my code correctly.

I am creating a robot car using the arduino uno, in which I use an IR remote to either change the car to manual mode, meaning I can use the remote to control if the car goes forward, left, right, etc., or in automatic mode, which will use an ultrasonic sensor to navigate the area.

The problem I find myself in is once the manual mode button is pressed, I want it to go forward, left, right, etc. depending on the button that is pressed, and when the CHANGE_GEAR button is pressed, the car should stop and wait until the user presses either the automatic or manual mode button.

I provided a little sudo code as to how I am thinking of using the IR remote to control the car and change the modes. I would appreciate any help with trying to figure this out.


#define IR_PIN 4
  IRrecv IR(IR_PIN);
  decode_results results;

//button Codes
#define ADVANCE       0x00FF18E7       //code from IR controller "^" button
#define BACK          0x00FF4AB5       //code from IR controller "v" button
#define RIGHT         0x00FF5AA5       //code from IR controller ">" button
#define LEFT          0x00FF10EF       //code from IR controller "<" button
#define STOP_         0x00FF38C7       //code from IR controller "OK" button

#define CHANGE_GEAR    0x00FFA857       //code from IR controller "8" button

#define AUTOMATIC     0x00FFA25D       //code from IR controller "1" button
#define MANUAL        0x00FFE21D       //code from IR controller "3" button

unsigned long LastCommand;

void setup() {
  pinMode(IR_PIN, INPUT);
  digitalWrite(IR_PIN, HIGH);


void ir_loop(){
  tick = true;
    if(results.value == MANUAL){
      //want to stay in this if statement, and check for other button
      //presses on the remote
      //if(results.value == ADVANCE){
      //  Serial.print("GO FORWARD\n");
      //  LastCommand = results.value;
      //else if(results.value == LEFT){
      //  Serial.print("GOING LEFT\n");
      //  LastCommand = results.value;

      //and so forth until the CHANGE_GEAR button is pressed, and then
      //it should exit this if statement
    else if(results.value == AUTOMATIC){
      LastCommand = results.value;
    else if(results.value == 0xFFFFFFFF){
      Serial.print("No valid input\n");
      results.value = LastCommand;
    results.value = 0;

void loop() {

Separate command input by IR or manual from command execution. Whenever a command entry is detected store it in LastCommand and execute the command in loop().

There are a lot of IR tutorials available to get started.

it's often less time consuming to develop off-target.

i suggest to develop code to affect the operations you want using the serial interface

separately develop code that can receive and interpret IR codes

then combine the two to use IR code to exercise the operations verified using the serial I/F

What version of the IRremote library do you have installed? The posted code is written for an older version of the library and may not work properly with the newest version of the library.

Sorry for the late reply, I have version 3.4.0 of the IRremote library installed.

The GitHub page for the IRremote library explains the differences from the older versions and how to change older code to work with the new version.

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