Robotics

My Blog

Latest blog
Previously we learnt how to decode IR signals using Arduino and how to use  these signals to control LEDs. It was pretty basic setup and a good project to get started. Today we will use that knowledge to build a simple robot car which will be controlled using an IR remote. I suggest you check out "Everything you need to know about motor drivers" article to get a better understanding on how to control the motors.

With out any further ado, lets get right into it.

Requirements: 

For any projects we need some materials. Here I have listed all the hardware and software requirements for this project.

Hardware:

  1. Arduino Uno   (Amazon Link)
  2. Arduino Motor Shield v1.0   (Amazon Link)
  3. 2 x Geared Motor   (Amazon Link)
  4. 2 x Wheels   (Amazon Link)
  5. Caster Wheel   (Amazon Link)
  6. 2WD Chassis   (Amazon Link)
  7. 1838 IR Receiver   (Amazon Link)
  8. 3 x Female Headers   (Amazon Link)
  9. 4 x 3.7v Li-ion batteries   (Amazon Link)
  10.  Li-ion Battery Holder   (Amazon Link)
  11. LM2596 5v Voltage Regulator   (Amazon Link)
  12. DC Power Jack   (Amazon Link)
  13. IR Remote   (Amazon Link)
NOTE: Make sure you use the same IR receiver as I have used here. Also The 2WD chassis are not required if you will make your own platform as I have.

Software:

  1. Arduino IDE: For writing and uploading code
  2. SketchUp : For designing Chassis  
That's all the things we need for this project, now lets move on to next step, designing chassis.

Building Chassis:

Building chassis is an optional part here, you can just skip this step and get yourself a 2WD robot chassis. I have built myself one using foamboard, The design is pretty simple you can find a SketchUp file below:

arduino robot


You can make your own design as you want, just make sure all the components fit in properly.

IR Robot CAD File

Making Circuit: 

The circuit is pretty straight forward, The motor shield is placed on top of the Arduino board and the IR receiver is connected to A0 pin. Refer the following image.

1838 IR receiver

Here I have soldered the pins of the receiver directly to female headers. Which can be connected to the motor shield directly as shown below:

arduino motor shield


Note:-  If you are not familiar with 1838 IR receiver, check out this article.

Now about the power supply, we need two. One for Arduino (9-12v) another for Motorshield (12-30v). For our motor requirements we need atleast 12v so we will use a 4cell 18650 battery pack. 4x3.7 will give us 14.5v which is enough for motor drive.

But now the problem is about arduino, we cannot power the microcontroller with more than 12v. To solve this problem I have used a DC to DC voltage regulator. 
Check the power supply circuit diagram given below for better understanding.


This is pretty simple circuit and needs no further explanation. But before you connect the output to arduino, use a multi meter to check if the voltage is between 9-12v. You can adjust the voltage by adjusting the screw on the trimmer. 

Coding:

Now we can write the code to control our robot. 
First get any IR remote you wish to use and decode its IR signals. If you have no idea how to do that, check out this article

Once you have successfully decoded the IR signals of the buttons on your remote, you should have some hex numbers as: 20DF02FD, 20DFE01F, etc. 

We will use these codes in the script below:

Note: Make sure that you have the ""IRremote" and "AFMotor" libraries installed in IDE.

#include <AFMotor.h>
#include <IRremote.h>
int RECV_PIN = A0; //data out of IR receiver connects to pin A0 
AF_DCMotor motor1(3); 
AF_DCMotor motor2(4);
IRrecv irrecv(RECV_PIN); 
decode_results results; 

void setup() 

 Serial.begin(9600); 
 irrecv.enableIRIn(); // start the receiver 
 motor1.setSpeed(100); 
 motor2.setSpeed(100); 


void loop() 

 if (irrecv.decode(&results)) 
{ Serial.println(results.value, HEX); 
 irrecv.resume(); // Receive the next value 
 if (results.value==0x20DF02FD)
{ //Go Forward 
 motor2.run(FORWARD); 
 motor1.run(FORWARD); 
 motor1.setSpeed(100); 
 motor2.setSpeed(100);

if (results.value==0x20DF827D)
{ //Go Backward 
 motor1.run(BACKWARD); 
 motor2.run(BACKWARD); 
 motor1.setSpeed(100); 
 motor2.setSpeed(100);

 if (results.value==0x20DFE01F)
{ //turn left 
 motor1.run(FORWARD); 
 motor2.run(BACKWARD); 
 motor1.setSpeed(80); 
 motor2.setSpeed(80);

if (results.value==0x20DF609F)
{ //turn right 
 motor1.run(BACKWARD); 
 motor2.run(FORWARD); 
 motor1.setSpeed(80); 
 motor2.setSpeed(80);

 if (results.value==0x20DF22DD)
{ //stop
 motor1.run(RELEASE); 
 motor2.run(RELEASE);

 irrecv.resume(); 
}
}

In the above codes just replace the codes with yours and make sure to put the '0x' prefix.
Now you can power up the robot and start controlling it with your IR remote.

Final Note:

Here is a look at the robot I made, you can go ahead and make your own design. 

arduino robot


Also you might like to increase the speed of the robot, to so that just increase the number in the setSpeed() function. It can be anywhere between 0-255, where 0 will stop the motors completely and 255 will set the highest speed as per the motor.

With that been said, you can now make robot and play around. If you have any questions or doubts, feel free to comment down below.

Contact Us

Contact With Us

Followers

Translate

Get in touch with us.

  • +91 7276861817
  • projecthub.in@protonmail.com