Gokul K B
Published © CC BY-NC-ND

ESP32-Powered 4x4 RC Rover Fully 3D Printed & Wi-Fi Control

3D-printed 4x4 RC rover powered by the compact and powerful Seeed Studio XIAO ESP32C3

IntermediateFull instructions provided2 hours1,255
ESP32-Powered 4x4 RC Rover Fully 3D Printed & Wi-Fi Control

Things used in this project

Hardware components

Seeed Studio XIAO ESP32C3 Pre-Soldered
Seeed Studio XIAO ESP32C3 Pre-Soldered
×1

Software apps and online services

Fusion
Autodesk Fusion

Story

Read more

Custom parts and enclosures

STL & STEP

Schematics

drawing_B1jdhzfalb.jpg

Code

Untitled file

C/C++
#include <WiFi.h>
#include <WebServer.h>

// Motor driver pins
const int motorA1 = D5; // D6
const int motorA2 = D6; // D5
const int motorB1 = D7; // D7
const int motorB2 = D8; // D8

// WiFi Access Point credentials
const char* ssid = "RC-Tank";
const char* password = "12345678";

IPAddress local_ip(192, 168, 50, 1);
IPAddress gateway(192, 168, 50, 1);
IPAddress subnet(255, 255, 255, 0);

WebServer server(80);

// HTML page with directional buttons
const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE html>
<html>
<head>
<title>RC Tank Control</title>
<style>
body { background-color: #111; color: white; text-align: center; font-family: sans-serif; }
h2 { margin-top: 20px; }
button {
width: 100px; height: 60px; font-size: 20px;
margin: 10px; border-radius: 10px; border: none;
background: #444; color: white;
    }
button:hover { background: #666; }
</style>
</head>
<body>
<h2>RC Tank Control</h2>
<div>
<buttononclick="send('F')">Forward</button><br>
<buttononclick="send('L')">Left</button>
<buttononclick="send('S')">Stop</button>
<buttononclick="send('R')">Right</button><br>
<buttononclick="send('B')">Backward</button>
</div>

<script>
functionsend(cmd) {
fetch(`/move?dir=${cmd}`);
}
</script>
</body>
</html>
)rawliteral";

void setup() {
  Serial.begin(115200);

  pinMode(motorA1, OUTPUT);
  pinMode(motorA2, OUTPUT);
  pinMode(motorB1, OUTPUT);
  pinMode(motorB2, OUTPUT);
  stopMotors();

  // Start Wi-Fi AP
  WiFi.softAPConfig(local_ip, gateway, subnet);
  WiFi.softAP(ssid, password);

  Serial.println("Wi-Fi AP Started");
  Serial.println(WiFi.softAPIP());

  // Serve main web page
  server.on("/", HTTP_GET, []() {
    server.send_P(200, "text/html", index_html);
  });

  // Movement handler
  server.on("/move", HTTP_GET, []() {
    String dir = server.arg("dir");
    handleDirection(dir);
    server.send(200, "text/plain", "OK");
  });

  server.begin();
}

void loop() {
  server.handleClient();
}

// Movement logic
void handleDirection(String dir) {
  dir.toUpperCase();
  if (dir == "F") {
    moveForward();
  } else if (dir == "B") {
    moveBackward();
  } else if (dir == "L") {
    turnLeft();
  } else if (dir == "R") {
    turnRight();
  } else {
    stopMotors();
  }
}

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 turnLeft() {
  digitalWrite(motorA1, LOW);
  digitalWrite(motorA2, HIGH);
  digitalWrite(motorB1, HIGH);
  digitalWrite(motorB2, LOW);
}

void turnRight() {
  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);
}

Credits

Gokul K B
34 projects • 30 followers
⚡Electronics Engineer |🛠️Maker & Open-Source Enthusiast | 🚀 3D Printing & CAD Expert | 🏗️ Product Design |🔌Embedded Systems & PCB Design

Comments