Introduction
Before embarking on my journey as a Front-End Software Engineer, I had the incredible opportunity to explore the world of Mechatronics Engineering during university. My years in the program were filled with exhilarating moments as we immersed ourselves in the realm of microcontrollers and embarked on the thrilling task of building our own creations from scratch. From crafting robot cars to working with oscilloscopes to measure PWM signals, each experience left me in awe of the possibilities with robotics. NASA had just successfully landed the Curiosity rover on Mars, which was a moment that drew many of my peers to the program, and we felt a connection to that incredible achievement.
Among the projects we tackled, our final endeavour was an ambitious open solution for a multifaceted robot. It was a challenge that involved a sequence of tasks: opening a door, navigating into a room, accurately throwing a water bottle into a distant trash can, moving a newspaper onto a high table, and ultimately, leaving the room and closing the door. No group succeeded.
However, as much as I cherished those moments, I found myself gradually drawn more towards the coding and programming aspects rather than the mechanical and electrical engineering courses. Thus, I made the transition to Software Engineering, which has been my professional path for the past five years.
After almost 7 years since my days in “Tron”, the allure of robotics resurfaced. I decided to open up my old electronics toolkit, and what better way to kickstart this journey than building a robotic car? In this blog post, we will explore the process of constructing a robot car that can be controlled using any smart device.
Parts List
Arduino Uno: The Uno is the microcontroller board that acts as the brain of the our Bluetooth car, controlling its various components and executing programmed instructions.
Motor Shield: The motor shield is an expansion board that allows the Arduino Uno to control multiple motors simultaneously, enabling the car to move in different directions.
Car Kit: The car kit consists of the physical components of the car, such as the chassis, wheels, and body, providing the basic structure for assembling our Bluetooth car.
Wiring: Here we have a basic wiring kit, which you’ll need to connect the different components of the car, ensuring proper communication and power supply.
Bluetooth Module: The Bluetooth module facilitates wireless communication between the Arduino and our smart device. This is basically the receiver for our remote control, and will allow us to send signals to the car.
2 18650 Lithium Ion Batteries: These batteries provide the necessary power to run the Bluetooth car, supplying voltage to the Arduino board, motor shield, and other components.
Battery Holder: The battery holder securely holds the 18650 batteries in place, preventing them from moving during operation and providing a convenient way to connect them to the circuit.
Li-Ion Battery Charger: This is just so you can recharge your 18650 batteries when they run out.
Rocker Switch: We will eventually connect this switch to the battery pack, so you can easily turn the car on and off.

