How to Build a Remote-Controlled Car with Wi-Fi Control

Building Remote-Controlled Cars / Visits:7

If you’ve ever wanted to build your own Wi-Fi-controlled car but felt intimidated by the complexity, you’re not alone. The good news is that with modern microcontrollers, affordable Wi-Fi modules, and the surprisingly versatile micro servo motor, you can build a fully functional, remotely operated vehicle that responds to commands from your smartphone or laptop. In this guide, we’ll walk through the entire process—from selecting components and understanding the role of micro servo motors in steering and actuation, to writing the code that brings your car to life. By the end, you’ll have a solid blueprint for a project that combines electronics, mechanics, and wireless networking.

Why Micro Servo Motors Matter in a Wi-Fi Car

When people think of RC cars, they often imagine brushed DC motors for drive and maybe a simple steering mechanism. But the micro servo motor changes the game. These tiny, lightweight actuators offer precise angular control (typically 0 to 180 degrees), low power consumption, and easy integration with microcontrollers like the ESP8266 or ESP32. In a Wi-Fi car, micro servos can handle steering, camera gimbals, or even robotic arms. Their small size means they fit into compact chassis without adding significant weight.

Key advantages of micro servo motors in this project: - Precision: You can command a specific angle, enabling fine-grained steering adjustments. - Simplicity: They require only a PWM signal, a power line, and ground—no complex drivers. - Low cost: Quality micro servos (like SG90 or MG90S) cost under $5 each. - Low power: They draw minimal current, ideal for battery-powered projects.

For our car, we’ll use a micro servo motor to steer the front wheels. This gives us smooth, proportional steering rather than the jerky on/off control typical of simple DC motor-based steering.

Project Overview: What We’re Building

We’re building a two-wheel drive (2WD) car with a third caster wheel for balance. The drive motors are standard DC gear motors controlled by an L298N motor driver. Steering is handled by a micro servo motor connected to the front axle via a linkage. An ESP32 microcontroller (with built-in Wi-Fi) receives commands over a local network, processes them, and sends PWM signals to both the drive motors and the servo.

The control interface is a simple web page hosted on the ESP32. You connect your phone or laptop to the car’s Wi-Fi network (or the same LAN), open the web page, and use virtual buttons or a joystick to drive.

Components List

  • ESP32 Dev Board (e.g., ESP32-WROOM-32) – the brain with Wi-Fi and Bluetooth.
  • L298N Motor Driver – to control two DC motors.
  • 2x DC Gear Motors with wheels (e.g., 3-6V, 100-200 RPM).
  • Micro Servo Motor (SG90 or MG90S) – for steering.
  • Caster Wheel – for front support.
  • Chassis – acrylic, 3D-printed, or even cardboard.
  • Power Supply: 7.4V Li-ion battery pack (2S) or 6x AA batteries.
  • Jumper wires, breadboard, and connectors.
  • Voltage regulator (AMS1117-3.3V) if needed for servo logic.

How the Micro Servo Motor Fits Into the Mechanical Design

The steering mechanism is straightforward. The micro servo sits on the chassis, its horn connected to a linkage rod. The rod connects to a steering arm that pivots the front wheels. When the servo rotates, it pushes or pulls the linkage, turning the wheels left or right. Because the servo can hold any angle, you get proportional steering—turn the wheels 10 degrees for a gentle curve, or 45 degrees for a sharp turn.

Important: The servo’s torque must be sufficient to overcome friction. The SG90 provides about 1.2 kg·cm, which is fine for lightweight plastic wheels on smooth surfaces. For heavier cars or rough terrain, upgrade to the MG90S (2.2 kg·cm) or even a metal-gear servo.

Step 1: Wiring the Electronics

Let’s connect everything. The ESP32 will be the central controller. Here’s the pinout we’ll use:

| Component | ESP32 Pin | Notes | |-----------|-----------|-------| | L298N IN1 | GPIO 26 | Left motor forward | | L298N IN2 | GPIO 27 | Left motor backward | | L298N IN3 | GPIO 14 | Right motor forward | | L298N IN4 | GPIO 12 | Right motor backward | | L298N ENA | GPIO 13 | PWM speed control left | | L298N ENB | GPIO 15 | PWM speed control right | | Servo signal | GPIO 4 | PWM for steering | | Servo VCC | 5V (from L298N 5V out) | Or external 5V regulator | | Servo GND | Common GND | |

