# Wi-Fi robot car on an ESP32 with a web control page: design worksheet and code

> A ₹1,340 design worksheet for a robot car you drive from a phone browser over the ESP32’s own Wi-Fi hotspot, with a command table, a safe stop-on-silence timer and PWM levels explained.

Canonical: https://roboticsengineering.in/projects/esp32-wifi-robot-car-web-control/ | Published: 2026-11-04 | Updated: 2026-11-04

**A ₹1,340 robot car that needs no app and no router. The ESP32 makes its own Wi-Fi hotspot, serves a small control page, and drives the motors while a button on the page is held. A stop-on-silence timer stops the car by itself if the phone goes out of range.**

**Scope:** intermediate. This is a design worksheet with illustrative costs. It has not been bench-tested by this site. The speed table below was computed by script. The sketch was written for the arduino-esp32 3.x core, where analogWrite is available; on the older 2.x core you would use ledcSetup and ledcAttachPin instead. The hotspot name and password in the sketch are placeholders and the password must be changed.

## How it works

The ESP32 runs as a Wi-Fi access point and a web server. A phone joins the hotspot and opens the default address of the access point, 192.168.4.1. The page has five buttons. Holding a button sends a short request such as /cmd?d=F every 150 ms, and releasing it sends /cmd?d=S for stop.

If the phone leaves range or the page closes, no more requests arrive. The sketch stops the motors when 500 ms have passed since the last request, which is more than three missed requests. This stop-on-silence rule is the most important safety feature of any remote-controlled robot.

## Bill of materials

| Part | Qty | Unit | Total |
| --- | --- | --- | --- |
| ESP32 development board | 1 | ₹450 | ₹450 |
| L298N motor driver board | 1 | ₹180 | ₹180 |
| 2WD chassis kit with two gear motors and wheels | 1 | ₹450 | ₹450 |
| Battery holder with two 18650 cells | 1 | ₹210 | ₹210 |
| Jumper wires | 1 | ₹50 | ₹50 |
| Parts total | ₹1,340 |  |  |

Scroll the table sideways to see every column.

Prices checked Nov 2026. Shipping and tools are not included.

Prices are illustrative figures for Indian sellers in November 2026, before shipping, and have not been checked against current listings.

## The numbers

| Speed level | PWM value (0 to 255) | Duty |
| --- | --- | --- |
| Slow | 100 | 39% |
| Medium | 160 | 63% |
| Fast | 220 | 86% |
| Full | 255 | 100% |

*Duty = value / 255. Motors usually need a minimum PWM to start turning, which depends on the motor and battery.*

Requests every 150 ms are about 6.7 a second. With a 500 ms timeout, three requests in a row must be lost before the car stops, which smooths short Wi-Fi glitches without leaving it running for long.

## Power and wiring

| Part | Connects to | Note |
| --- | --- | --- |
| L298N ENA / IN1 / IN2 | GPIO 14 / 26 / 27 | Left motor |
| L298N ENB / IN3 / IN4 | GPIO 13 / 32 / 33 | Right motor |
| ESP32 power | 5 V from the L298N 5V output, or a USB power bank | Do not feed the ESP32 5 V and USB together |
| Battery | L298N 12V input | Join the ESP32 GND to the L298N GND |

*The L298N logic inputs generally accept 3.3 V signals from the ESP32, but check your board. Avoid GPIO 12 and the other boot-strapping pins.*

## The sketch

```
// ESP32 Wi-Fi robot car: hotspot + web control + L298N
// Design worksheet: for the arduino-esp32 3.x core. Change the password!

#include <WiFi.h>
#include <WebServer.h>

const char* AP_NAME = "RobotCar";
const char* AP_PASS = "change-this-pass";   // at least 8 characters

const int L_EN = 14, L_IN1 = 26, L_IN2 = 27;
const int R_EN = 13, R_IN3 = 32, R_IN4 = 33;
const int SPEED = 160;
const unsigned long TIMEOUT_MS = 500;

WebServer server(80);
char cmd = 'S';
unsigned long lastCmd = 0;

const char PAGE[] PROGMEM = R"rawliteral(
<!doctype html><meta name=viewport content="width=device-width,initial-scale=1">
<style>button{width:30vw;height:20vw;font-size:8vw;margin:1vw;touch-action:none}</style>
<div><button onpointerdown="hold('F')" onpointerup="rel()" onpointerleave="rel()">F</button></div>
<div><button onpointerdown="hold('L')" onpointerup="rel()" onpointerleave="rel()">L</button>
<button onpointerdown="hold('R')" onpointerup="rel()" onpointerleave="rel()">R</button></div>
<div><button onpointerdown="hold('B')" onpointerup="rel()" onpointerleave="rel()">B</button></div>
<script>
let t=null;
function send(d){fetch('/cmd?d='+d).catch(()=>{});}
function hold(d){rel();send(d);t=setInterval(()=>send(d),150);}
function rel(){if(t){clearInterval(t);t=null;send('S');}}
</script>
)rawliteral";

void drive(int left, int right) {
  digitalWrite(L_IN1, left >= 0);  digitalWrite(L_IN2, left < 0);
  digitalWrite(R_IN3, right >= 0); digitalWrite(R_IN4, right < 0);
  analogWrite(L_EN, abs(left));
  analogWrite(R_EN, abs(right));
}

void handleCmd() {
  if (server.hasArg("d")) { cmd = server.arg("d")[0]; lastCmd = millis(); }
  server.send(200, "text/plain", "ok");
}

void setup() {
  int pins[] = {L_EN, L_IN1, L_IN2, R_EN, R_IN3, R_IN4};
  for (int p : pins) pinMode(p, OUTPUT);
  drive(0, 0);
  WiFi.softAP(AP_NAME, AP_PASS);
  server.on("/", []() { server.send_P(200, "text/html", PAGE); });
  server.on("/cmd", handleCmd);
  server.begin();
}

void loop() {
  server.handleClient();
  if (millis() - lastCmd > TIMEOUT_MS) cmd = 'S';
  switch (cmd) {
    case 'F': drive(SPEED, SPEED); break;
    case 'B': drive(-SPEED, -SPEED); break;
    case 'L': drive(-SPEED, SPEED); break;
    case 'R': drive(SPEED, -SPEED); break;
    default:  drive(0, 0);
  }
}
```

Anyone who joins the hotspot can drive the car, so choose a real password. Because the sketch uses a plain web server and no encryption beyond Wi-Fi’s own, do not put anything private on this network. The sketch has been proofread but not compiled on this site.

## Test plan

1. **Join the hotspot:** connect a phone and open 192.168.4.1; the five buttons should appear.
2. **Wheels up:** test each button with the wheels off the floor and swap motor wires if a direction is wrong.
3. **Stop on release:** hold F, release it, and confirm the car stops at once.
4. **Stop on silence:** hold F, then turn off the phone’s Wi-Fi and check the car stops within about half a second.
5. **Range:** walk away indoors and note where commands start to lag.
6. **Battery:** watch whether the ESP32 resets when the motors start, which means the supply is sagging.

## What usually goes wrong

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| Page does not load | Phone is on mobile data or another Wi-Fi | Join the RobotCar hotspot and disable mobile data |
| Car runs after release | Release event missed | The 500 ms timeout stops it; check the timeout logic |
| ESP32 resets when motors start | Voltage dip | Power the ESP32 from a separate bank or add a capacitor |
| analogWrite not found | Older ESP32 core | Update the core or use the ledc functions |
| One side always wrong | Motor wires reversed | Swap that motor’s two wires |

## Upgrades

- **Speed slider:** add a slider to the page.
- **Telemetry:** show battery voltage on the page.
- **Camera:** use an ESP32-CAM for a video view.
- **Station mode:** join your home Wi-Fi instead of making a hotspot.

## Cost and parts notes

The ₹1,340 total is an illustration and does not include shipping. Use the [cost calculator](https://roboticsengineering.in/robotics-project-cost-calculator/) to compare sellers.

## Common questions

**Why does the car need its own hotspot?**

It means the car works anywhere, even without a router.

**What is the stop-on-silence timer for?**

It makes the car stop if the phone disconnects, so it cannot run away.

**Can several phones connect?**

Yes, and each can send commands, which is why the password matters.

**Why not use WebSockets?**

They would reduce latency, but plain requests are simpler to write and are enough for a small car.

Last reviewed: November 2026. This is a design worksheet with illustrative costs. It has not been bench-tested by this site; library names, pins and limits must be checked against your board and the current library versions, and measurements from your build are welcome.
