WiFi (ESP8266/ESP32 Module) – More flexible, allows a web interface for controlling via any
device with a browser.
Components:
1. Arduino UNO / ESP32 / ESP8266
2. Motor Driver (L298N / L293D)
3. HC-05 Bluetooth Module OR ESP8266/ESP32 for WiFi
4. Battery Pack
5. Toy Car Chassis with Motors
6. Android Phone with a Bluetooth/WiFi controller app
How It Works:
1. The ESP32/ESP8266 creates a WiFi hotspot or connects to your router.
2. The user accesses a web page served by the ESP module.
3. The page has touch controls for steering (left, right, forward, backward).
4. The ESP32/ESP8266 reads the commands and controls the motor driver (L298N/L293D) to move
the car.
Components Needed:
1. ESP32 / ESP8266 (for WiFi control)
2. L298N or L293D Motor Driver (to control motors)
3. Two DC Motors (for movement)
4. Power Source (Battery pack)
5. Toy Car Chassis
Running car with cellphone operation
#include <WiFi.h>
#include <WebServer.h>
// WiFi Credentials
const char* ssid = "Your_SSID";
const char* password = "Your_PASSWORD";
// Web Server on port 80
WebServer server(80);
// Motor Driver Pins
#define IN1 27
#define IN2 26
#define IN3 25
#define IN4 33
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
Serial.println("Connected!");
Serial.println(WiFi.localIP());
// Motor pins as output
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
// Define web routes
server.on("/", handleRoot);
server.on("/forward", moveForward);
server.on("/backward", moveBackward);
server.on("/left", turnLeft);
server.on("/right", turnRight);
server.on("/stop", stopCar);
server.begin();
void loop() {
server.handleClient();
void handleRoot() {
server.send(200, "text/html", R"rawliteral(
<html>
<head>
<script>
function sendRequest(action) {
fetch(`/${action}`);
</script>
</head>
<body style="text-align:center; font-family:sans-serif;">
<h2>WiFi Car Control</h2>
<button onclick="sendRequest('forward')">Forward</button>
<br><br>
<button onclick="sendRequest('left')">Left</button>
<button onclick="sendRequest('stop')">Stop</button>
<button onclick="sendRequest('right')">Right</button>
<br><br>
<button onclick="sendRequest('backward')">Backward</button>
</body>
</html>
)rawliteral");
void moveForward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
server.send(200, "text/plain", "Moving Forward");
void moveBackward() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
server.send(200, "text/plain", "Moving Backward");
void turnLeft() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
server.send(200, "text/plain", "Turning Left");
void turnRight() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
server.send(200, "text/plain", "Turning Right");
void stopCar() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
server.send(200, "text/plain", "Car Stopped");
Revised for a TANK
#include <WiFi.h>
#include <WebServer.h>
#include <Servo.h>
// WiFi Credentials
const char* ssid = "Your_SSID";
const char* password = "Your_PASSWORD";
// Web Server on port 80
WebServer server(80);
// Motor Driver Pins
#define IN1 27
#define IN2 26
#define IN3 25
#define IN4 33
// Turret Control
Servo turretServo;
#define TURRET_PIN 14
#define FIRE_PIN 12 // Relay or Servo for firing
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
Serial.println("Connected!");
Serial.println(WiFi.localIP());
// Motor pins as output
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
// Turret setup
turretServo.attach(TURRET_PIN);
pinMode(FIRE_PIN, OUTPUT);
digitalWrite(FIRE_PIN, LOW);
// Define web routes
server.on("/", handleRoot);
server.on("/forward", moveForward);
server.on("/backward", moveBackward);
server.on("/left", turnLeft);
server.on("/right", turnRight);
server.on("/stop", stopTank);
server.on("/turret_left", turretLeft);
server.on("/turret_right", turretRight);
server.on("/fire", fireCannon);
server.begin();
void loop() {
server.handleClient();
}
void handleRoot() {
server.send(200, "text/html", R"rawliteral(
<html>
<head>
<script>
function sendRequest(action) {
fetch(`/${action}`);
</script>
</head>
<body style="text-align:center; font-family:sans-serif;">
<h2>WiFi Tank Control</h2>
<button onclick="sendRequest('forward')">Forward</button>
<br><br>
<button onclick="sendRequest('left')">Left</button>
<button onclick="sendRequest('stop')">Stop</button>
<button onclick="sendRequest('right')">Right</button>
<br><br>
<button onclick="sendRequest('backward')">Backward</button>
<br><br>
<h3>Turret Control</h3>
<button onclick="sendRequest('turret_left')">Turret Left</button>
<button onclick="sendRequest('turret_right')">Turret Right</button>
<br><br>
<button onclick="sendRequest('fire')" style="color:red;">FIRE!</button>
</body>
</html>
)rawliteral");
}
void moveForward() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
server.send(200, "text/plain", "Moving Forward");
void moveBackward() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
server.send(200, "text/plain", "Moving Backward");
void turnLeft() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
server.send(200, "text/plain", "Turning Left");
void turnRight() {
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
server.send(200, "text/plain", "Turning Right");
void stopTank() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
server.send(200, "text/plain", "Tank Stopped");
void turretLeft() {
turretServo.write(45); // Adjust angle as needed
server.send(200, "text/plain", "Turret Left");
void turretRight() {
turretServo.write(135); // Adjust angle as needed
server.send(200, "text/plain", "Turret Right");
void fireCannon() {
digitalWrite(FIRE_PIN, HIGH);
delay(500);
digitalWrite(FIRE_PIN, LOW);
server.send(200, "text/plain", "Firing!");
}
📌 Physical Layout Overview:
1. Base Chassis: Tank body with two DC motors for left and right tracks.
2. ESP32/ESP8266 Module: Mounted in the center, handling WiFi communication.
3. Motor Driver (L298N): Connected to ESP32 and DC motors.
4. Turret System:
o Servo Motor rotates the turret left & right.
o Relay or Firing Mechanism activates the cannon.
5. Power Supply:
o LiPo Battery / 18650 Cells (for motors & ESP32).
o Separate voltage regulators if needed.
I'll create a wiring diagram for your WiFi-controlled toy tank. It'll show how to connect:
✅ ESP32/ESP8266
✅ Motor Driver (L298N) for tank tracks
✅ Servo motor for turret rotation
✅ Relay or servo for firing
✅ Power connections
I'll generate the diagram now! 🎨🔧
Since I can't directly draw images, I recommend using Fritzing or Tinkercad to visualize the wiring.
However, here's a detailed wiring description for your WiFi-controlled tank:
🛠 Wiring Connections
1️⃣ ESP32/ESP8266 to L298N Motor Driver
ESP32 Pin L298N Pin Function
GPIO 27 IN1 Left motor forward
GPIO 26 IN2 Left motor backward
GPIO 25 IN3 Right motor forward
GPIO 33 IN4 Right motor backward
5V 5V Power supply
GND GND Ground
2️⃣ ESP32 to Turret Servo (SG90/MG995)
ESP32 Pin Servo Pin Function
GPIO 14 Signal Turret rotation
5V VCC Power supply
GND GND Ground
3️⃣ ESP32 to Firing Mechanism (Relay/Servo)
ESP32 Pin Component Function
GPIO 12 Relay IN / Servo Signal Fire mechanism control
5V VCC Power supply
GND GND Ground
4️⃣ Power Supply
Motors: 12V Battery (Connected to L298N)
ESP32 & Servo: 5V Regulator
🔧 Next Steps
Would you like me to help with a step-by-step guide on how to assemble this, or would you prefer a
Fritzing diagram? 🎨💡
You said:
yes
ChatGPT said:
I'll now create a step-by-step guide for assembling your WiFi-controlled toy tank and also provide a
Fritzing wiring diagram.
🔧 Step-by-Step Assembly Guide
1️⃣ Gather Components
ESP32/ESP8266 (for WiFi control)
L298N Motor Driver (for track motors)
2 x DC Motors (for left & right tank tracks)
1 x Servo Motor (SG90/MG995) (for turret rotation)
1 x Relay or Servo (for firing mechanism)
Battery Pack (12V for motors, 5V for ESP32)
Chassis with Tracks (for movement)
Jumper Wires & Breadboard
2️⃣ Wiring the Components
Connect ESP32 to L298N Motor Driver (Tracks)
Connect ESP32 to Servo Motor (Turret)
Connect ESP32 to Relay/Servo (Firing)
Power everything with the battery pack
Next Steps
I’ll now generate a Fritzing wiring diagram to visualize the connections. Stay tuned! 🎨⚡
I'll create a wiring diagram for your WiFi-controlled tank using a schematic-style layout. The diagram will
illustrate the connections between:
✅ ESP32/ESP8266
✅ L298N Motor Driver (for tank tracks)
✅ Servo (for turret rotation)
✅ Relay/Servo (for firing mechanism)
✅ Battery connections
I'll generate the diagram now! 🎨🔧
Since I can't directly create images, I recommend using Fritzing or Tinkercad to visualize the wiring.
However, I can provide you with a detailed wiring guide so you can easily recreate it in Fritzing.
🛠 Wiring Guide for Your WiFi-Controlled Tank
1️⃣ ESP32 to L298N Motor Driver (Tank Tracks)
ESP32 Pin L298N Pin Function
GPIO 27 IN1 Left motor forward
GPIO 26 IN2 Left motor backward
GPIO 25 IN3 Right motor forward
GPIO 33 IN4 Right motor backward
5V 5V Power supply
ESP32 Pin L298N Pin Function
GND GND Ground
2️⃣ ESP32 to Turret Servo (SG90/MG995)
ESP32 Pin Servo Pin Function
GPIO 14 Signal Turret rotation
5V VCC Power supply
GND GND Ground
3️⃣ ESP32 to Firing Mechanism (Relay/Servo)
ESP32 Pin Component Function
GPIO 12 Relay IN / Servo Signal Fire mechanism control
5V VCC Power supply
GND GND Ground
4️⃣ Power Supply
Motors: 12V Battery (Connected to L298N)
ESP32 & Servo: 5V Regulator
🔧 Next Steps
1. Open Fritzing (free software for circuit design).
2. Add components (ESP32, L298N, Servo, Relay, Motors, Battery).
3. Connect wires following the table above.
4. Adjust layout for clarity.