Sri Lanka's First and Only Platform for Luxury Houses and Apartment for Sale, Rent

Saturday, October 19, 2013

Giving RC Car a simple brain using Arduino + Ping (Ultrasonic) Sensor

It has been quite a sometime from my last post. Mainly due to busy schedules and settling down in Malaysia I would say. But I came to back to Sri Lanka on vacation and got time on a lazy Saturday morning and put together a small Arduino + RC Car setup.

In one of my previous posts I teared down a RC Car and explained the internals of that. Working further on that I managed to write a small Arduino sketch to work with a Ping Sensor to give a simple brain to the RC Car. What makes this distinguishable from other RC Car + Arduino hacks is that, Almost all other hacks use the Arduino to control the Remote Control not the Car itself. But I wanted to control the car directly using the Arduino so that I can eventually achieve the goal of using an Android phone connected to Arduino using a USB Host Shield to act as the Smart Brain of the RC Car.

The following items were used in setting up this prototype.
  1. 1 Arduino UNO Rev 3
  2. 1 Breadboard
  3. 1 DFRobot URM37 V3.2 Ultrasonic Sensor
  4. Some Jumper Cables
  5. And of course a RC Car
Following is the Arduino Sketch. The DFRobot Ultrasonic Sensor was used in TTL Mode and Arduino Pin 3 was connected to PWM and 5 was connected to COMP/TRIG of the Sensor. The Arduino Digital Out pin 11 was used for forward actuating and pin 10 was used for backward actuating of the RC Car . I have soldered jumper cables to the RC Car so that they can be easily used and distinguished. 

int URPWM = 3; 
int URTRIG=5; 
int forwardPin = 11;
int backwardPin = 10;
unsigned int Distance=0;
uint8_t EnPwmCmd[4]={0x44,0x02,0xbb,0x01};    
boolean forward = false;
boolean backward = false;
int minDistanceCm = 5;

void setup(){                                 
  pinMode(URPWM, INPUT);                      
  pinMode(forwardPin, OUTPUT);
  pinMode(backwardPin, OUTPUT);
void loop()
   digitalWrite(URTRIG, LOW);
   digitalWrite(URTRIG, HIGH);               
   unsigned long DistanceMeasured=pulseIn(URPWM,LOW);
   } else {
   if(Distance > minDistanceCm) {
      forward = true;  
      backward = false;
   } else {
      forward = false;
      backward = true; 
   if(forward) {
      digitalWrite(forwardPin, HIGH);
      digitalWrite(forwardPin, LOW);
   } else {
      digitalWrite(backwardPin, HIGH);
      digitalWrite(backwardPin, LOW);     

The video below shows the prototype in action. The USB cable is only used to supply electricity for the Arduino. Adding a battery will eliminate the need for the USB cable.

This prototype is by no means complete. I did this so that I can achieve the goal of using an Android phone with Camera + GPS as the brain. But this step was a necessary and crucial learning stage for me. Constructive criticism is always welcome.

  1. DFRobot Ultrasonic Sensor Manual -

No comments: