Build your own robot car with the Raspberry Pi!

Build your own robot car with the Raspberry Pi!

In the ESP32-CAM robot car two small 6V gear motors are installed. These yellow motors are very popular and can be found in many models from China. To ensure that all components in the robot are supplied with power, two cables for the power supply must be soldered to each motor. The electronic components like the servo controller or the OLED display are connected with jumper cables which are plugged in. Therefore the manual leads again step by step through the wiring of the robot car and shows with pictures how and where the cables are attached. To keep the description of the wiring of the robot car not too complex and long I have divided it into two articles.

We start with the wiring of the gear motors in the robot car.

Wiring up the gear motors

Two cables for the power supply must be soldered to the gear motors. It is important that the motors are removed from the yellow plastic housing before soldering the cables. Otherwise, the housing of the gear motors may be slightly damaged when using a hot soldering iron. Therefore, please use pliers to loosen the tab at the back of the motors with which the motors are attached to the housing. When the two motors have been removed, solder one red and one black cable to the motor and to the respective copper lugs of the motors.

After the cables are soldered on and the motors are put back into the housing, they can be installed in the chassis again. The following picture shows the two motors with the soldered cables already installed in the robot car chassis.

Note: When assembling the motors with the housing, make sure that the cables point inside the housing. So do not run along the edge of the chassis.

ESP8266 NodeMCU robot car dc motor mount final

ESP8266 NodeMCU robot car dc motor mount final

Now place the cardboard, the so-called component carrier with the electronic components on top of the two motors again and lead the two motor cables upwards through a small hole.

ESP32-CAM robot chassis

ESP32-CAM robot chassis

Wiring the motor driver

The motor driver has six connections which are led out as pin strip. These six pins are used for the logical control of the motor driver from the servo controller. The six pins are named ENA, IN1, IN2, IN3, IN4 and ENB. These six pins are used, for example, to control the direction of rotation of the motors and also the speed at which the robot should drive a car.

Motor speed control

Two DC motors or a stepper motor with four cables can be connected to the L298N motor driver. DC motors are used in the robot car presented here. To allow the two motors to rotate at different speeds, a PWM signal is applied to the ENA and ENB pins, which is generated by the PCA9685 servo controller. So the two motors can be controlled to rotate from standstill to maximum speed.

Controlling the direction of rotation of motors

If the direction of rotation of the motors is to be controlled so that the robot car can also drive backwards, pins IN1 to IN4 come into play. The pins IN1 and IN2 are relevant for motor 1 (e.g. the left motor) and the pins IN3 and IN4 for motor 2 (which would be the right motor).

In the following, the control is explained using the example of motor 1.

  • Depending on whether a HIGH signal is present at IN1 or IN2, the motor rotates forward or backward.
  • If there is a HIGH signal at IN1 and IN2, the motor is short-circuited and a kind of motor brake is achieved. In this case there should be no PWM signal at pin ENA.
  • If IN1 and IN2 are LOW then the motor stops and does not rotate.

Cabling between motor driver and servo controller

The following table shows the wiring of the motor driver. Since the PCA9685 servo controller can be controlled to output a PWM, LOW (0) or HIGH (1) signal, this function can be used to control the direction of rotation and also the speed of the motors. More about this in the section Programming and here in particular about programming with the PCA9685 Servo Controller.

The following table shows which cable is connected to which pin

 

L298N motor driver
PCA9685 servo controller
ENA Channel 0
IN1 Channel 1
IN2 Channel 2
IN3 Channel 3
IN4 Channel 4
ENB Channel 5

Six female-to-female jumper cables are used to establish the connection. Now the setup in the robot car looks as shown below.

ESP32-CAM PCA9685 wires

ESP32-CAM PCA9685 wires

Connect motors to the motor driver

The motors must be connected to the motor driver. For this purpose, the motor on the left side is connected as motor 1. The motor of the right side of the robot car as motor 2. It is important that the cables of the colors are connected reversed. So the colors of motor 1 and motor 2 are swapped in the sense of the colors and how the motor is installed in the robot car. The background is that the motors should turn in the same direction. If this is not the case and the robot car is turning in a circle when it is supposed to drive forward then the cables of the motor that turns in the wrong direction have to be swapped here.

ESP32-CAM L298N H-Bridge wires

ESP32-CAM L298N H-Bridge wires

Now the wiring of the electronic components is finished and the power supply of the robot car still has to be established.

Connecting the power supply

The only thing missing is the USB cable which is cut off to supply the motor driver with +5V / GND from e.g. a power bank. The 5V from a power bank are enough for the small yellow motors to turn. An old USB cable can be bought at the local recycling center in the container for electronic waste. Here you can cut the USB cable from an old keyboard.

If you cut the cable, you can see the four wires of the USB cable. The red cable is for the +5V and the black one is the GND cable. These two cables, red and black, are the cables you need. The white and green wires are the wires for the data and they are not needed. Therefore you can cut them as close as possible.

The following picture shows the yellow cutted USB cable as I connected it to the motor driver. Also connected to the motor driver are two more cables which provide the 5V power supply for the ESP32-CAM.

 

ESP32-CAM power supply USB wire

ESP32-CAM power supply USB wire

If no power bank is used, a step-down converter must be installed. This generates from the approx. 7.2V voltage of the six battery pack the appropriate 5V for our robot car.

Loading ...

Summary

Now almost all cables in the robot car are connected. The wiring of the I2C bus between ESP32-CAM and the I2C hub is still missing. This cabling is described in an extra article. The software for the control of the robot car is still missing and has to be installed on the ESP32-CAM. For this to work, the ESP32-CAM must be connected to the PC with a USB-Serial adapter. How exactly all this works you will find out in the next report.

 


Article Overview ESP32-CAM Robot Auto:

ESP32-CAM building your own robot car with live video streaming – project start
ESP32-CAM building your own robot car with live video streaming – Set up development environment
ESP32-CAM building your own robot car with live video streaming – USB-serial adapter wiring
ESP32-CAM building your own robot car with live video streaming – Installing the live video streaming software
ESP32-CAM building your own robot car with live video streaming – Design of the chassis
ESP32-CAM building your own robot car with live video streaming – Cabling in general
ESP32-CAM building your own robot car with live video streaming – Wiring the I²C hub
ESP32-CAM building your own robot car with live video streaming – robo car example programs
ESP32-CAM building your own robot car with live video streaming – programming the WIFI remote control
ESP32-CAM building your own robot car with live video streaming – connect external WIFI antenna

(Visited 114 times, 6 visits today)