Lesson 20

Wireless Communication and Remote Control

🎯 Learning Objectives

📡 Introduction to Wireless Communication

What is Wireless Communication?

Wireless communication allows devices to send information to each other without physical wires. Instead of cables, they use invisible signals that travel through the air at the speed of light!

Think about how your phone connects to WiFi, or how a TV remote controls your television. These are all examples of wireless communication that we use every day.

Types of Wireless Communication

  • WiFi: High-speed internet connection, long range (100+ feet)
  • Bluetooth: Short-range connection for nearby devices (30 feet)
  • Radio Waves: Simple signals that can travel very far
  • Infrared: Light signals that need direct line of sight (like TV remotes)

How Wireless Signals Work

Wireless signals are like invisible waves that carry information. Just like throwing a ball to a friend, one device "throws" a signal, and another device "catches" it. The information is encoded in the pattern of these waves.

The strength of the signal depends on distance - the farther away you are, the weaker the signal becomes. Walls, metal objects, and other electronics can also interfere with or block signals.

🔧 Arduino Wireless Modules

ESP32 WiFi Module

The ESP32 is a powerful module that can connect to WiFi networks and communicate over the internet. It's like giving your robot a smartphone brain that can connect to WiFi!

#include <WiFi.h>

const char* ssid = "YourWiFiName";
const char* password = "YourPassword";

void setup() {
  Serial.begin(115200);
  
  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  
  Serial.println("Connected to WiFi!");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  // Your robot code here
}

Bluetooth Module (HC-05)

Bluetooth is perfect for connecting your robot to a smartphone or tablet. It's easy to use and doesn't require internet - just pair the devices like connecting wireless headphones!

#include <SoftwareSerial.h>

SoftwareSerial bluetooth(2, 3); // RX, TX pins

void setup() {
  Serial.begin(9600);
  bluetooth.begin(9600);
  Serial.println("Bluetooth Ready!");
}

void loop() {
  // Check for commands from phone
  if (bluetooth.available()) {
    String command = bluetooth.readString();
    command.trim(); // Remove extra spaces
    
    if (command == "FORWARD") {
      moveForward();
    } else if (command == "BACKWARD") {
      moveBackward();
    } else if (command == "LEFT") {
      turnLeft();
    } else if (command == "RIGHT") {
      turnRight();
    } else if (command == "STOP") {
      stopMotors();
    }
  }
}

Radio Frequency (RF) Modules

RF modules are simple and reliable for basic remote control. They work like walkie-talkies - one module transmits, and another receives. Great for long-distance control!

  • Range: Can work from 100+ feet away
  • Simple: Just send basic commands (forward, back, left, right)
  • Reliable: Less interference than WiFi or Bluetooth
  • Battery Friendly: Uses very little power

🎮 Building a Remote Control System

Step 1: Choose Your Control Method

First, decide how you want to control your robot. Each method has advantages:

  • Smartphone App: Touch buttons, tilt controls, voice commands
  • Computer/Laptop: Keyboard controls, mouse steering
  • Game Controller: Joysticks and buttons for precise control
  • Custom Remote: Build your own with buttons and joysticks

Step 2: Design Your Commands

Plan what commands your robot should understand. Keep it simple at first:

// Basic movement commands
void processCommand(String cmd) {
  if (cmd == "F") {
    moveForward();
  } else if (cmd == "B") {
    moveBackward();
  } else if (cmd == "L") {
    turnLeft();
  } else if (cmd == "R") {
    turnRight();
  } else if (cmd == "S") {
    stopMotors();
  } else if (cmd == "BEEP") {
    playBeep();
  } else if (cmd == "LIGHTS") {
    toggleLights();
  }
  
  // Send confirmation back
  bluetooth.println("Command received: " + cmd);
}

Step 3: Add Safety Features

Always include safety features in your remote control system:

  • Connection Check: Stop the robot if connection is lost
  • Emergency Stop: Always have a way to stop immediately
  • Speed Limits: Don't let the robot go too fast
  • Boundary Detection: Stop at edges or obstacles

