IR Controlled Car
This is a simple IR controlled car built with an Arduino Nano and a HG7881 motor driver. It has two geared drive motors and can be controlled with a TV remote. It runs on two 3.7v Li ion 18650 batteries, one for the Arduino Nano and one for the motor driver which last for a very long time.
Supplies
Parts Required.
- Arduino Nano and programming cable 1x
- HG7881 motor driver 1x
- Switch 1x
- Geared motors and wheels 2x
- 400 pin breadboard 1x
- + battery terminals 2x
- - battery terminals 2x
- Male to female jumper wires 9x
- 3D printed parts
- M2 washer 2x
- M4 washer 2x
- M2 bolt 2x
- M2 nut 2x
- IR receiver 1x
- Male to male jumper wires 2x
- 3.7v Li ion 18650 batteries 2x
Tools Required.
- Soldering iron
- Glue gun
- 3D printer
Software Required
- Arduino IDE
- Cura or some other 3D printing software.
3D Printing the Parts.
The first step is to print the parts for the robot. I printed parts 2 and 3 with a resolution of .10 mm and the rest of the parts with a resolution of .20 mm.
Attaching the Motors and the Motor Driver.
In this step we will attach the motors and the motor driver. Use the M2 bolts, nuts, and washers to attach the motor driver to the frame of the robot. If your motor driver doesn't have holes or they don't line up you can glue it down. I also glued the motor wires to the frame so they wouldn't be in the way.
Attaching the Breadboard.
Now we will attach the Arduino Nano and the breadboard to the main part of the robot.
Stick the Arduino Nano onto the breadboard and then plug in the jumper wires. If you don't have solid core wire you can always use flexible jumper wires or just wire.
The Battery Terminals.
Next we will attach the battery terminals and the switch then plug it all in to the breadboard.
First get four battery terminals (two positive and two negative) and solder wires onto them. Then slide the negative terminals into place on the right side of the battery pack and plug one wire into the negative part of the left power rail and the other one on the negative part of the right power rail.
For the positive terminals solder the two ends of the wire together and then solder the switch on. Next get two wires and solder them onto the other pin of the switch. Then glue the switch onto the robot body and plug one of the pins into the Vin pin of the Arduino nano and the other into the positive part of the power rail by the battery pack.
The Motor Driver Wires.
In this step we will attach the wires for the motor driver.
Get six male to female jumper wires and plug them into the motor driver as shown. then attach the other ends of the wires to the Arduino Nano. After that use electrical tape to wrap up the wires.
- Green goes to pin 9
- Blue goes to pin 10
- Gray goes to the + side of the power rail by the battery pack.
- Purple goes to the - side of the power rail by the battery pack.
- White goes to pin 12
- Black goes to pin 11
After that use electrical tape to wrap up the wires.
The IR Receiver
In this step we will attach the IR receiver.
Get three male to female jumper wires and attach them to the IR receiver as shown. Then tape or glue it to the part in the front of the robot and plug in the wires.
- Black goes to the - side of the power rail by the motor driver.
- red goes to the + side of the power rail by the motor driver.
- Brown goes to pin 8
Then use tape to wrap up the wires and glue them to the robot body.
The Front and Back Wheels.
Now we will attach the front and back wheels.
Get the wheels for the geared motors and slide them on to the geared motors.
For the front wheel get one of the wheel support with the pin and put an M4 washer on it. Then put the 3D printed wheel on top of it. Next put another M4 washer on top and put the other wheel support on top. Then stick it in the holes in the front of the robot.
The Code.
In this step we will upload the code to the robot
Before we upload the code we need to find the code of the remote. first upload the IR decoder code to the robot and push a button on the remote and the code to that button will show in the serial monitor. If you want the robot to go forward when the up button of the remote is pushed, use the decoder to decode that button then copy the top number sequence from the serial monitor to the line of code that makes the robot go forward.
Example.
switch (results.value) {
case 752:// This is the number the decoder showed when I pushed the up button. It will be different on your remote.
Serial.println("up");
digitalWrite(M1pin1, LOW);
digitalWrite(M1pin2, HIGH);
digitalWrite(M2pin1, HIGH);
digitalWrite(M2pin2, LOW);
break;
}
I hope this makes sense to you. If not please leave a comment and I will try to explain it to you better.
Testing the Robot.
Now we will test the robot.
Get the batteries for the robot and put them in with the + on one side and the - on the other.( The + goes on the springs.) Then turn on the switch and the motor driver LED and the Arduino LED should turn on. Then push one of the buttons that you have programmed in to the robot and it should respond to it.
Have Fun!
Troubleshooting.
If your robot is not working try doing some of these things things to fix it.
- If the robot is turning right when you want it to go forward switch the white and black wires around.
- if the robot is turning left when you want it to go forward switch the green and blue wires around.
- if the robot is going backwards when you want it to go forward switch the green and blue wires around and switch the black and white wires around.
- if the motor driver light is dimming a lot and the robot is not moving recharge the batteries.
- if the motor driver light is not lighting up switch the battery that goes to the motor driver around.
- if the robot is not responding to the remote try using a different remote.
- if the code is not uploading make sure that the processor is switched to the ATmega328P(Old Bootloader) if your Arduino Nano you are using was made before 2018. If it was made after 2018, switch it to ATmega328P.
- if the front wheel is falling off glue the part that is falling off together.
If you have any more problems please leave a comment below.