Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

ESP8266 WiFi-Controlled Robot with L298N Motor Driver and LED/Buzzer Indicators

View and Edit Project In Cirkit DesignerImage of ESP8266 WiFi-Controlled Robot with L298N Motor Driver and LED/Buzzer Indicators

Circuit Documentation

Summary

This circuit is designed to control a four-wheeled robot with two DC gearmotors for each side (left and right), an ESP8266 NodeMCU microcontroller for logic control, an L298N DC motor driver for motor control, a buzzer for audio signaling, an LED for visual signaling, a TP5100 module for battery charging, and a rocker switch for power control. The ESP8266 NodeMCU is programmed to receive commands via a WiFi connection to drive the motors, control the LED, and activate the buzzer.

Component List

Gearmotor DC Wheels (Right and Left)

L298N DC Motor Driver

18650 Li-Ion Battery

DC Female Jack

Rocker Switch

LED: Two Pin (White)

ESP8266 NodeMCU

Buzzer

TP5100

Wiring Details

Gearmotor DC Wheels (Right and Left)

L298N DC Motor Driver

18650 Li-Ion Battery

DC Female Jack

Rocker Switch

LED: Two Pin (White)

ESP8266 NodeMCU

Buzzer

TP5100

Documented Code

#define ENA   14          // Enable/speed motors Right        GPIO14(D5)
#define ENB   12          // Enable/speed motors Left         GPIO12(D6)
#define IN_1  15          // L298N in1 motors Right           GPIO15(D8)
#define IN_2  13          // L298N in2 motors Right           GPIO13(D7)
#define IN_3  2           // L298N in3 motors Left            GPIO2(D4)
#define IN_4  0           // L298N in4 motors Left            GPIO0(D3)

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

String command;             // String to store app command state.
int speedCar = 800;         // Speed range between 400 - 1023.
int speed_Coeff = 3;        // Speed coefficient for turning.

const int beepHornPin = D1; // Buzzer pin.
const int ledPin = D2;      // LED pin.

const char* ssid = "ESP8266_Wifi_Car"; // WiFi SSID.
const char* pwd = "test@123";          // WiFi Password.
ESP8266WebServer server(80);           // Web server on port 80.

void setup() {
  // Motor control pins setup
  pinMode(ENA, OUTPUT);
  pinMode(ENB, OUTPUT);  
  pinMode(IN_1, OUTPUT);
  pinMode(IN_2, OUTPUT);
  pinMode(IN_3, OUTPUT);
  pinMode(IN_4, OUTPUT); 

  // Buzzer and LED pins setup
  pinMode(beepHornPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
  Serial.begin(115200); // Start serial communication at 115200 baud rate.
  
  // Connecting to WiFi
  WiFi.mode(WIFI_AP); // Set WiFi to AP mode.
  WiFi.softAP(ssid);  // Start WiFi access point with SSID and password.

  IPAddress myIP = WiFi.softAPIP(); // Get IP address of the ESP8266.
  Serial.print("192.168.4.1 ");     // Print the IP address to the serial monitor.
  Serial.println(myIP);
  
  // Starting the web server
  server.on("/", HTTP_handleRoot); // Define root URL handling.
  server.onNotFound(HTTP_handleRoot); // Handle not found URLs.
  server.begin(); // Start the server.
}

// Function definitions for robot movement, horn, and LED control omitted for brevity.

void loop() {
  server.handleClient(); // Handle incoming client requests.
  
  // Process command from the web server.
  command = server.arg("State");
  // Movement commands
  if (command == "F") goAhead();
  else if (command == "B") goBack();
  else if (command == "L") goLeft();
  else if (command == "R") goRight();
  else if (command == "I") goAheadRight();
  else if (command == "G") goAheadLeft();
  else if (command == "J") goBackRight();
  else if (command == "H") goBackLeft();
  // Horn and LED commands
  else if (command == "V") beepHorn();
  else if (command == "W") ledOn();
  else if (command == "w") ledOff();
  // Speed adjustment commands
  else if (command == "0") speedCar = 400;
  // ... other speed settings omitted for brevity.
  else if (command == "9") speedCar = 1023;
  else if (command == "S") stopRobot(); // Stop the robot.
}

void HTTP_handleRoot(void) {
  if(server.hasArg("State")){
    Serial.println(server.arg("State")); // Print the command to the serial monitor.
  }
  server.send(200, "text/html", ""); // Send response to the client.
  delay(1); // Short delay.
}

Note: The full implementation of the movement functions (goAhead, goBack, goLeft, goRight, etc.), horn (beepHorn), and LED control (ledOn, ledOff) are not included in this document for brevity. These functions are responsible for controlling the GPIO pins according to the commands received from the web server, thus driving the motors, activating the buzzer, and toggling the LED.