Introduction: RC Car Arduino Controlled

Picture of RC Car Arduino Controlled

This year i participated in a workshop and needed to submit a project. Because i was short on time, the project was a rc car controlled by an arduino. The car uses an ultrasonic sensor to calculate the distance to the objects in front. If was detected an object, the car stop and changes the direction.

Step 1: What You Need

Step 2: Prepare the RC Car

Picture of Prepare the RC Car

First i need to remove the rc car controller. This controller was connected to the motors, the batteries and the wireless receiver.

Step 3: Connect the Motors

Picture of Connect the Motors

The L298 has twelve connectors that we need to use. On one side are the connectors (blue connectors) to the motors an the power. Two control one motor, other two control the other motor and the final two power the module.

On the other side (yellow connectors) two enable and disable the motors, two control the rotation of the motor A and the other two control the rotation of the motor B,

Step 4: Connect the Arduino

Picture of Connect the Arduino

The L298 is connected to the arduino following way:

Pin enableA (L298) -> 12 (Arduino)

Pin enableB (L298) -> 9 (Arduino)

Pin A1 (L298) -> 11 (Arduino)

Pin A2 (L298) -> 10 (Arduino)

Pin B1 (L298) -> 8 (Arduino)

Pin B2 (L298) -> 7 (Arduino)

Step 5: Connect the HC-SR04

Picture of Connect the HC-SR04

The HC-SR04 uses four pins to connect to the arduino. Two are for the power, one is Trigger, to emit a signal to calculate the distance, and the other is Echo, to receive the signal. The connections to the arduino are the following:

Pin VCC (HC-SR04) -> 5V (Arduino)

Pin Ground (HC-SR04) -> Ground (Arduino)

Pin Echo (HC-SR04) -> 3 (Arduino)

Pin Trigger (HC-SR04) -> 2 (Arduino)

Step 6: Arduino Sketch

This is the Arduino sketch used to control the car.

 Tiago Santos, 2014
 Code to control a RC Car
 Thanks to Bruno Santos ( for some code
 Free to share
//Ultrasound Sensor
#define trigPin 2 // Trigger  2
#define echoPin 3 //echo      3

//Motor A
int enableA = 12;  //12
int pinA1 = 11;    //11
int pinA2 = 10;    //10

///Motor B
int enableB = 9;
int pinB1 = 8;    //8
int pinB2 = 7;  //7

long duration;
int distance;
<p>int r;</p>
void setup()
 /* Initialize Ultrasound Pin Modes */
 pinMode(trigPin, OUTPUT); // Trigger PIN
 pinMode(echoPin, INPUT); // Echo PIN
 /* Initialize Motor A Pin Modes */
  pinMode (enableA, OUTPUT);
  pinMode (pinA1, OUTPUT);
  pinMode (pinA2, OUTPUT);  
 /* Initialize Motor B Pin Modes */  
  pinMode (enableB, OUTPUT);
  pinMode (pinB1, OUTPUT);
  pinMode (pinB2, OUTPUT);  
void loop()
  //check the distance
  distance = checkDistance(); 
  //if distance is less that 30 cm
  if(distance < 30)
    //stop car, turn wheels right and go back for 500 ms. Then stop
    r = random(1);
    if( r == 1)
    if( r == 1)
//function to calcutate the distance to an obstacle
long microsecondsToCentimeters (long microseconds) {
 // The speed of sound is 340 m/s or 29 microseconds per centimeter
 // The ping travels forth and back, so, the distance is half the distance traveled
 return microseconds / 29 / 2;
//function to check the distance of an obstacle
long checkDistance()
 /* The following trigPin/echoPin cycle is used to determine the distance of the nearest
 object by bouncing soundwaves off it */
 //Trigger a HIGH pulse for 2 or more microseconds
 //Give a short LOW pulse before sending a HIGH one
 digitalWrite (trigPin, LOW);
 digitalWrite(trigPin, HIGH);
 digitalWrite (trigPin, LOW);
 //Now, lets read the read the bounced wave
 duration = pulseIn(echoPin, HIGH);
 //calculate the distance
 distance = microsecondsToCentimeters(duration);
 return distance;
//function to go forward
void goForward()
  //Enable Motor A
  digitalWrite (enableA, HIGH);
  digitalWrite (pinA1, LOW);
  digitalWrite (pinA2, HIGH);
//function to stop Motor A movement
void stopMotorA()
  digitalWrite (enableA, LOW);
//function to go back
void goBack()
  //Enable Motor A
  digitalWrite (enableA, HIGH);  
  digitalWrite (pinA1,HIGH);
  digitalWrite (pinA2,LOW);  
//function to stop Motor B movement
void stopMotorB()
  digitalWrite (enableB, LOW);
//function to turn the RC car right
void turnRight()
  //Enable Motor B  
  digitalWrite (enableB, HIGH);
  digitalWrite (pinB1, LOW);
  digitalWrite (pinB2, HIGH);  
//function to turn the RC car left
void turnLeft()
  //Enable Motor B  
  digitalWrite (enableB, HIGH);  
  digitalWrite (pinB1,HIGH);
  digitalWrite (pinB2,LOW);  

Step 7: Power

Because the low amperage of the 9v battery, was needed a second battery holder for the motors.The L298 is powered by 5v, but because the motors need a constant and stable power source, i used four 1.5v battery, is a total of 6v.

Step 8: Final Result

Picture of Final Result


WaliedA (author)2016-11-25

Hi Nice project

We have tried this with L298N Motor Driver Shield but it is not powering the DC motor, what could have gone wrong, can you give us the connection diagram.


jorovengua1 (author)WaliedA2017-08-18

Have a look at the connections of the jumpers. Here´s a page that will help you, but it is in Spanish:

TiagoSantos (author)WaliedA2016-11-25

Hi. The L298N needs to have is own power source to power the motors. I had a 4x1.5v battery pack connected to 5v and ground pins on the L298N (picture on step 5). I don't have a diagram.

WannaDuino (author)2016-08-10

movie pleace and results and some infopleace

this is not a full IBLE

but verry cool so i want to make it.

TiagoSantos (author)WannaDuino2016-08-15


There isn't a movie because some parts were needed for other projects and i need to disassemble the car before have time to make the movie.

What other info do you need?

About This Instructable




More by TiagoSantos:Halloween CheerlightsLightbox With Controller and StorageAquarium Controller Using NodeMCU and MQTT
Add instructable to: