Subscribe To Our List

We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
Email address
Secure and Spam free...

In this project, we are going to make a Arduino Robot Car which will be controlled using the remote. The remote that we will use can be any remote i.e. T.V remote, DVD player remote or even you can use the remote APP for mobile to control it. We will use the IR sensor for receiving the signals from the remote and then we will move the Arduino robot car according to that.

Required Components for Arduino Robot Car

The components required for making Arduino Robot Car are as follows. Click on the link to buy from amazon.

Circuit Diagram and Explanation

First of all, we will make the connections for the L298N motor driver with the Arduino. Connect the motor driver pins to the Arduino as follows

  • ENA to pin 13 of Arduino
  • IN1 to pin 12 of Arduino
  • IN2 to pins 11 of Arduino
  • IN3 to pin 10 of Arduino
  • IN4 to pin 9 of Arduino
  • ENB to pin 8 of Arduino

After that, connect the motors at the two sides of the L298N motor driver. To power the L298N motor driver, we will have to give it 7 to 12V. Connect the positive of your battery to the 12V pin and the negative of your battery to the GND of L298N. Then connect the 5V pin of L298N to the VIN of Arduino and also make the connection from the GND of L298N to the GND of Arduino.

If you want to control motors using the L293D motor controller, then follow this Tutorial | L293D Motor Driver IC with Arduino

In the end, connect the IR sensor 1838B to the digital pins of Arduino. Connect the GND of IR sensor to the pin 6 of Arduino, VCC of IR sensor to the pin 5 of Arduino and the signal pin of IR sensor to the pin 4 of Arduino.

If you want to read more about interfacing IR sensor with Arduino, then follow this Tutorial | Arduino IR Sensor Tutorial

Arduino Robot car

 

Working

In the Arduino program, we have saved the codes for the buttons that we will use to move the Arduino robot car. Whenever we will press the button from the remote, the remote will send a IR signal in the form of a code to the IR sensor. The IR sensor will receive this signal and will give it to the Arduino.

The Arduino will then decode this signal and it will be compared with the codes that we have saved in our Arduino program. If any of the code  will match, then the Arduino will executes the commands written inside it and the Arduino robot car will move according to that.

How to run it

To upload the code to the Arduino, remove the battery wires from the circuit and then upload the code. After uploading the code, open the serial monitor and press the buttons from the remote. You will receive the code for the buttons like I received from my remote as below

Now put the codes you have received in the Arduino code in place of the already saved codes for the buttons.

Now remove the cable from the Arduino and connect the battery wires. Now press the buttons and the Arduino robot car will move according to that.

Code

Before uploading the code to the Arduino, download the IRremote library from here and add into your library folder.

#include <IRremote.h>   // including the IR remote library

#define forward  58359 // code received from forward  button
#define backward  5499  // code received from backward button
#define left  25979 // code received from left button
#define right  59295 // code received from right button
#define stop_button  15547 // code received from stop button

// Pins for first motor
int EN_A = 13;
int IN_1 = 12;
int IN_2 = 11;
// Pins for second motor
int EN_B = 8;
int IN_3 = 10;
int IN_4 = 9;

char command;
int receiver_pin = 4;   //Connect the output pin of IR receiver at pin 4
int vcc = 5;            //VCC for IR sensor
int gnd = 6;            //GND for IR sensor
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 as output pins
  pinMode(vcc, OUTPUT);
  pinMode(gnd, OUTPUT);
  pinMode(EN_A, OUTPUT);
  pinMode(EN_B, OUTPUT);
  pinMode(IN_1, OUTPUT);
  pinMode(IN_2, OUTPUT);
  pinMode(IN_3, OUTPUT);
  pinMode(IN_4, OUTPUT);
  
// Initializing ENA, ENB and vcc pin high
  digitalWrite(vcc, HIGH);
  digitalWrite(EN_A, HIGH);
  digitalWrite(EN_B, HIGH);
}

void loop() {
  if (receiver.decode(&output)) {
    unsigned int value = output.value;
    switch(value) {
     
  case forward:
      //Moving Forward
  digitalWrite(IN_1, HIGH);
  digitalWrite(IN_2, LOW); 
  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, HIGH);
          break;
       
case backward:
      //Moving backward
  digitalWrite(IN_1, LOW);
  digitalWrite(IN_2, HIGH); 
  digitalWrite(IN_3, HIGH);
  digitalWrite(IN_4, LOW);
         break;
       
case left:
       //Turning left
  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, HIGH);
          break;  
        
  case right:
        //Turning Right
  digitalWrite(IN_1, HIGH);
  digitalWrite(IN_2, LOW);
          break;
       
  case stop_button:
        //Stop
  digitalWrite(IN_1, LOW);
  digitalWrite(IN_2, LOW); 
  digitalWrite(IN_3, LOW);
  digitalWrite(IN_4, LOW);
          break;
}
    Serial.println(value);
    receiver.resume();
}
}

 Code Explanation

First of all, we have added the library for the IR sensor which will help in communication between the Arduino and the IR sensor. After that, we added the codes for the buttons which we are going o use. We are going to use five buttons of the remote.

#include <IRremote.h>   // including the IR remote library
#define forward  58359 // code received from forward  button
#define backward  5499  // code received from backward button
#define left  25979 // code received from left button
#define right  59295 // code received from right button
#define stop_button  15547 // code received from stop button

We have initialized the pin 4 as the signal pin for IR sensor and two other pins as the VCC and the gnd for IR sensor. We have connected the IR sensor directly to Arduino and have given the VCC and the gnd from the Arduino digital pins. The IRrecv receiver() command will tell the Arduino that where we have connected the IR sensor signal pin. The “decode_results output” will decode the output in the code form.

int receiver_pin = 4;   //Connect the output pin of IR receiver at pin 4
int vcc = 5;            //VCC for IR sensor
int gnd = 6;            //GND for IR sensor
IRrecv receiver(receiver_pin); //Arduino will take output of IR receiver from pin 2
decode_results output;

We have made the VCC and the ENA, ENB pins high. The VCC pin will give 5V to the IR sensor to power up and the reason for making the ENA, ENB high is that it will allow the motors of the robot car to run. If the enable pins won’t be high, then the motors will not move.

  digitalWrite(vcc, HIGH);
  digitalWrite(EN_A, HIGH);
  digitalWrite(EN_B, HIGH);

In the loop function, the Arduino will take the output from the IR sensor and will convert this output in the code form. This output will then be compared with the codes that we have saved earlier. If the received code will match with any of the saved code, then the robot car will move according to the code written in it.

if (receiver.decode(&output)) {
    unsigned int value = output.value;
    switch(value) {
       case forward:
      //Moving Forward
  digitalWrite(IN_1, HIGH);
  digitalWrite(IN_2, LOW); 
.
.
.

 Video

If you have any questions, feel free to ask us in the comment section.

JOIN OUR NEWSLETTER
We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
We hate spam. Your email address will not be sold or shared with anyone else.

Leave a Reply

Your email address will not be published.

Subscribe To Our List

We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
Email address
Secure and Spam free...
Skip to toolbar