As an Amazon Associate we earn from qualifying purchases.
An Android controlled land rover is a small motorised vehicle that you drive from your phone over Bluetooth. The phone sends a single character for each button press, and an Arduino board reads that character and switches the motors, lights and horn. This page walks through the Arduino sketch we use, explains what every command does, and points out a few things to fix so it works reliably on your own build.
If you want to see a complete finished build, have a look at our Android controlled land rover version 1.0 project.
How the rover works
The idea is simple, and it has three parts:
- Android phone: runs a Bluetooth controller app that sends one character per button, such as F for forward.
- Bluetooth module: receives those characters and passes them to the Arduino as serial data at 9600 baud. Common modules for this are the HC-05 and HC-06.
- Arduino and motor driver: the Arduino reads each character and sets its output pins high or low. A motor driver board turns those signals into power for the wheel motors.
What you need
- An Arduino board (an Uno or similar)
- A Bluetooth serial module connected to the Arduino TX and RX pins
- A dual H-bridge motor driver, such as an L293D or L298N board
- Two DC gear motors and a chassis with wheels
- Two LEDs with resistors for the front and back lights, and a small buzzer for the horn
- A battery pack for the motors, and a stable supply for the Arduino
- An Android phone with a Bluetooth controller app that lets you set the characters it sends
Pin connections used in the sketch
The code below uses these pins:
- Pins 13 and 12: inputs for one motor on the driver board
- Pins 11 and 10: inputs for the other motor
- Pin 3: front light
- Pin 4: back light
- Pin 2: horn
Which motor is “left” and which is “right” depends on how you wired them, so test the turns on your own rover and swap the motor wires if the directions come out reversed.
The Arduino code
This is the original sketch for the rover:
void setup()
{
pinMode(13,OUTPUT);
Serial.begin(9600);
Serial.print("WELCOME TO EMERGING TECHNOLOGIES");
digitalWrite(13,LOW); digitalWrite(12,LOW); digitalWrite(11,LOW); digitalWrite(10,LOW);
delay(1000);
}
void loop()
{
unsigned char a=Serial.read();
if(a=='F') {digitalWrite(13,HIGH); digitalWrite(12,LOW); digitalWrite(11,HIGH); digitalWrite(10,LOW); delay(10);}
else if(a=='B') {digitalWrite(13,LOW); digitalWrite(12,HIGH); digitalWrite(11,LOW); digitalWrite(10,HIGH); delay(10);}
else if(a=='L') {digitalWrite(13,HIGH); digitalWrite(12,LOW); digitalWrite(11,LOW); digitalWrite(10,LOW); delay(10);}
else if(a=='R') {digitalWrite(13,LOW); digitalWrite(12,LOW); digitalWrite(11,HIGH); digitalWrite(10,LOW); delay(10);}
// if(a=='S') {digitalWrite(13,LOW); digitalWrite(12,LOW); digitalWrite(11,LOW); digitalWrite(10,LOW); delay(10);}
else if(a=='W') {digitalWrite(3,HIGH); delay(10);} //FRONT LIGHT ON
else if(a=='w') {digitalWrite(3,LOW); delay(10);} //FRONT LIGHT OFF
else if(a=='U') {digitalWrite(4,HIGH); delay(10);} //BACK LIGHT ON
else if(a=='u') {digitalWrite(4,LOW); delay(10);} //BACK LIGHT OFF
else if(a=='V') {digitalWrite(2,HIGH); delay(10);} //HORN ON
else if(a=='v') {digitalWrite(2,LOW); delay(10);} //HORN OFF
else
{
digitalWrite(13,LOW); digitalWrite(12,LOW); digitalWrite(11,LOW); digitalWrite(10,LOW);
}
}What each command does
The sketch reads one character at a time and acts on it:
- F: drives both motors forward (pins 13 and 11 high, pins 12 and 10 low).
- B: drives both motors in reverse (pins 12 and 10 high, pins 13 and 11 low).
- L: powers only the motor on pins 13 and 12, so the rover pivots around the other wheels.
- R: powers only the motor on pins 11 and 10, which pivots it the other way.
- W / w: front light on / off.
- U / u: back light on / off.
- V / v: horn on / off.
- Anything else: all four motor pins go low, so the rover stops.
The stop command S is commented out in the original. You do not need it, because the final else branch already stops the motors for any other character, including when no data arrives.
One fix: set every pin as an output
The original setup() only calls pinMode for pin 13. On an Arduino, pins default to input, and calling digitalWrite on an input pin only switches its internal pull-up resistor. It does not drive the pin properly. For the rover to work as intended, declare all the pins you use as outputs:
void setup()
{
pinMode(13,OUTPUT); pinMode(12,OUTPUT);
pinMode(11,OUTPUT); pinMode(10,OUTPUT);
pinMode(4,OUTPUT); pinMode(3,OUTPUT);
pinMode(2,OUTPUT);
Serial.begin(9600);
}The rest of the sketch stays the same. You can keep the welcome message too, but remember it is sent to the phone through the Bluetooth module, so it may show up in the app’s terminal.
Set up the Android side
Pair the Bluetooth module with your phone first, using the module’s pairing code from its documentation. Then open a controller app that lets you assign the character sent by each button. Match the buttons to the table above: F, B, L and R for movement, W/w, U/u and V/v for the lights and horn. Many Bluetooth RC car apps use a similar set of characters, but always check the app’s settings before assuming.
Because the sketch stops the motors whenever it reads anything that is not a known command, the rover only keeps moving while characters keep arriving. If your app sends a character only once per tap, the rover will move for a split second and stop. Pick an app mode that repeats the character while the button is held, or change the code to remember the last command until a stop character arrives.
Tips for a reliable build
- Unplug the module when uploading. The Bluetooth module shares the Arduino’s TX and RX pins with the USB connection, so disconnect it while you upload a sketch.
- Share the ground. The Arduino, motor driver and battery must be connected to a common ground, or the control signals will not work.
- Power the motors separately. Motors can draw far more current than an Arduino pin or its regulator can supply, so use the motor driver with its own battery supply.
- Use resistors for the LEDs. Each LED on pins 3 and 4 needs a series resistor.
- Test with the wheels off the ground. Check each command before putting the rover on the floor.
Troubleshooting
- Nothing moves: check the motor battery, the common ground and that all motor pins are set as outputs.
- The rover goes backward when you press forward: swap the two wires of that motor on the driver board.
- The phone connects but there is no response: confirm the baud rate on the module matches 9600, and that the module’s TX goes to the Arduino RX and its RX to the Arduino TX.
- It stutters: a weak or low battery is a common cause, so try fresh cells.
Where to go next
Once the basic rover works, you can add obstacle sensors and try automatic navigation so it can steer itself. The same Bluetooth and Arduino approach is also used for home automation using Android, where the characters switch relays instead of motors.
FAQ
Which Bluetooth module works with this code?
Any Bluetooth serial module that talks at 9600 baud, such as an HC-05 or HC-06, should work. The sketch just reads characters from the Arduino’s hardware serial port.
Can I use a different motor driver?
Yes. The sketch only sets four pins high or low, so any H-bridge driver with two inputs per motor works. Check your driver’s documentation for its input and power requirements.
Why does the rover stop right after I press a button?
The code stops the motors whenever no valid character is received. Use an app mode that keeps sending the command while the button is held, or modify the sketch to keep the last command.
Do I need to change the code to use different pins?
Only the pin numbers in the digitalWrite and pinMode calls. Avoid pins 0 and 1, which are used by the Bluetooth module for serial communication.