Remote controlled Car Using Arduino

Remote controlled Car Using Arduino
One of the common applications of IR receivers is in remote controlled car using Arduino as shown in this tutorial. The other major component of this project is the L298N motor driver whose functioning has already been discussed in a previous tutorial.
Before proceeding you should first know the working of IR receivers, decoding of IR remotes and DC motor control usingthe L298N motor driver. This knowlegde can be got by visiting the following posts:
  • Arduino IR remote control of Leds
  • DC motor control using L298N motor driver and Arduino
  • Schematic for the remote controlled car

    remote controlled car schematic
    NOTE: This project of remote controlled car using arduino  is highly dependent on a stable power supply to be able to run the four DC motors for a longer period of time. I recommend using rechargeable batteries.
    You can buy the parts from this project from these recommended links.
    YIKESHU 4WD 2 Layer Smart Robot Car Chassis Kit with Speed Encoder Battery Box for Kids Teens DIY
    Qunqi 2Packs L298N Motor Drive Controller Board Module Dual H Bridge DC Stepper For Arduino
    WINGONEER Infrared IR Wireless Remote Control Sensor Module Kits for Arduino
    Energizer NH15BP-8 Rechargeable AA Batteries, 2300 mAh, Pre-Charged, 8 count (Recharge Power Plus)
    Product
    4-Wheel Smart Car Robot Chassis
    L298N Motor Driver
    IR Receiver and Remote control
    Rechargeable batteries
    Price
    $16.99
    $8.89
    $8.99
    $19.96
    YIKESHU 4WD 2 Layer Smart Robot Car Chassis Kit with Speed Encoder Battery Box for Kids Teens DIY
    Product
    4-Wheel Smart Car Robot Chassis
    Price
    $16.99
    Buy Now
    Qunqi 2Packs L298N Motor Drive Controller Board Module Dual H Bridge DC Stepper For Arduino
    Product
    L298N Motor Driver
    Price
    $8.89
    Buy Now
    WINGONEER Infrared IR Wireless Remote Control Sensor Module Kits for Arduino
    Product
    IR Receiver and Remote control
    Price
    $8.99
    Buy Now
    Energizer NH15BP-8 Rechargeable AA Batteries, 2300 mAh, Pre-Charged, 8 count (Recharge Power Plus)
    Product
    Rechargeable batteries
    Price
    $19.96
    Buy Now

    Last update on 2021-04-14 / Affiliate links / Images from Amazon Product Advertising API

    CODE

    This code is simply for controlling the movement of the four DC motors attached to the L298N motor driver using a remote control that has been decoded so that when a specific button of the remote is pressed, the motors will turn in a given direction thereby controlling the overall movement of the car.
    #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();
    }
    }   
    
    NOTE:
  • The first part of this code involves using the numbers got from decoding the different buttons of the remote that are going to be used. These values differ for every remote.
  • The state of the different pins to determine the direction of movement of the motors depends on how you have connected the motors to the L298N Motor driver, therefore you have to troubleshoot your setup by either changing the code or the motor connection
  • One thought on “Remote controlled Car Using Arduino

    1. Hi there, great post. I actually was hoping you could help me with something. Do you prefer the electric motors or gas motors in your RC cars? It seems like the gas ones are more expensive but not much better. I’m trying to figure it out before I drop too much on something I’ll regret. Thanks for your help.

    Leave a Reply

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

    Back to top