Power Note: The L298N has a built-in 5V regulator that can power the ESP32 and servo, but only if the motor supply is 7-12V. For a 7.4V battery, this works. However, the servo may cause voltage dips during rapid movement. A separate 5V regulator for the servo is safer.

Wiring Diagram (Textual)

Battery + (7.4V) --> L298N 12V input Battery - (GND) --> L298N GND

L298N 5V output --> ESP32 VIN (5V pin) and Servo VCC (red wire) L298N GND --> ESP32 GND, Servo GND (brown wire)

L298N OUT1, OUT2 --> Left motor L298N OUT3, OUT4 --> Right motor

ESP32 GPIO 4 --> Servo signal (orange/yellow wire)

Double-check all connections before powering on. A wrong connection can fry the ESP32 or servo.

Step 2: Programming the ESP32 for Wi-Fi and Servo Control

We’ll write the code in the Arduino IDE. The ESP32 will run a web server that serves an HTML page with control buttons. When you press a button, an HTTP request is sent to the ESP32, which then adjusts the motors and servo accordingly.

Setting Up the Servo Library

The ESP32 servo control is similar to Arduino but uses the ESP32Servo library. Install it via the Library Manager.

cpp

include <WiFi.h>

include <WebServer.h>

include <ESP32Servo.h>

Servo steeringServo; int servoPin = 4; int servoAngle = 90; // Center position

