Lesson 17: Wireless Control: Bluetooth and Wi-Fi BasicsNew-age
A robot on a wire is a robot on a leash. Wireless control cuts the cable: a phone or a computer sends commands over Bluetooth or Wi-Fi, and the robot moves freely. This lesson explains the two commonest wireless options, shows how to receive commands from a phone over Bluetooth, and covers the practical questions — range, pairing, power and security — that decide which one to use.
Wireless also changes how you debug. When the cable is gone, the Serial Monitor is gone too, so you will learn to build a small status display and a heartbeat signal into the robot, so you can tell at a glance whether it is connected, receiving, and working.
- Bluetooth — a short-range wireless protocol, common for phone-to-robot control.
- Wi-Fi — a longer-range wireless protocol that can connect a robot to a network or the internet.
- Pairing — the one-time process of trusting two Bluetooth devices to each other.
- Range — how far apart two wireless devices can be and still communicate.
- Latency — the delay between sending a command and the robot acting on it.
- Heartbeat — a regular signal that shows a connection is alive, such as a blink every second.
- SSID — the name of a Wi-Fi network.
- Encryption — scrambling data so only the intended recipient can read it.
Bluetooth: the phone as a remote control
Bluetooth is the simplest wireless option for a robot. A cheap HC-05 module connects to the microcontroller’s serial pins and appears to the robot as a second serial port: whatever the phone sends arrives as serial data, and whatever the robot prints is sent back. From the code’s point of view, Bluetooth is just serial without a cable — the command protocol from Lesson 10 works unchanged, with “F” for forward and “S” for stop.
Pair the module once from the phone’s Bluetooth settings (the default PIN is usually 1234 or 0000), then use a terminal app to send commands. The range is about 10 metres, and walls reduce it. The module draws little power, which makes it good for battery robots, and it needs no network — the phone talks directly to the robot.
Wi-Fi: more range, more power
Wi-Fi gives a longer range — across a building, or anywhere with network coverage — and it can connect the robot to the internet, so it can send data to a server or be controlled from another country. Boards such as the ESP32 have Wi-Fi built in, and they can run a tiny web server: the robot shows a web page with buttons, and tapping a button sends a command. That is more work to set up than Bluetooth, but it needs no special app — any phone with a browser can control the robot.
Wi-Fi costs power: a Wi-Fi radio draws far more current than a Bluetooth module, so a battery robot will run for a shorter time. It also needs a network: the SSID and password must be in the code, and the robot must be in range of the router. For a classroom robot, Bluetooth is usually enough; for a robot that must be reached from anywhere, Wi-Fi is the answer.
Commands over the air
The command protocol from Lesson 10 works over wireless, but the wireless link adds two problems: delay and loss. Latency — the time between sending a command and the robot acting — is a fraction of a second on Bluetooth and can be longer on Wi-Fi. And a command can be lost, especially at the edge of range. Design for both: send commands repeatedly while a button is held (so a lost “forward” is followed by another one), and make “stop” the safest command — if no command arrives for half a second, the robot should stop by itself.
Security and the heartbeat
A wireless robot can be controlled by anyone in range, which is a security problem as well as a practical one. Change the Bluetooth module’s default PIN before you use it in public, and do not leave a Wi-Fi robot’s control page open without a password. A robot that anyone can drive is a robot that will be driven by someone you did not intend.
Worked example — a Bluetooth command loop
The HC-05 module is wired to the microcontroller’s hardware serial or to a software serial port. The loop reads a command character and drives the robot, with a timeout that stops it if no command arrives for 500 ms.
unsigned long lastCmd = 0;
void loop() {
if (Serial.available()) {
char c = Serial.read();
lastCmd = millis();
if (c == 'F') drive(150, 150);
else if (c == 'S') drive(0, 0);
else if (c == 'L') drive(-100, 100);
else if (c == 'R') drive(100, -100);
}
if (millis() - lastCmd > 500) drive(0, 0); // lost link: stop
}
Common mistakes
- Forgetting the stop-on-timeout rule, so the robot keeps driving when the link drops.
- Leaving the Bluetooth module’s default PIN unchanged, so anyone nearby can connect.
- Expecting Wi-Fi range from a Bluetooth module. Bluetooth reaches about 10 metres.
- Debugging a wireless robot with no status display. Add a heartbeat LED before you cut the cable.
Discussion questions
- A robot stops 500 ms after the last command. Is that too fast, too slow, or right? What would change your answer?
- Bluetooth needs no network; Wi-Fi needs a router. When is each one the right choice for a school robot?
- Anyone in range can drive your robot. Whose responsibility is that — yours, the module maker’s, or the school’s?
Practice questions
- Why does Bluetooth code look like serial code? Answer: Because a Bluetooth module presents itself as a serial port: data arrives byte by byte, just as over USB. The same reading code works for both. Explanation: Bluetooth is serial without a cable.
- What is the stop-on-timeout rule, and why does it matter? Answer: If no command arrives for 500 ms, the robot stops. It prevents the robot driving on after the link drops. Explanation: Silence means stop.
- Why does Wi-Fi use more power than Bluetooth? Answer: Its radio is more powerful and stays connected to a network. A battery robot will run for a shorter time on Wi-Fi. Explanation: Range costs power.
- What is a heartbeat, and what does it tell you? Answer: A regular blink showing the connection is alive — once a second when connected, twice when receiving. If it stops, the link is gone. Explanation: A blink is a status report.
- Why change a Bluetooth module’s default PIN? Answer: Because anyone who knows the default can connect to your robot and drive it. The default is public knowledge. Explanation: Defaults are not secrets.
✅ Check your understanding
Quick recall check, generated from this lesson’s key terms. It is practice only and is not graded.