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

Arduino UNO and ESP8266 Wi-Fi Controlled Battery-Powered Robot Car

View and Edit Project In Cirkit DesignerImage of Arduino UNO and ESP8266 Wi-Fi Controlled Battery-Powered Robot Car

Circuit Documentation

Summary

This circuit is designed to control a robot using an Arduino UNO and an ESP8266 ESP-01 WiFi module. The Arduino UNO receives commands from the ESP8266 via UART and controls the H-bridge to drive two DC motors. The ESP8266 sets up a web server to allow remote control of the robot via a web interface.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Puente H carrito

    • Description: An H-bridge motor driver for controlling DC motors.
    • Pins: OUT1, OUT2, OUT3, OUT4, 12V, GND, 5V, ENA, IN1, IN2, IN3, IN4, ENB, 5VEN
  3. DC Motor

    • Description: A standard DC motor.
    • Pins: pin 1, pin 2
  4. 2x 18650

    • Description: A battery pack consisting of two 18650 batteries.
    • Pins: vcc, gnd
  5. ESP8266 ESP-01 WiFi Module

    • Description: A WiFi module based on the ESP8266 chip.
    • Pins: TXD, CH_PD, RST, VCC, GND, GPIO_2, GPIO_0, RXD

Wiring Details

Arduino UNO

Puente H carrito

DC Motor

2x 18650

ESP8266 ESP-01 WiFi Module

Code Documentation

Arduino UNO Code

// Arduino UNO code
/*
 * This Arduino Sketch receives commands from the ESP8266 ESP-01 module via
 * UART and controls the H-bridge and motors accordingly.
 */

// Pin definitions
const int trigPin = 6;
const int echoPin = 7;
const int motorA1 = 9;
const int motorA2 = 8;
const int motorB1 = 5;
const int motorB2 = 4;
const int enableA = 10;
const int enableB = 3;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);

  // Initialize pins
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(motorA1, OUTPUT);
  pinMode(motorA2, OUTPUT);
  pinMode(motorB1, OUTPUT);
  pinMode(motorB2, OUTPUT);
  pinMode(enableA, OUTPUT);
  pinMode(enableB, OUTPUT);

  // Enable motors
  analogWrite(enableA, 255);
  analogWrite(enableB, 255);
}

void loop() {
  if (Serial.available() > 0) {
    String command = Serial.readStringUntil('\n');
    command.trim();
    if (command == "forward") {
      moveForward();
    } else if (command == "backward") {
      moveBackward();
    } else if (command == "left") {
      turnLeft();
    } else if (command == "right") {
      turnRight();
    } else if (command == "stop") {
      stopMotors();
    }
  }
}

// Motor control functions
void moveForward() {
  digitalWrite(motorA1, HIGH);
  digitalWrite(motorA2, LOW);
  digitalWrite(motorB1, HIGH);
  digitalWrite(motorB2, LOW);
}

void moveBackward() {
  digitalWrite(motorA1, LOW);
  digitalWrite(motorA2, HIGH);
  digitalWrite(motorB1, LOW);
  digitalWrite(motorB2, HIGH);
}

void turnRight() {
  digitalWrite(motorA1, LOW);
  digitalWrite(motorA2, HIGH);
  digitalWrite(motorB1, HIGH);
  digitalWrite(motorB2, LOW);
}

void turnLeft() {
  digitalWrite(motorA1, HIGH);
  digitalWrite(motorA2, LOW);
  digitalWrite(motorB1, LOW);
  digitalWrite(motorB2, HIGH);
}

void stopMotors() {
  digitalWrite(motorA1, LOW);
  digitalWrite(motorA2, LOW);
  digitalWrite(motorB1, LOW);
  digitalWrite(motorB2, LOW);
}

ESP8266 ESP-01 Code

/*
   This Arduino Sketch sets up a web server on the ESP8266 ESP-01 module to
   control the movement of a robot via the Arduino UNO. The web server has
   buttons to send commands to the Arduino to move forward, backward, left,
   right, and stop.
*/

#include <ESP8266WiFi.h>

// WiFi credentials
const char* ssid = "your_SSID";
const char* password = "your_PASSWORD";

WiFiServer server(80);

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
  delay(10);

  // Connect to WiFi
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  // Start the server
  server.begin();
  Serial.println("Server started");
}

void loop() {
  WiFiClient client = server.available(); // Listen on port 80
  if (client) {
    Serial.println("New connection");
    String request = client.readStringUntil('\r'); // Read HTTP request
    Serial.println(request);
    client.flush();

    // Handle buttons
    if (request.indexOf("/forward") != -1) {
      Serial.println("Command: forward"); // Send forward command
      Serial.write("forward\n");
    }
    if (request.indexOf("/backward") != -1) {
      Serial.println("Command: backward"); // Send backward command
      Serial.write("backward\n");
    }
    if (request.indexOf("/left") != -1) {
      Serial.println("Command: left"); // Send left command
      Serial.write("left\n");
    }
    if (request.indexOf("/right") != -1) {
      Serial.println("Command: right"); // Send right command
      Serial.write("right\n");
    }
    if (request.indexOf