Are you ready to build a WiFi-controlled robot that’s faster and more efficient than traditional Bluetooth-controlled robots? With the ESP32, you can create a high-speed, responsive robot that you can control via a smartphone app. This guide will walk you through every step, from understanding the basics of WiFi and ESP32 to building and controlling your robot. Let’s dive in!

Table of Contents
What is WiFi?
WiFi is a wireless technology that allows devices to connect to the internet or communicate with each other over a local network. Unlike Bluetooth, WiFi offers a longer range, faster data transfer, and the ability to handle multiple connections simultaneously. This makes it ideal for projects like a WiFi-controlled robot, where speed and responsiveness are crucial.
What is ESP32?
The ESP32 is a powerful, low-cost microcontroller with built-in WiFi and Bluetooth capabilities. It’s widely used in IoT projects due to its versatility, dual-core processor, and extensive GPIO pins. The ESP32 Dev Board is a development board that makes it easy to program and use the ESP32 in your projects.
Why Choose ESP32 for a WiFi-Controlled Robot?
- Faster Communication: Compared to HC-05 Bluetooth modules, the ESP32 offers faster data transfer and lower latency.
- Longer Range: WiFi provides a longer range than Bluetooth, allowing you to control your robot from a greater distance.
- Ease of Use: The ESP32 is beginner-friendly and integrates seamlessly with the Arduino IDE.
- Speed Control: With PWM (Pulse Width Modulation), you can precisely control the speed of your robot’s motors.
Step-by-Step Guide to Building a WiFi-Controlled Robot
Materials Needed
- ESP32 Dev Board
- L298N Motor Driver Module
- DC Motors (2)
- Wheels (2)
- Chassis
- Battery Pack (7.4V or 9V)
- Jumper Wires
- Smartphone with the ESP32 WiFi Controller App
Step 1: Add ESP32 to Arduino IDE
- Open the Arduino IDE and go to File > Preferences.
- In the Additional Boards Manager URLs field, paste this link:
https://dl.espressif.com/dl/package_esp32_index.json
- Go to Tools > Board > Boards Manager, search for ESP32, and install the package.
- Select your ESP32 board under Tools > Board > ESP32 Arduino.
Step 2: Circuit Connections
Here’s how to connect the ESP32 to the L298N motor driver and motors:
ESP32 Pin | L298N Pin | Function |
---|---|---|
GPIO 26 | ENA | Left Motor Speed |
GPIO 27 | IN1 | Left Motor Direction |
GPIO 25 | IN2 | Left Motor Direction |
GPIO 14 | ENB | Right Motor Speed |
GPIO 12 | IN3 | Right Motor Direction |
GPIO 13 | IN4 | Right Motor Direction |
GND | GND | Ground |
5V | 5V | Power |
- Connect the motors to the L298N outputs.
- Power the L298N and ESP32 using the battery pack.
Step 3: Upload the Code
Copy and paste the following code into the Arduino IDE:
#include <WiFi.h>
#include <WebServer.h>
// WiFi AP credentials
const char* ssid = "ESP32-AP";
const char* password = "12345678";
// Create web server on port 80
WebServer server(80);
// L298N motor driver pins
const int ENA = 26; // Left motor PWM (speed)
const int IN1 = 27; // Left motor direction 1
const int IN2 = 25; // Left motor direction 2
const int ENB = 14; // Right motor PWM (speed)
const int IN3 = 12; // Right motor direction 1
const int IN4 = 13; // Right motor direction 2
// Variables to store command and speed
String currentCommand = "";
int currentSpeed = 0;
const int defaultSpeed = 100; // Default speed when no value is provided
void setup() {
// Start Serial
Serial.begin(115200);
delay(1000);
// Set up motor pins
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
// Set up Access Point
WiFi.softAP(ssid, password);
Serial.println();
Serial.print("AP IP address: ");
Serial.println(WiFi.softAPIP());
// Define server routes
server.onNotFound(handleCommand);
// Start server
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}
void handleCommand() {
String request = server.uri();
if (request.startsWith("/")) {
request = request.substring(1);
}
// Parse command and speed (if provided)
if (request.indexOf(":") != -1) {
int colonIndex = request.indexOf(":");
currentCommand = request.substring(0, colonIndex);
String speedStr = request.substring(colonIndex + 1);
currentSpeed = speedStr.toInt();
} else {
currentCommand = request;
currentSpeed = (currentCommand == "S") ? 0 : defaultSpeed; // Default speed unless "S"
}
// Process command and control robot
controlRobot();
displayCommand();
// Send response back to client
server.send(200, "text/plain", "Command received: " + request);
}
void controlRobot() {
// Stop motors by default
analogWrite(ENA, 0);
analogWrite(ENB, 0);
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
if (currentCommand == "F") { // Forward
digitalWrite(IN1, HIGH); // Left motor forward
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH); // Right motor forward
digitalWrite(IN4, LOW);
analogWrite(ENA, currentSpeed);
analogWrite(ENB, currentSpeed);
}
else if (currentCommand == "B") { // Backward
digitalWrite(IN1, LOW); // Left motor backward
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW); // Right motor backward
digitalWrite(IN4, HIGH);
analogWrite(ENA, currentSpeed);
analogWrite(ENB, currentSpeed);
}
else if (currentCommand == "L") { // Left
digitalWrite(IN1, LOW); // Left motor backward
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH); // Right motor forward
digitalWrite(IN4, LOW);
analogWrite(ENA, currentSpeed);
analogWrite(ENB, currentSpeed);
}
else if (currentCommand == "R") { // Right
digitalWrite(IN1, HIGH); // Left motor forward
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW); // Right motor backward
digitalWrite(IN4, HIGH);
analogWrite(ENA, currentSpeed);
analogWrite(ENB, currentSpeed);
}
else if (currentCommand == "S") { // Stop
analogWrite(ENA, 0);
analogWrite(ENB, 0);
}
}
void displayCommand() {
Serial.println("-------------------");
Serial.print("Received Command: ");
Serial.println(currentCommand);
if (currentSpeed > 0) {
Serial.print("Speed Value: ");
Serial.println(currentSpeed);
}
if (currentCommand == "F") {
Serial.println("Action: Moving Forward");
} else if (currentCommand == "B") {
Serial.println("Action: Moving Backward");
} else if (currentCommand == "L") {
Serial.println("Action: Turning Left");
} else if (currentCommand == "R") {
Serial.println("Action: Turning Right");
} else if (currentCommand == "S") {
Serial.println("Action: Stop");
}
Serial.println("-------------------");
}
Step 4: Download the ESP32 WiFi Controller App
- Search for the ESP32 WiFi Controller App on the Google Play Store or Apple App Store.
- Connect your smartphone to the ESP32’s WiFi network (SSID: ESP32-AP, Password: 12345678).
- Open the app and enter the ESP32’s IP address.
- Use the app to control your robot’s movement and speed.
Step 5: Test and Calibrate
- Power on your robot and ensure it connects to the app.
- Test each command (Forward, Backward, Left, Right, Stop) and adjust the speed as needed.
Commonly Asked Questions
1. Can I use a different motor driver?
Yes, you can use other motor drivers like the L293D or TB6612FNG. Just adjust the pin connections accordingly.
2. How do I increase the range of my WiFi-controlled robot?
Use an external antenna or a WiFi repeater to extend the range.
3. Can I control multiple robots with one app?
Yes, but each robot must have a unique SSID and IP address.
Conclusion
Building a WiFi-controlled robot with the ESP32 is a fun and rewarding project that combines electronics, programming, and robotics. With its superior speed and range, this robot outperforms traditional Bluetooth-controlled models. Follow this guide, and you’ll have a fully functional robot in no time. Happy building!
By following this guide, you’ve created a WiFi-controlled robot that’s faster, smarter, and more efficient. Whether you’re a beginner or an experienced maker, this project is a great way to explore the capabilities of the ESP32 and WiFi technology.
Read More –
- Download the BlueBot Controller App here. (For HC-05 Projects)
- Make sure you have a Bluetooth-enabled smartphone to pair with your project.
Downlaod Basic electronics e-Book Click Here
Visit : Home Page
Learn about other sensors, such as Arduino sensors.