📱 Smartphone App Control

Using Existing Apps

The easiest way to start is using apps that are already available:

  • Arduino Bluetooth Controller: Simple button interface
  • Bluetooth Terminal: Send text commands directly
  • MIT App Inventor: Create your own custom app

Creating a Simple Web Interface

With WiFi, you can create a web page that controls your robot from any device with a browser:

// Simple web server for robot control
#include <WiFi.h>
#include <WebServer.h>

WebServer server(80);

void setup() {
  // Connect to WiFi (code from earlier)
  
  // Define web pages
  server.on("/", handleRoot);
  server.on("/forward", handleForward);
  server.on("/backward", handleBackward);
  server.on("/left", handleLeft);
  server.on("/right", handleRight);
  server.on("/stop", handleStop);
  
  server.begin();
  Serial.println("Web server started!");
}

void handleRoot() {
  String html = "<html><body>";
  html += "<h1>Robot Control</h1>";
  html += "<button onclick='fetch("/forward")'>Forward</button><br>";
  html += "<button onclick='fetch("/backward")'>Backward</button><br>";
  html += "<button onclick='fetch("/left")'>Left</button>";
  html += "<button onclick='fetch("/right")'>Right</button><br>";
  html += "<button onclick='fetch("/stop")'>STOP</button>";
  html += "</body></html>";
  
  server.send(200, "text/html", html);
}

Advanced Control Features

Once you have basic control working, you can add exciting features:

  • Tilt Control: Tilt your phone to steer the robot
  • Voice Commands: Say "go forward" to control the robot
  • Camera View: See what your robot sees on your phone
  • Sensor Data: Display distance, temperature, and other readings
  • Path Recording: Record a path and replay it automatically

🔬 Hands-On Activity: Build a Bluetooth Remote Control

Materials Needed

  • miniAuto robot with Arduino
  • HC-05 Bluetooth module
  • Jumper wires
  • Smartphone with Bluetooth
  • Arduino Bluetooth Controller app (free download)

Step-by-Step Instructions

  1. Wire the Bluetooth Module:
    • VCC → 5V on Arduino
    • GND → GND on Arduino
    • RX → Pin 2 on Arduino
    • TX → Pin 3 on Arduino
  2. Upload the Control Code: Use the Bluetooth code example from Section 2
  3. Pair Your Phone: Find "HC-05" in Bluetooth settings and connect
  4. Download Controller App: Install "Arduino Bluetooth Controller" from app store
  5. Configure the App: Set up buttons to send F, B, L, R, S commands
  6. Test the Connection: Try each button and watch your robot respond
  7. Add Features: Program additional commands like lights or sounds

Testing and Troubleshooting

  • No Connection: Check wiring and make sure Bluetooth is paired
  • Robot Not Moving: Verify motor connections and battery charge
  • Delayed Response: Normal with Bluetooth - expect small delays
  • Connection Drops: Stay within 30 feet and avoid interference

📋 Assessment & Homework

Practice Exercises

  1. Successfully connect and control your robot via Bluetooth
  2. Add a "horn" command that makes your robot beep
  3. Program an emergency stop that works from any state
  4. Test the maximum range of your Bluetooth connection
  5. Create a simple obstacle course and navigate it remotely

Challenge Projects

  • Voice Control: Use phone's voice recognition to control robot
  • Gesture Control: Control robot by tilting your phone
  • Two-Way Communication: Have robot send sensor data back to phone
  • Multiple Robots: Control several robots from one phone

Reflection Questions

  1. What are the advantages and disadvantages of wireless vs. wired control?
  2. Why might Bluetooth be better than WiFi for robot control in some situations?
  3. How could you improve the safety of your remote control system?
  4. What real-world applications use similar wireless control systems?
← Lesson 19: Machine Learning 📚 Semester Overview Take Quiz →