Project showcase
Arduino Controlled Car with HC-SR04

Arduino Controlled Car with HC-SR04 © GPL3+

Convert an ordinary RC car into an extraordinary obstacle-avoiding robot.

  • 10,095 views
  • 1 comment
  • 12 respects

Components and supplies

Apps and online services

About this project

With this project I want to show you how to convert an RC car into an Auto Controlled car with Arduino Uno R3.

Wiring

I opened the car and found the PCB which is controlling the two motors. I identified the points that are responsible for the four motor movements (left motor front, left motor back, right motor front, right motor back) and soldered four wires on to them. Then I connected those to the pins 9, 10, 11, 12 of the Arduino board as shown in the picture. Lastly, I connected the GND of the H-BRIDGE to the GND of the Arduino board.

Then I connected the Ultrasonic sensor to the Arduino board like this:

  • VCC pin to pin 5V
  • GND pin to GND pin
  • Trig pin to pin 8
  • Echo pin to pin 7

To power the Arduino I joined it with a 9V battery to the DC jack and because I didn't want to waste the battery's power I cut the Volt wire and soldered an On/Off switch. Then to make it more stylish I made a hole at the car with the electric drill at the size of the switch and put it in there.

Demo

Code

ProgramArduino
/*
 HC-SR04 Ping distance sensor:
 VCC to arduino 5v 
 GND to arduino GND
 Echo to Arduino pin 7 
 Trig to Arduino pin 8

 */


#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
#define Pin 9
#define Pin 10
#define Pin 11
#define Pin 12

int maximumRange = 55; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance

int forward = 9; // forward pin
int front = 10; // front pin
int reverse = 11; // reverse pin
int back = 12; // back pin


void setup() {
 Serial.begin (9600);
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(forward, OUTPUT);
 pinMode(front, OUTPUT);
 pinMode(reverse, OUTPUT);
 pinMode(back, OUTPUT);
}

void go_forward()
{
digitalWrite(forward,HIGH); // turn forward motor on
digitalWrite(front,HIGH); // turn front motor on
digitalWrite(reverse,LOW); // turn reverse motor off
digitalWrite(back,LOW); // turn back motor off
}
void go_rvrs()
{
digitalWrite(forward,LOW); // turn forward motor off
digitalWrite(front,LOW); // turn front motor off
digitalWrite(reverse,HIGH); // turn reverse motor on
digitalWrite(back,HIGH); // turn back motor on
}

void stop_car()
{
digitalWrite(reverse,LOW); // turn reverse motor off
digitalWrite(forward,LOW); // turn forward motor off
digitalWrite(front,LOW);
digitalWrite(back,LOW);
}
void go_right()
{
digitalWrite(forward,HIGH); // turn forward motor on
digitalWrite(back,HIGH); // turn back motor on
digitalWrite(reverse,LOW); // turn reverse motor off  
digitalWrite(front,LOW); // turn front motor off
}
// the loop() method runs over and over again,
// as long as the Arduino has power





void loop() {
/* 
The following trigPin/echoPin cycle is used to determine the
 distance of the nearest object by bouncing soundwaves off of it. 
*/ 
 digitalWrite(trigPin, LOW); 
 delayMicroseconds(2); 

 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10); 
 
 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);
 
 //Calculate the distance (in cm) based on the speed of sound.
 distance = duration/58.2;
 
 

if (distance > maximumRange || distance < minimumRange){
 /* Send a positive number to computer and Turn MOTORS ON 
 to indicate "out of range" */
 Serial.println("1");
 go_forward();


}
 else {
  go_rvrs();
  delay(250);
  go_right();
 delay(500);
 
 
 }
 //Delay 50ms before next reading.
 delay(50);

Comments

Similar projects you might like

RC Car to BT Car Controlled with Blynk

Project tutorial by Team Daxes Hacks

  • 3,598 views
  • 2 comments
  • 6 respects

PlayStation Remote Controlled Wireless Car

Project showcase by Jasmeet Singh

  • 2,586 views
  • 1 comment
  • 6 respects

Bluetooth Controlled Car

Project tutorial by JANAK13

  • 2,282 views
  • 7 comments
  • 15 respects

Remote Controlled Car

Project showcase by Jeremy Vestal

  • 2,444 views
  • 2 comments
  • 9 respects

Clap Controlled Car

Project showcase by Team Clara & Jone

  • 1,181 views
  • 0 comments
  • 1 respect
Add projectSign up / Login