void setup() { steeringServo.attach(servoPin); steeringServo.write(servoAngle); // Start centered }

The servo expects a PWM signal with a period of 20ms and a pulse width between 1ms (0 degrees) and 2ms (180 degrees). The library handles this automatically.

Wi-Fi Configuration

We’ll set the ESP32 as a Wi-Fi access point (AP) so you don’t need a router. This makes the car portable.

cpp const char* ssid = "WiFi_Car"; const char* password = "12345678";

WebServer server(80);

void setup() { WiFi.softAP(ssid, password); Serial.print("AP IP address: "); Serial.println(WiFi.softAPIP()); }

The IP will typically be 192.168.4.1. Connect your phone to this network, then open a browser to that IP.

Handling HTTP Requests

We’ll define endpoints like /forward, /backward, /left, /right, /stop, and /steer?angle=45.

cpp server.on("/forward", { digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); analogWrite(ENA, 200); // Speed 0-255 analogWrite(ENB, 200); server.send(200, "text/plain", "Forward"); });

server.on("/left", { servoAngle = 135; // Turn right (servo mounted facing forward) steeringServo.write(servoAngle); server.send(200, "text/plain", "Left"); });

server.on("/steer", { if(server.hasArg("angle")){ int angle = server.arg("angle").toInt(); angle = constrain(angle, 0, 180); steeringServo.write(angle); servoAngle = angle; server.send(200, "text/plain", "Steer " + String(angle)); } });

Why servo angles for steering? If the servo is mounted with the horn pointing forward, 90 degrees is straight. 45 degrees turns left, 135 degrees turns right. You’ll need to calibrate based on your mechanical linkage.

The Complete HTML Interface

The ESP32 serves an HTML page with buttons. Here’s a minimal example:

cpp server.on("/", [](){ String html = "<!DOCTYPE html><html><body>"; html += "<h1>Wi-Fi Car Control</h1>"; html += "<button onmousedown='fetch(\"/forward\")' onmouseup='fetch(\"/stop\")'>Forward</button>"; html += "<button onmousedown='fetch(\"/left\")' onmouseup='fetch(\"/center\")'>Left</button>"; html += "<button onmousedown='fetch(\"/right\")' onmouseup='fetch(\"/center\")'>Right</button>"; html += "<button onmousedown='fetch(\"/backward\")' onmouseup='fetch(\"/stop\")'>Backward</button>"; html += "<br><input type='range' min='0' max='180' value='90' oninput='fetch(\"/steer?angle=\"+this.value)'>"; html += "</body></html>"; server.send(200, "text/html", html); });

The slider allows continuous steering angle adjustment, which is where the micro servo motor truly shines. Unlike a simple left/right toggle, you can set any angle, mimicking a real car’s steering wheel.

Step 3: Mechanical Assembly and Servo Integration

Now for the hands-on part. Mount the micro servo securely to the chassis. Use screws or double-sided tape. The servo horn should be at the same height as the steering linkage.

Building the Steering Linkage

  1. Attach a servo horn to the servo shaft.
  2. Connect a linkage rod (a stiff wire or a plastic rod with ball joints) from the horn to the steering arm.
  3. The steering arm should pivot the front wheels. You can use a simple L-bracket or a 3D-printed part.
  4. Ensure free movement: The servo should not bind at extreme angles. If it does, adjust the linkage length.

Testing the servo range: Before final assembly, run a test sketch that sweeps the servo from 0 to 180 degrees. Mark the positions where the wheels are straight, full left, and full right. Then adjust the linkage so that straight corresponds to 90 degrees.

Calibrating the Servo for Straight Driving

Even with perfect mechanics, the car may drift. In the code, you can add a trim offset:

cpp int steeringTrim = 0; // Adjust this value (e.g., -5 to +5 degrees) void setSteering(int angle){ steeringServo.write(angle + steeringTrim); }

Test drive on a flat surface, note the drift direction, and adjust steeringTrim accordingly.

Step 4: Advanced Features with Micro Servo Motors

Once the basic car works, you can extend the project using additional micro servos.

Adding a Camera Gimbal

Mount a small camera (like an ESP32-CAM) on a two-axis gimbal using two micro servos. One servo controls pitch, the other yaw. Control them via separate HTTP endpoints or joystick.

cpp Servo pitchServo, yawServo; pitchServo.attach(5); // GPIO 5 yawServo.attach(18); // GPIO 18

Now you have a first-person view (FPV) car. The gimbal can be controlled independently of the steering, giving you a “look around” capability.

Implementing a Robotic Arm

A micro servo can also actuate a small claw or arm. Add a servo on top of the car to open/close a gripper. This turns your car into a simple pick-and-place robot. Control the gripper with a button on the web page.

cpp server.on("/grip", [](){ gripServo.write(0); // Close server.send(200, "text/plain", "Grip"); }); server.on("/release", [](){ gripServo.write(90); // Open server.send(200, "text/plain", "Release"); });

Speed Control via Servo? Not Quite, But…

While micro servos are for angular position, you can use them to control a potentiometer that adjusts motor speed via analog input. But it’s simpler to use PWM directly on the motor driver. The servo is best left for steering and auxiliary functions.

Step 5: Troubleshooting Common Micro Servo Issues

Even with careful assembly, you may encounter problems. Here are typical issues and fixes:

Servo Jitter or Unstable Movement

  • Cause: Insufficient power. The servo draws current spikes that can brown out the ESP32.
  • Fix: Use a separate 5V regulator for the servo. Add a 470µF capacitor across the servo power lines.

Servo Not Moving to Full Range

  • Cause: The servo’s physical limits are constrained by the linkage.
  • Fix: Adjust the linkage length or use the writeMicroseconds() function to fine-tune pulse widths. For example, some servos respond to 500-2500µs instead of 1000-2000µs.

Car Pulls to One Side

  • Cause: The servo center (90 degrees) does not align with mechanical straight.
  • Fix: Recalibrate the servo horn position. Remove the horn, set the servo to 90 degrees, then reattach the horn with wheels straight.

Wi-Fi Disconnects During Servo Movement

  • Cause: Voltage drops cause the ESP32 to reset.
  • Fix: Add a large capacitor (1000µF) across the battery input. Ensure all ground connections are solid.

Step 6: Optimizing the Web Interface for Real-Time Control

The basic HTML interface works but has latency because each button press sends an HTTP request. For smoother control, consider WebSockets.

WebSocket Implementation

WebSockets allow bidirectional, low-latency communication. The ESP32 can send servo angle updates and receive commands instantly.

cpp

include <WebSocketsServer.h>

WebSocketsServer webSocket = WebSocketsServer(81);

void webSocketEvent(uint8t num, WStypet type, uint8t * payload, sizet length){ if(type == WStype_TEXT){ String msg = (char*)payload; if(msg.startsWith("steer:")){ int angle = msg.substring(6).toInt(); steeringServo.write(angle); } // Handle other commands } }

On the client side, use JavaScript WebSocket to send joystick data. This gives you near-zero delay, making the micro servo motor feel responsive and precise.

Step 7: Power Management for Micro Servo and Motors

The micro servo motor is efficient, but the drive motors are power-hungry. Here’s how to manage your battery:

  • Use a 2S LiPo (7.4V): Provides enough voltage for the L298N and servo regulator.
  • Separate battery for servo: If the servo causes instability, power it from a dedicated 5V battery pack (e.g., 2x 18650 cells with a regulator).
  • Low voltage cutoff: Add a buzzer or LED to warn when battery voltage drops below 6V. The servo may behave erratically at low voltage.

Calculating Run Time

A typical micro servo draws 150-200mA when moving and about 10mA when idle. Two DC motors at full speed might draw 500mA each. Total average current: ~1.2A. A 2000mAh battery gives about 1.5 hours of driving, less if you’re constantly steering.

Step 8: Enclosures and Aesthetics

The micro servo motor is small enough to hide inside a 3D-printed body. Design a chassis that protects the electronics and allows the servo horn to poke through. Consider these design tips:

  • Servo mounting: Use M2 screws and nylon standoffs to isolate vibration.
  • Waterproofing: Add a plastic cover over the servo to protect from dust.
  • LED indicators: Wire an LED to the servo’s power line to show when it’s active.

Step 9: Expanding to Multi-Car Control

If you want to control multiple Wi-Fi cars simultaneously, each ESP32 can run its own access point with a unique SSID. Alternatively, connect all cars to the same router and assign static IPs. The web interface can include a car selector.

For multi-car coordination, you can use UDP broadcasting to send steering commands to all cars at once. The micro servo motors in each car will respond independently, allowing synchronized movements.

Step 10: Real-World Testing and Calibration

Take your car to a parking lot or a large room. Test these scenarios:

  • Straight line: Does the car drift? Adjust servo trim.
  • Turning radius: At maximum servo angle, how sharp is the turn? If too sharp, reduce the max angle in code.
  • Response time: Is there noticeable lag between pressing a button and the servo moving? If yes, check Wi-Fi signal strength.

Pro tip: Use the servo’s ability to hold position. When you release the steering control, the servo stays at the last commanded angle. This is different from spring-return systems and requires you to explicitly send a “center” command when you want to go straight.

Final Code Structure

Here’s a skeleton of the full program:

cpp

include <WiFi.h>

include <WebServer.h>

include <ESP32Servo.h>

// Pin definitions

define IN1 26

define IN2 27

define IN3 14

define IN4 12

define ENA 13

define ENB 15

define SERVO_PIN 4

Servo steeringServo; WebServer server(80);

const char* ssid = "WiFi_Car"; const char* password = "12345678";

void setup() { Serial.begin(115200); WiFi.softAP(ssid, password);

// Motor pins pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); pinMode(ENA, OUTPUT); pinMode(ENB, OUTPUT);

// Servo steeringServo.attach(SERVO_PIN); steeringServo.write(90);

// Web server routes server.on("/", handleRoot); server.on("/forward", handleForward); server.on("/backward", handleBackward); server.on("/left", handleLeft); server.on("/right", handleRight); server.on("/stop", handleStop); server.on("/steer", handleSteer); server.on("/center", handleCenter);

server.begin(); }

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

// Implement handler functions...

The micro servo motor is the unsung hero of this project. It provides the precision and reliability needed for smooth steering, camera control, and beyond. While the drive motors get the car moving, the servo gives you the finesse to navigate tight spaces, follow curves, and even perform small robotic tasks. As you experiment, you’ll find that adding more servos opens up endless possibilities—from pan-tilt cameras to grippers and sensor sweeps. The Wi-Fi control layer makes it all accessible from anywhere in your home, turning a simple RC car into a connected robotic platform.

Copyright Statement:

Author: Micro Servo Motor

Link: https://microservomotor.com/building-remote-controlled-cars/rc-car-wifi-control.htm

Source: Micro Servo Motor

The copyright of this article belongs to the author. Reproduction is not allowed without permission.

About Us

Lucas Bennett avatar
Lucas Bennett
Welcome to my blog!

Tags