top of page
Search

Robotics - How to make a RC car

Components -

  1. Car Chassis

  2. Arduino Module/ Arduino Uno/ ESP - 32

  3. Bluetooth Module

  4. L-298 Motor Driver

  5. Jumper wires - Male to Male, Female to Female , Male to Female.

  6. Laptop - Arduino IDE

  7. Mobile App - Arduino Bluetooth car

  8. Wires - Red and Black (to make the connection easier)

  9. Battery and Battery holder

  10. Bread Board



Arduino UNO, Arduino Nano and ESP 32 all do the same function hence any one of them can be used .In general the Arduinos don't have built in blutooth connection hence the bluetooth module becomes necessary. This writer preferred ESP 32 beccause it didn't require this extra bluetooth module ,making connections a bit easier. This blog will be focussing on using ESP 32 WROOM.

Okay now that you have become completely broke because of this writer, let's start the process.



First soft ware part

Click this link and download Arduino IDE.


This is the software we will use to code our robot rv car.

Open the app and create new sketch < Press file and select new sketch >

Go to library option in the left hand side, and search for 'Bluetooth'


select this one and install.

similarily for esp 32 install this one --



Now connect your esp 32 to your laptop using cable


And select board in arduino IDE -- steps are :-


and next the port - depending on the model you use ,for example, for usCOM 5 was reflecting , click on that.

The select board option in the main screen will fix on its own-


Now copy paste the code below


-------------------


#include <BluetoothSerial.h>

 

BluetoothSerial SerialBT;

 

// Motor control pins

const int motor1Pin1 = 23;  // IN1

const int motor1Pin2 = 22;  // IN2

const int motor2Pin1 = 21;  // IN3

const int motor2Pin2 = 19;  // IN4

 

void setup() {

  Serial.begin(115200);

  SerialBT.begin("ESP32_RC_Car"); // Set Bluetooth device name

  Serial.println("The device started, now you can pair it with Bluetooth!");

 

  // Set motor control pins as output

  pinMode(motor1Pin1, OUTPUT);

  pinMode(motor1Pin2, OUTPUT);

  pinMode(motor2Pin1, OUTPUT);

  pinMode(motor2Pin2, OUTPUT);

 

  // Initially stop the motors

  stop();

}

 

void loop() {

  if (SerialBT.available()) {

    char command = SerialBT.read(); // Read command from Bluetooth

    Serial.print("Command received: ");

    Serial.println(command); // Print command to serial monitor

 

    switch (command) {

      case 'F': // Move forward

        moveForward();

        break;

      case 'B': // Move backward

        moveBackward();

        break;

      case 'L': // Turn left

        turnLeft();

        break;

      case 'R': // Turn right

        turnRight();

        break;

      case 'S': // Stop

        stop();

        break;

      default:

        Serial.println("Invalid command");

        break;

    }

  }

}

 

void moveForward() {

  digitalWrite(motor1Pin1, HIGH);

  digitalWrite(motor1Pin2, LOW);

  digitalWrite(motor2Pin1, HIGH);

  digitalWrite(motor2Pin2, LOW);

  Serial.println("Moving Forward");

}

 

void moveBackward() {

  digitalWrite(motor1Pin1, LOW);

  digitalWrite(motor1Pin2, HIGH);

  digitalWrite(motor2Pin1, LOW);

  digitalWrite(motor2Pin2, HIGH);

  Serial.println("Moving Backward");

}

 

void turnLeft() {

  digitalWrite(motor1Pin1, LOW);

  digitalWrite(motor1Pin2, HIGH);

  digitalWrite(motor2Pin1, HIGH);

  digitalWrite(motor2Pin2, LOW);

  Serial.println("Turning Left");

}

 

void turnRight() {

  digitalWrite(motor1Pin1, HIGH);

  digitalWrite(motor1Pin2, LOW);

  digitalWrite(motor2Pin1, LOW);

  digitalWrite(motor2Pin2, HIGH);

  Serial.println("Turning Right");

}

 

void stop() {

  digitalWrite(motor1Pin1, LOW);

  digitalWrite(motor1Pin2, LOW);

  digitalWrite(motor2Pin1, LOW);

  digitalWrite(motor2Pin2, LOW);

  Serial.println("Stopped");

}



------------------------------------------


< yes, this writer also gave up at this bit and used chatgpt 😂> There are several courses to understand each code in detail but if you know basic programming language like python or C , the code becomes self explanatory.


NOTE:-

This part of the code is important during the connections hence pay extra attention to it ( we will come back to this again)


Now press the upload button on the left hand corner.



It will get compiled and will upload into the ESP 32


Now let's move into the hardware part of the robo car.


First connections,

ESP 32 WROOM in general looks like this


Don't worry about all the weird short forms, we won't be using all of them.


and the L-298 motor driver looks like this.



Now use jumper wires and make the following connections ( Use the different types of jumper wires to your own discretion )


Turn your ESP32 around and you will see pins, the jumper wires will be attached to them and made connections . Instead of directly using the pins (they could have chances of bending if pushed too hard) , you could use breadboard too.

If you are a complete beginner then using breadboard is clearly the safest choice.

Let me explain how the bread board works :

I am pretty sure we all know about parallel and series connections learnt in physics.


In a breadboard

Each row in between is a series connection ( for example the one circled in red).

So by connecting one wire to one slot in the bread board, and another in any one of the slots in the same row, they will be connected together. Didn't understand? Take into consideration the below picture :-

Each of the points in the orange line are connected together.

Place the ESP 32 in configuration which leaves enough space to connect the jumper wires.

Example --

Now all the pins in the same row have the same connection.


If you look at the above labelled picture of ESP 32 , you will see GP I 0 some number written. GPI0 means general purpose input - output. These are the main places where the connections will be made.


Take you L298 Motor driver and ESP 32 and make the connections as given...

These port connections ( except the gnd - gnd and voltage connection ofc) are dependent on the code you write. This is I will explain more in detail further on.


While I made the connections, i found the tabular form of information to be the most helpful because at times its hard to find the circuit diagram of the connections of the exact model of esp 32 , you have. But in general most builders use the circuit diagram for easier visualisation so I shall paste one of those which I found for ESP 32 here.

< did I copy - paste it from youtube? yes, yes I did>

The issue with these kind of circuit diagrams is that the connections are in reality code specific. (which I will explain in detail when we deal with the coding part). IN1 , IN2, IN3 and IN4 control the motors to which the wheels are attached.

For example , to explain this in absolute simple terms- the code asks the connection at a particular pin ( i.e GP IO23 ) to do a particular action, the motor receives it via motor driver and starts spinning.


If the circuit diagram is used blindly, the connections made and the corresponding code wouldn't match and the system won't work. You will have to spend hours trouble shooting again ( like we did 😥)


In this step it is best to complete the coding work then check the connections accordingly.


The actual motors (which are connected to the wheels) are always connected to the side two pins with normal wires, usage of jumper wires at that part is generally refrained because you have to twist the wire around the small rectangular metal < the red part in image > attached to the motor. (again completely personal opinion , if you feel jumper wires works better, you can go ahead)

Connections between the battery and the L 298 are also pretty straightforward, you can follow the circuit diagram above , just make sure to use the right screw driver so that the L298 doesn't get jammed with the wires.


Now that the connections are made, between ESP 32 -- L298 -- Battery holder, plug in the batteries. Red LED lights will glow on ESP 32 and L298 driver.


Stick all of this onto a chassis. A chassis is the body of the bot and can range from cardboard to metal. You could even take any cardboard box or delivery box and stick all these items in them, as this is the first time. If you do want a proper RC car chassis, there are several models available online. This writer personally bought a small tool box worth 25 ruppees and used it as chassis because she was broke by the time she bought all the other parts 😂.


Now that all the major parts are over, take your phone and download this app --


This app contains the basic control joystick. Connect your RC car with bluetooth --


click on settings (the wheel/ gear icon) --

Turn on bluetooth and select your RC car

The red light blinking in left corner turns green after connection.

Now is the moment of truth

Hopefully your car connects in the first try and you can control it. If not -

  1. Check all the wire and jumper wires connections again

  2. Check if all the ESP 32 ports are connected properly

  3. Check there are no loose connections in the L298

  4. Check if the battery holder is properly connected with the L298 and the battery

  5. Charge your battery again

  6. Check for faulty parts ( this error is the most irritating and suprisingly very common 😅 )


    Then retry!


    This robot bulding experience comes with its own set of highs and lows. You will learn so much on the journey about both mechatronics and your patience tolerance. If the robot doesn't work after even several times, close your laptop, go for a jog or drink coffee ( coffee is an universal solution according to this writer) and try again. Just don't give up. 🙃

 
 
 

3 Comments


Lalith Karthikeyan
Lalith Karthikeyan
Dec 08, 2024

Would PCBs make for a better design since they take up much less space, leading to weight reduction, which in turn results in more speed? Or am I just telling this because I don't wanna deal with a bread board?

Like

Majestic G
Majestic G
Aug 22, 2024

yo ngl this pretty straightforward and good. 9/10 read

Edited
Like

Lalith Karthikeyan
Lalith Karthikeyan
Aug 19, 2024

This is honestly much much more fun than what I learnt in 11th and 12th.

Like
bottom of page