Introduction: TV Remote Control Car

About: I build robots with Arduino and Raspberry Pi

This is a remote controlled car using any TV remote with a distance sensor for crash prevention. This is fairly easy and cheap to make. I would suggest getting an Arduino kit and I would highly recommend getting this kit or this because it includes so many things for many good projects at a good price.

Supplies

Computer with the Arduino software

2 wheel drive chassis (This come with motors and gearboxes for it)

Arduino (Pretty much any)

TV remote (any IR remote)

IR receiver

L293D Motor driver

9-12V Power source (For the motors. You could get just this and not the one above)

Jumper Wires

Arduino Prototyping shield with mini breadboard (get one that is compatible with your Arduino, this one is for the UNO)

Double sided foam tape (Or Blutack)

Optional:

HC-SR04 distance sensor

LED with resistor (preferably 220R ohms)

Step 1: Building the Chassis

The chassis comes with two motors in a gearbox ready to use so all you need to do is peel of the brown tape in the chassis and screw on the motors. Make sure to follow the instructions carefully. Don't put on the battery pack it came with because you will be using another power source. Stick down the Arduino with Blu tack or double sided foam tape at the back in a central position.

Step 2: Wiring

Wire this on the prototyping shield (not the Arduino because we will put the shield on the Arduino later). Get your breadboard and place the L293D chip on it like in the picture. There's is a dot at the top left of the chip and that is called pin 1. Underneath pin one is pin 2 and so on. The bottom left of the chip is pin 8 then pin 9 starts opposite it (bottom right) the pin above the bottom right is pin 10 and so on till the top right is pin 16.

Connect:

Pin 1 - 5V

Pin 2 - Digital pin

Pin 3 - The left motors left connection

Pin 4 - Ground

Pin 5 - Ground

Pin 6 - The left motors right connection

Pin 7 - Digital pin

Pin 8 - 9V-12V external power source (connect to + and the - to ground)

Pin 9 - 5V

Pin 10 - Digital pin

Pin 11 - The right motors left connection

Pin 12 - Ground

Pin 13 - Ground

Pin 14 - The right motors right connection

Pin 15 - Digital pin

Pin 16 - 5V

Plug the positive connection of the 9V battery (the one for the Arduino) connector to Vin on the Arduino and the negative to Ground.

If you want to add a 3 pin switch, connect the pin on the edge (either edge, it doesn't matter) to 5V and the middle pin to Ground

Step 3: IR Receiver and Remote

Connect the receiver in an open place in view. With the ball facing you, the left lead to digital pin 12. The middle to Ground and the right to 5V. Go to file, examples, and near the bottom 'IRremote' and find 'IRrecvDemo'. Get your TV/IR remote and open the serial monitor and click the up button, down, left, right then select (in between the direction buttons). Leave the serial monitor open. Get a piece of paper and open this website, copy the value into the converter and write down the numbers it gave you with the button you pressed. Do this for all 5 buttons/values.

Step 4: Optional Distance Sensor and Led

If you want a sensor to avoid collision, then get the HC-SR04 and plug Vcc to 5v, Gnd to Ground, Trig to digital pin 5 and Echo to digital pin 6. Stick this down on the front of the robot. Delete the /* on line 46 and the */ on line 57 of the code before uploading it to the Arduino.

If you want a led indicator for when a button is pressed on the remote and the Arduino receives it, then insert it into the breadboard and connect the shorter leg of the led to ground then the longer one to the resistor then to digital pin 13. The on board 'L' led will also work as the same but you can't see it with all the components on top.

Step 5: Putting It Together

Stick your Arduino down with double sided foam tape and carefully insert your prototyping shield in correctly. Your breadboard should already be placed on the middle of the shield with all the wiring connected. Make sure the distance sensor is stuck down properly at the front if you have one and the IR receiver is in the open view.

Step 6: The Code

#include "SR04.h"

#define TRIG_PIN 5 #define ECHO_PIN 6 SR04 sr04 = SR04(ECHO_PIN, TRIG_PIN); long a;

#include "IRremote.h" int RECV_PIN = 12; IRrecv irrecv(RECV_PIN); decode_results results;

//Below are the symbolic constants. Instead of having to type in a non-sensical pin number each time we want to do something we can write an easy to understand name which represents the pin, the compiler will then replace the names with the numbers #define LeftMotorForward 10 #define LeftMotorBackward 11 #define RightMotorForward 8 #define RightMotorBackward 9

#define redoff = FD00FF; //16580863 This is an example of where to type the numbers from the online converter #define volup = FD807F; //16613503 #define skipforward = FD609F; //16605343 https://www.binaryhexconverter.com/hex-to-decimal... #define skipback = FD20DF; //16589023 #define voldown = FD906F; //16617583

int led = 13;

void setup() //This block happens once on startup { Serial.begin(9600); //I have included the serial initialize but commented it out, if you want to debug and print information to the serial monitor just uncomment pinMode(LeftMotorForward, OUTPUT); pinMode(LeftMotorBackward, OUTPUT); pinMode(RightMotorForward, OUTPUT); pinMode(RightMotorBackward, OUTPUT);

pinMode(led, OUTPUT); digitalWrite(led, LOW);

irrecv.enableIRIn(); }

void loop() { /* a = sr04.Distance(); if (a <= 15) { Serial.println(""); Serial.println("Stopping"); digitalWrite(LeftMotorBackward, LOW); digitalWrite(LeftMotorForward, LOW); digitalWrite(RightMotorForward, LOW); digitalWrite(RightMotorBackward, LOW); moveStop(); } */

digitalWrite(led, LOW); if (irrecv.decode(&results)) { Serial.println(results.value, HEX); irrecv.resume(); // Receive the next value

switch (results.value) { case 16580863: moveStop(); //this is the button in the middle of the direction arrows (select) digitalWrite(led, HIGH); delay(300); break;

case 16613503: moveForward(); //Up arrow digitalWrite(led, HIGH); delay(300); break;

case 16605343: moveRight(); digitalWrite(led, HIGH); delay(300); //Right arrow break;

case 16589023: moveLeft(); //left arrow digitalWrite(led, HIGH); delay(300); break;

case 16617583: moveBackward(); //down arrow digitalWrite(led, HIGH); delay(300); break;

} irrecv.resume(); } }

void moveForward() //This function tells the robot to go forward { Serial.println(""); Serial.println("Moving forward"); digitalWrite(LeftMotorBackward, LOW); digitalWrite(LeftMotorForward, HIGH); digitalWrite(RightMotorBackward, LOW); digitalWrite(RightMotorForward, HIGH); }

void moveBackward() //This function tells the robot to move backward { Serial.println(""); Serial.println("Moving backward"); digitalWrite(LeftMotorForward, LOW); digitalWrite(LeftMotorBackward, HIGH); digitalWrite(RightMotorForward, LOW); digitalWrite(RightMotorBackward, HIGH); }

void moveLeft() //This function tells the robot to turn left { Serial.println(""); Serial.println("Moving left"); digitalWrite(LeftMotorForward, LOW); digitalWrite(LeftMotorBackward, HIGH); digitalWrite(RightMotorBackward, LOW); digitalWrite(RightMotorForward, HIGH); delay(150); digitalWrite(LeftMotorForward, LOW); digitalWrite(LeftMotorBackward, LOW); digitalWrite(RightMotorBackward, LOW); digitalWrite(RightMotorForward, LOW);

}

void moveRight() //This function tells the robot to turn right { Serial.println(""); Serial.println("Moving right"); digitalWrite(LeftMotorBackward, LOW); digitalWrite(LeftMotorForward, HIGH); digitalWrite(RightMotorForward, LOW); digitalWrite(RightMotorBackward, HIGH); delay(150); digitalWrite(LeftMotorForward, LOW); digitalWrite(LeftMotorBackward, LOW); digitalWrite(RightMotorBackward, LOW); digitalWrite(RightMotorForward, LOW); }

void moveStop() //This function tells the robot to stop moving { Serial.println(""); Serial.println("Stopping"); digitalWrite(LeftMotorBackward, LOW); digitalWrite(LeftMotorForward, LOW); digitalWrite(RightMotorForward, LOW); digitalWrite(RightMotorBackward, LOW); }

Copy and paste this into a new Arduino sketch and have the values from the ir remote control demo ready. On line 67 it shows "case 16580863:". I wrote a comments for you which tells you that this is the select button in the middle of the directional buttons. Change the number to the one you wrote down for this. Change all the numbers on the lines where it has 'case .......' and change them to the correct corresponding button. Upload this to the board.

Upload the file above into the Arduino software. If a problem occurs to do with there being no libraries for SR04.h or IRremote.h, download this and this by clicking the green button clone or download and click download .zip. In the Arduino software, click sketch, then include library, then add .zip library and find where you downloaded them .zips and click ok and do this for both.

Close the sketch (the Arduino software) and re open the code. Upload the code and if there is still problems, ask me in the comments section underneath this Instructable.

Arduino Contest 2020

Participated in the
Arduino Contest 2020