WiFi Controlled RC Robot using ESP8266

J
Jagannath Panigrahi
April 10, 2026
1 likes
0 comments

RC Robot using ESP8266 (Wemos D1 Mini) with Ultrasonic Obstacle Avoidance

Overview

This project is a WiFi-controlled robotic car built using the ESP8266-based Wemos D1 Mini. It supports both manual control through a web interface and autonomous obstacle avoidance using an ultrasonic sensor.

The robot creates its own WiFi hotspot, allowing any smartphone or laptop to connect and control it directly via a browser without requiring a dedicated mobile application.


Features

  • WiFi Access Point mode (no router required)
  • Web-based control interface
  • Manual control (forward, backward, left, right, stop)
  • Autonomous obstacle avoidance mode
  • Real-time response
  • Simple and low-cost hardware setup

Hardware Requirements

  • Wemos D1 Mini (ESP8266)
  • HC-SR04 Ultrasonic Sensor
  • L298N Motor Driver Module
  • 2 DC Motors with wheels
  • Robot chassis
  • Battery pack (7.4V or 9V recommended)
  • Jumper wires

Pin Configuration

Ultrasonic Sensor

Sensor PinWemos D1 Mini
VCC5V
GNDGND
TRIGD5
ECHOD6

Motor Driver (L298N)

L298N PinWemos Pin
IN1D1
IN2D2
IN3D3
IN4D4
ENAD7
ENBD8

How It Works

Manual Mode

  • User connects to robot WiFi
  • Opens web interface
  • Sends movement commands
  • Robot responds instantly

Auto Mode

  • Ultrasonic sensor measures distance continuously

  • If obstacle is detected:

    • Robot stops
    • Moves backward
    • Turns to avoid collision
  • Otherwise, moves forward


Getting Started

1. Upload Code

  • Open Arduino IDE
  • Select board: Wemos D1 Mini (ESP8266)
  • Upload the provided code

2. Power the Robot

  • Use battery pack or external power supply

3. Connect to WiFi

  • SSID: RC_Robot
  • Password: 12345678

4. Open Web Interface

Open browser and go to: http://192.168.4.1


Project Structure

RC-Robot-ESP8266/

  • robot_code.ino
  • README.md
  • circuit_diagram.png
  • robot_image.jpg

Applications

  • Robotics learning projects
  • IoT-based vehicle control
  • Obstacle avoidance systems
  • Educational demonstrations

Future Improvements

  • Mobile app control (Android / iOS)
  • Camera integration for live streaming
  • Voice command support
  • AI-based navigation
  • Line following feature

License

This project is open-source and free to use for educational and personal purposes.


Author

Developed as a DIY IoT robotics project using ESP8266 and basic electronic components.

Source Code

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

// Motor Pins
#define IN1 D1
#define IN2 D2
#define IN3 D3
#define IN4 D4
#define ENA D7
#define ENB D8

// Ultrasonic Pins
#define TRIG D5
#define ECHO D6

ESP8266WebServer server(80);

bool autoMode = false;

// WiFi credentials
const char* ssid = "RC_Robot";
const char* password = "12345678";

// Distance function
long getDistance() {
  digitalWrite(TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG, LOW);

  long duration = pulseIn(ECHO, HIGH);
  long distance = duration * 0.034 / 2;
  return distance;
}

// Motor functions
void stopMotors() {
  digitalWrite(IN1, LOW); digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW); digitalWrite(IN4, LOW);
}

void forward() {
  digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
}

void backward() {
  digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH);
}

void left() {
  digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW);
}

void right() {
  digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH);
}

// Web Handlers
void handleRoot() {
  String html = R"rawliteral(
  <!DOCTYPE html>
  <html>
  <head>
  <title>Robot Control</title>
  <style>
    body { text-align:center; font-family:Arial; background:#222; color:white; }
    button { width:120px; height:50px; margin:10px; font-size:16px; }
  </style>
  </head>
  <body>
  <h2>Robot Control</h2>
  <button onclick="fetch('/auto')">AUTO MODE</button>
  <button onclick="fetch('/manual')">MANUAL MODE</button><br>
  <button onclick="fetch('/forward')">FORWARD</button><br>
  <button onclick="fetch('/left')">LEFT</button>
  <button onclick="fetch('/stop')">STOP</button>
  <button onclick="fetch('/right')">RIGHT</button><br>
  <button onclick="fetch('/backward')">BACKWARD</button>
  </body>
  </html>
  )rawliteral";

  server.send(200, "text/html", html);
}

void setupRoutes() {
  server.on("/", handleRoot);

  server.on("/forward", []() {
    autoMode = false;
    forward();
    server.send(200, "text/plain", "Forward");
  });

  server.on("/backward", []() {
    autoMode = false;
    backward();
    server.send(200, "text/plain", "Backward");
  });

  server.on("/left", []() {
    autoMode = false;
    left();
    server.send(200, "text/plain", "Left");
  });

  server.on("/right", []() {
    autoMode = false;
    right();
    server.send(200, "text/plain", "Right");
  });

  server.on("/stop", []() {
    autoMode = false;
    stopMotors();
    server.send(200, "text/plain", "Stop");
  });

  server.on("/auto", []() {
    autoMode = true;
    server.send(200, "text/plain", "Auto Mode");
  });

  server.on("/manual", []() {
    autoMode = false;
    stopMotors();
    server.send(200, "text/plain", "Manual Mode");
  });

  server.begin();
}

void setup() {
  pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT);
  pinMode(ENA, OUTPUT); pinMode(ENB, OUTPUT);

  pinMode(TRIG, OUTPUT);
  pinMode(ECHO, INPUT);

  analogWrite(ENA, 800);
  analogWrite(ENB, 800);

  WiFi.softAP(ssid, password);

  setupRoutes();
}

void loop() {
  server.handleClient();

  if (autoMode) {
    long distance = getDistance();

    if (distance < 20) {
      stopMotors();
      delay(300);
      backward();
      delay(500);
      right();
      delay(400);
    } else {
      forward();
    }
  }
}

Comments (0)

No comments yet. Share your feedback!

Leave a Comment

You need to be logged in to join the conversation.