"IR Controlled car using Arduino"


-------------------------------------------------*******************************----------------------------------------


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


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();
}
}

-------------------------**************************-------------------------------/////////////////////////////////--------------------------

Visit my website SR Automation and Robotics and signup for more interesting projects like this.
Follow us on facebook @ SR Automation & Robotics
Subscribe to my youtube channel SR Automation & Robotics






Comments

Post a Comment

Popular posts from this blog

Bluetooth controlled car using Arduino