How to make an IR remote control car with Arduino

How to make an IR remote control car with Arduino

Hello and welcome back. In this project, we will learn how to make an IR remote control car using Arduino. Also, the IR receiver module is mainly used to control this car. Therefore, we can control this car using any kind of IR remote. This car is based on the Arduino UNO board and L293D motor driver shield. Also, this tutorial shows you step by step how to make this car so you can easily make it.

The process of this car

When the car is powered on, the L293D motor shield and the IR receiver module are activated through the Arduino UNO board. The IR receiver then captures the IR signals. When the IR remote sends values that match the program, the gear motors rotate forward or backward according to those values. The motor rotation is controlled by the motor driver shield.

A key point to remember when assembling this car is that, despite using the L293D motor driver shield, the motor 1 and motor 2 terminals are not functional with the IR receiver library we are using. Therefore, only the motor 3 and motor 4 terminals can be used.

OK, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, let’s identify these components.

Step 2

Secondly, cut the foam board piece as follows.

Step 3

Thirdly, glue the gear motors as follows.

Step 4

Now, connect the motor drive shield to the Arduino board. Then, glue it to the center of the car chassis.

Step 5

Then, connect the gear motors. To do this, use the circuit diagram below.

How to make an IR remote control car with Arduino

Step 6

Now, glue the IR receiver module, After, connect it to the motor driver shield. For that, use the circuit diagram above.

Step 7

Then, glue the li-ion battery holder and connect it to the motor driver shield.

Step 8

OK, now let’s set up the program for this project. It is as follows.

Firstly, get the IR values from the IR remote. For that, you can use any type of IR remote.

/*IR remote control car with Arduino.
 * https://srituhobby.com
 */
 
#include <AFMotor.h>
#include <IRremote.h>

AF_DCMotor motor1(3);
AF_DCMotor motor2(4);

IRrecv IR(A0);
decode_results result;

int Speed = 150;

#define up 0
#define down 0
#define left 0
#define right 0
#define Stop 0

void setup() {
  Serial.begin(9600);
  motor1.setSpeed(Speed);
  motor2.setSpeed(Speed);
  IR.enableIRIn();
}

void loop() {
  if (IR.decode(&result)) {
    Serial.println(result.value);
    IR.resume();
  }
  delay(100);
  if (result.value == up ) {
    motor1.run(FORWARD);
    motor2.run(FORWARD);
  } else if (result.value == down ) {
    motor1.run(BACKWARD);
    motor2.run(BACKWARD);
  } else if (result.value == Stop) {
    motor1.run(RELEASE);
    motor2.run(RELEASE);
  } else if (result.value == left) {
    motor1.run(FORWARD);
    motor2.run(BACKWARD);
  } else if (result.value == right) {
    motor1.run(BACKWARD);
    motor2.run(FORWARD);
  }
}

Code explanation

Firstly, libraries are included.

#include <AFMotor.h>
#include <IRremote.h>

Secondly, objects are created for these libraries.

AF_DCMotor motor1(3);
AF_DCMotor motor2(4);

IRrecv IR(A0);
decode_results result;

Next, the IR remote values are defined. For this, we will then enter the IR values.

#define up 0
#define down 0
#define left 0
#define right 0
#define Stop 0

In the setup function,

void setup() {
//The serial monitor is begin.
  Serial.begin(9600);
//Includes speed of motorsග
  motor1.setSpeed(Speed);
  motor2.setSpeed(Speed);
//IR module is enable.
  IR.enableIRIn();
}

In the loop function,

void loop() {
//This code retrieves IR values from the IR remote.
  if (IR.decode(&result)) {
    Serial.println(result.value);
    IR.resume();
  }
  delay(100);
//These values are checked using the IF condition and the car is moved UP, DOWN, LEFT, RIGHT, and STOP using these values.
  if (result.value == up ) {
    motor1.run(FORWARD);
    motor2.run(FORWARD);
  } else if (result.value == down ) {
    motor1.run(BACKWARD);
    motor2.run(BACKWARD);
  } else if (result.value == Stop) {
    motor1.run(RELEASE);
    motor2.run(RELEASE);
  } else if (result.value == left) {
    motor1.run(FORWARD);
    motor2.run(BACKWARD);
  } else if (result.value == right) {
    motor1.run(BACKWARD);
    motor2.run(FORWARD);
  }
}

Step 9

Now, select the board and port. Then, upload this program.

Step 10

Now, run the serial monitor and get the IR values. After, copy and paste them into the program.

Step 11

Lastly, upload this program again.

OK, enjoy this project. The full video guide is given below. So, we will meet in the next tutorial.

How to make an IR remote control car with Arduino

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *