Wi-Fi Controlled Robot Car using ESP32

 Wi-Fi Controlled Robot Car using ESP32


Introduction

 The Wi-Fi Controlled Robot Car is a fun and educational project where you control a robot vehicle directly from your smartphone or laptop’s web browser. Using the ESP32 microcontroller’s built-in Wi-Fi capabilities, the car can receive commands in real-time without any external modules. This makes it perfect for robotics enthusiasts, students, and IoT hobbyists.


Working Principle

The ESP32 acts as both a microcontroller and Wi-Fi server.

When powered on, it creates its own Wi-Fi hotspot or connects to an existing router.

The user accesses a web interface with control buttons (Forward, Backward, Left, Right, Stop).

When a button is pressed, the ESP32 sends signals to the motor driver to move the car accordingly.


Components Required


ESP32 Development Board


L298N Motor Driver Module


2 × DC Geared Motors (with wheels)


1 × Caster Wheel


Li-ion Battery Pack (7.4V or 11.1V)


Jumper Wires


Chassis for Robot Car



Block Diagram



Circuit Diagram (Description)


ESP32 GPIO pins are connected to IN1, IN2, IN3, IN4 of the L298N motor driver.


Motor driver output pins OUT1 & OUT2 connect to Motor A, and OUT3 & OUT4 connect to Motor B.


The motor driver is powered by the battery pack, and the ESP32 is powered via its Vin pin from the same source.


Arduino Code (Basic Version)


#include <WiFi.h>

#include <WebServer.h>


// Wi-Fi Credentials

const char* ssid = "ESP32_Robot";

const char* password = "12345678";


// Motor pins

int IN1 = 14;

int IN2 = 12;

int IN3 = 27;

int IN4 = 26;


WebServer server(80);


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);

}


void stopCar() {

  digitalWrite(IN1, LOW);

  digitalWrite(IN2, LOW);

  digitalWrite(IN3, LOW);

  digitalWrite(IN4, LOW);

}


void handleRoot() {

  server.send(200, "text/html", "<h1>ESP32 Robot Car</h1>\

  <button onclick=\"location.href='/f'\">Forward</button>\

  <button onclick=\"location.href='/b'\">Backward</button>\

  <button onclick=\"location.href='/l'\">Left</button>\

  <button onclick=\"location.href='/r'\">Right</button>\

  <button onclick=\"location.href='/s'\">Stop</button>");

}


void setup() {

  Serial.begin(115200);


  pinMode(IN1, OUTPUT);

  pinMode(IN2, OUTPUT);

  pinMode(IN3, OUTPUT);

  pinMode(IN4, OUTPUT);


  WiFi.softAP(ssid, password);


  server.on("/", handleRoot);

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

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

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

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

  server.on("/s", []() { stopCar(); server.send(200, "text/plain", "Stop"); });


  server.begin();

}


void loop() {

  server.handleClient();

}


Advantages


No Bluetooth module required — uses built-in Wi-Fi.


Can be controlled from any device with a browser.


Can be expanded with sensors for obstacle avoidance.


Comments

Popular posts from this blog

Smart Home Automation System Project using Arduino

Solar mobile charger

Automatic street light