Assembly
The assembly of our car is actually very simple. You might need a hot glue gun or some double sided tape if you want to stick components to the chassis of the car. Here is a very simple YouTube video that takes you through the connections and chassis setup: Setup Video
A few notes:
- We are using a battery holder, which you will need to connect one side with a wire, and the other two sides will be our + and – nodes. The switch will still be connected to our + end with a wire, and the other end of the switch will go into the + side of the Motor Shield. You can glue or tape both the battery holster and switch to the car. Do not insert batteries until all connections are firmly in place.
- I attached a metal hangar to the front to elevate the bluetooth module, which can lead to some overall better connectivity, but you can also attach the bluetooth module directly to the chassis.
- If you notice wheels spinning the wrong way when you are running the car, you can simply reverse the wiring into the Motor Shield. My wiring is below:
Code
Most lines have comments, so try to read through it if you want to know what the code does. Also viewable on GitHub here. Make sure you download the AFMotor library, as well as the Dabble library. If you need instructions on downloading and getting started with the Arduino IDE, you can find that here. Download or copy this code into your Arduino IDE, connect your Arduino to your computer and click Upload.
Play around with the code! Feel free to change:
- MAX_SPEED: This is the max speed your car will run. The values can be between 0-255, but be careful as at 255 you will waste battery extremely quickly and at 0 the car will not run at all, both scenarios can cause some damage. I would recommend keeping the variable between 50-200.
- turnSpeed: This is the cars speed when turning. Same values as above apply as this is still just a control to the motors.
- accelerationIncrement: This variable changes how fast or slow the car accelerates! We have increments coded in (that get implemented with a for loop) so that the car isn’t wasting huge amounts of battery power accelerating from 0 – top speed. But this value (I’d recommend keeping it between 2 – 30, but feel free to play around) changes how quickly we accelerate. Larger values will waste the battery quicker.
//You must download the AFMotor library: https://www.arduinolibraries.info/libraries/adafruit-motor-shield-library
//As well as the Dabble library: https://www.arduinolibraries.info/libraries/dabble
//For a tutorial on adding libraries to your Arduino IDE: https://support.arduino.cc/hc/en-us/articles/5145457742236-Add-libraries-to-Arduino-IDE
#include <AFMotor.h>
#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_MODULE
#include <Dabble.h>
int MAX_SPEED = 150; //Max speed the wheels can move while going forward and backward
int turnSpeed = 120; // Max speed the wheels can move when turning
int speedSet = 0; // Variable used in for loops later on where we will will gradually increase the motor speed
bool atSpeed = false; // Used to figure out if the car is moving already or not, so we don't run our motor acceleration code
int accelerationIncrement = 10; //How much we increment the accelleration of our motors by, higher = higher acceleration, but will drain the battery
char command; //This var is used to store the command we receive from the Bluetooth connection
//Motor Declarations using the AF_DCMotor Library
AF_DCMotor motor1(1, MOTOR12_1KHZ); //BACK LEFT
AF_DCMotor motor2(2, MOTOR12_1KHZ); // BACK RIGHT
AF_DCMotor motor3(3, MOTOR34_1KHZ); // FRONT LEFT
AF_DCMotor motor4(4, MOTOR34_1KHZ); //FRONT RIGHT
void setup() {
// WITH BLUETOOTH
Serial.begin(250000); //Set up Serial and Dabble for Bluetooth connection
Dabble.begin(9600, 9, 10); //Initialize RX & TX pins as 9 and 10 and begin Dabble communication
motorStop(); // Initialize the motors to stop until we recive a command
}
void loop() {
Dabble.processInput();//this function is used to refresh data obtained from Bluetooth connection, calling this function is mandatory in order to get data properly
//Main function below, we want to check if any buttons are pressed, if not we will stop the motors
if(GamePad.isUpPressed() || GamePad.isDownPressed() || GamePad.isLeftPressed() || GamePad.isRightPressed()){
if (GamePad.isUpPressed())
{
motorForward(); // If up is pressed, move motors forward
}
if (GamePad.isDownPressed())
{
motorBackward(); // If back is pressed, move motors backward
}
if (GamePad.isLeftPressed())
{
motorLeft(); // If left is pressed, move motors left
}
if (GamePad.isRightPressed())
{
motorRight(); // If right is pressed, move motors right
}
}
else{
motorStop(); // Stop motors if no buttons are pressed
}
}
void motorStop() {
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
atSpeed = false;
}
void motorForward(){
if (!atSpeed) { //If we're at speed and still pushing the forward button, the motors just continue to run until they are stopped, so skip the function
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet+= accelerationIncrement) { //The for loops are used to gradually increase speed to the motors in order to not drain the batteries
int speed = map(speedSet, 0, MAX_SPEED, 0, 255);
motor1.setSpeed(speed);
motor2.setSpeed(speed);
motor3.setSpeed(speed);
motor4.setSpeed(speed);
delay(10);
}
atSpeed = true;
}
}
void motorBackward(){
if (!atSpeed) {
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
for (speedSet = 0; speedSet < MAX_SPEED; speedSet+=accelerationIncrement) {
int speed = map(speedSet, 0, MAX_SPEED, 0, 255);
motor1.setSpeed(speed);
motor2.setSpeed(speed);
motor3.setSpeed(speed);
motor4.setSpeed(speed);
delay(10);
}
atSpeed = true;
}
}
void motorRight(){
if (!atSpeed) {
motor1.run(FORWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(FORWARD);
for (speedSet = 0; speedSet < turnSpeed; speedSet += accelerationIncrement) {
int speed = map(speedSet, 0, turnSpeed, 0, 255);
motor1.setSpeed(speed);
motor2.setSpeed(speed);
motor3.setSpeed(speed);
motor4.setSpeed(speed);
delay(10);
}
atSpeed = true;
}
}
void motorLeft(){
if (!atSpeed) {
motor1.run(BACKWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(BACKWARD);
for (speedSet = 0; speedSet < turnSpeed; speedSet += accelerationIncrement) {
int speed = map(speedSet, 0, turnSpeed, 0, 255);
motor1.setSpeed(speed);
motor2.setSpeed(speed);
motor3.setSpeed(speed);
motor4.setSpeed(speed);
delay(10);
}
atSpeed = true;
}
}Final Steps
- Download the Dabble App onto any smart device you want to use as your remote control
- On Dabble, click Game Pad to enter the remote control interface we need.
- Turn on the car with the switch. On Dabble, click a button at the top right of the screen, which looks like a plug. This is the Bluetooth connection button, which allows you to choose which device you are connected to.
- The Bluetooth modules we bought are commonly named HC-05, so look for that and connect.
- If everything went to plan, you should now be able to control your car from your device! Happy Driving!