How to Make a 2WD IR Remote Controlled Car with Arduino Nano

How to Make a 2WD IR Remote Controlled Car with Arduino Nano

Hello and welcome back. In this project, we will learn how to make an IR remote-controlled car using an Arduino Nano board. You can control it using your own IR-based remote, like a TV remote or any other IR remote you have at home. I used two gear motors for this project, just like in a 2WD IR remote control car. Also, you do not need an additional chassis for this project. For that, I designed a custom PCB with JLCPCB, and it works like a chassis. You can easily mount all the components onto this PCB chassis without any extra parts.

Specially, you can control this car using any IR remote you want. Therefore, you don’t need to build or buy a separate remote for it. You only need to change the IR values in the code according to your remote’s buttons.

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, identify these components.

Step 2

Secondly, let’s order the PCBs for this project.

  • Click the “Instant Quote” button and upload the Gerber file, which you can download from the link below.
  • Gerber file – Download
  • For this project, I ordered five Yellow PCBs. Next, select the build time and shipping method. Finally, click “Save to Cart” and complete the payment.

Step 3

Thirdly, unbox your PCB package carefully.

Step 4

Now, solder the components onto the PCB.

Step 5

Next, attach the wheels to the gear motor and install them on the bottom side of the chassis. Then, install the caster wheel on the back of the chassis.

Step 6

Afterward, connect the motor wires to the motor terminals. Then, install the battery holder and connect the power jack to the DC power port.

Step 7

Now, connect the Arduino Nano board, the L293D motor driver, and the IR receiver to the PCB. Then, connect the Arduino board to your computer.

Step 8

Next, copy and paste the following program into the Arduino IDE. Also, make sure to include the library file first.

#include <IRremote.hpp>

#define IR_RECEIVE_PIN 3

#define ENA 5
#define ENB 6

#define IN1 7
#define IN2 8
#define IN3 9
#define IN4 10

#define LED1 11
#define LED2 12
#define Buzzer 13

#define Speed 180

// Remote button codes (replace with actual values if needed)
#define up 0
#define down 0
#define left 0
#define right 0
#define stop 0
#define lights 0
#define turbo 0        
#define dance 0

int currentSpeed = Speed;

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(Buzzer, OUTPUT);
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);
  
  Serial.begin(115200);
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
}

void loop() {
  if (IrReceiver.decode()) {
    unsigned long command = IrReceiver.decodedIRData.decodedRawData;
    Serial.println(command);
    IrReceiver.resume();

    if (command == up) {
      Forward();
    } else if (command == down) {
      Backward();
    } else if (command == left) {
      Left();
    } else if (command == right) {
      Right();
    } else if (command == stop) {
      Stop();
    } else if (command == lights) {
      digitalWrite(LED1, !digitalRead(LED1));
      digitalWrite(LED2, !digitalRead(LED2));
    } else if (command == turbo) {
      currentSpeed = 255;
      Forward();
    } else if (command == dance) {
      Dance();
    } else {
      currentSpeed = Speed;  // Reset speed to normal
    }
  }
}

// Movement Functions
void Forward() {
  analogWrite(ENA, currentSpeed);
  analogWrite(ENB, currentSpeed);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
}

void Backward() {
  analogWrite(ENA, currentSpeed);
  analogWrite(ENB, currentSpeed);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
}

void Stop() {
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
}

void Left() {
  analogWrite(ENA, currentSpeed);
  analogWrite(ENB, currentSpeed);
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);
  //BlinkLED(LED1);  // Left indicator
}

void Right() {
  analogWrite(ENA, currentSpeed);
  analogWrite(ENB, currentSpeed);
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  //BlinkLED(LED2);  // Right indicator
}

// Turning Indicator
void BlinkLED(int ledPin) {
  digitalWrite(ledPin, HIGH);
  delay(100);
  digitalWrite(ledPin, LOW);
  delay(100);
}

// Dance Mode
void Dance() {
  Forward(); delay(300);
  Backward(); delay(300);
  Left(); delay(300);
  Right(); delay(300);
  Stop();
}
  • Now, select the board and port. After, click the upload button.
  • After that, open the Serial Monitor and get the IR remote button values. You can use any IR remote for this. I used eight buttons for my project.
  • Then, copy and paste these values into the main program and click the upload button again.

Step 9

Finally, put the batteries into the battery holder. Now, you can test the car using your IR remote. Enjoy this project! The full video guide is below. We hope to see you in the next project. Have a great day!

How to Make a 2WD IR Remote Controlled Car with Arduino Nano

Similar Posts

Leave a Reply

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