There are different types of RC Cars which are generally used. In this article we will discuss regarding the remote control of a Differential Drive Robot over Wi-Fi using Raspberry Pi module and also control the speed of motors using Pule Width Modulation (PWM).
1. Components Required:
· Raspberry Pi 3
· Motor Driver IC L298D
· Power Bank
· 2 BO motors
· 2 Wheels for motors and one free wheel
· 2-wheel chassis
· 3.7V Li-ion batteries
· Battery holder ad charger
· Jumpers
2. Understanding the working of a differential drive robot
A Differential Drive robot can be controlled by changing the speed and direction of both of its wheels.
3. Connections
Note that both the enable pins need to be connected to PWM pins of Raspberry Pi
4. Understanding the code
There are two libraries to be installed on the raspberry pi namely Curses and RPi.GPIO.
The code is pretty straight forward. All we need to do is read the input signals from keyboard and send necessary control signals to the motor driver.
Define the variables for the enable pins and motor input pins and define all the pins as output.
We need to perform the above operations to be able to read inputs from the keypad without any overlapping.
Both the enable pins are set as GPIO PWM pins and their duty cycle is reduced to 50%.
Now we read inputs from keypad and give necessary control signals to the bot.
We use the key ‘s’ to stop the bot.
Perform necessary cleanup on the curses and we are done with the code.
Source Code Link : https://github.com/bhargav-s-271100/Medium-Posts/blob/master/RC_Car_using_RaspberryPi.py
5. Output Video
Install the necessary libraries and run the code on Pi console to check the working of the bot.
Code Upload Video: https://youtu.be/6sRNfgA4BTw
Output Video Link: https://youtu.be/PvyWBSFrq3w
Note : The bot will not run straight always because BO motors dont run at the same speed. The solution to this is to use speed encoders.