Building a Wi-Fi Controlled Car: A Step-by-Step Guide



Introduction:

A Wi-Fi-controlled car is an exciting and educational DIY project for tech enthusiasts. It allows you to control a small vehicle remotely using a Wi-Fi connection. In this article, we’ll guide you through building your own Wi-Fi-controlled car using simple components like the ESP8266 Wi-Fi module, L298N motor driver, and BO motors.

This project will cover the necessary materials, assembly steps, and coding required to bring your car to life.


Components Required:

Here is a list of components you’ll need for this project:

  • Chassis: The framework to hold all the components.
  • 4 BO Motors: These motors will drive the car's wheels.
  • 4 Wheels: Attached to the motors for movement.
  • 12V Battery with BMS: Powers the motors and electronics safely.
  • ESP8266 Wi-Fi Module: Enables wireless control via Wi-Fi.
  • L298N Motor Driver Module: Controls the motors’ direction and speed.
  • Jumper Wires: For connecting components.

Step 1: Assemble the Chassis and Motors

  1. Attach the four BO motors to the chassis.
  2. Securely connect the wheels to the motors for smooth movement.

Step 2: Wiring the Motors to the L298N Motor Driver

  1. Connect the motor driver’s output pins (OUT1, OUT2, OUT3, OUT4) to the motors:
    • OUT1 and OUT2 to the left-side motors.
    • OUT3 and OUT4 to the right-side motors.
  2. Connect the 12V battery to the motor driver’s power terminals.
  3. Link the motor driver’s Enable pins to the ESP8266's digital pins for speed control.


Step 3: Connecting the ESP8266 to the Motor Driver

  1. Connect the L298N’s input pins (IN1, IN2, IN3, IN4) to the ESP8266’s GPIO pins.
  2. Ensure a common ground connection between the ESP8266 and the L298N motor driver.


Step 4: Powering the System

  • The 12V battery powers the motors via the L298N motor driver.
  • The ESP8266 can be powered via the L298N’s 5V regulator or a separate 3.3V power source.

Circuit Diagram


Step 5: Programming the ESP8266

You’ll need to program the ESP8266 to control the car via Wi-Fi. Here’s a quick overview:

1. Set up the Arduino IDE:
Install the ESP8266 library in Arduino IDE.
Connect the ESP8266 module to your computer for coding.

2. Write the Control Code: The code below sets up a basic web server to control the car's movements:


//**********//program By Sakshyam Bastakoti /**********//

#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;         // 400 - 1023.
int speed_Coeff = 3;

const char* ssid = "NodeMCU Car";
ESP8266WebServer server(80);
lWrite(IN_3, HIGH);
      digitalWrite(IN_4, LOW);
      analogWrite(ENB, speedCar/speed_Coeff);
  }

void stopRobot(){  

      digitalWrite(IN_1, LOW);
      digitalWrite(IN_2, LOW);
      analogWrite(ENA, speedCar);

      digitalWrite(IN_3, LOW);
      digitalWrite(IN_4, LOW);
      analogWrite(ENB, speedCar);
 }
void setup() {
 
 pinMode(ENA, OUTPUT);
 pinMode(ENB, OUTPUT);  
 pinMode(IN_1, OUTPUT);
 pinMode(IN_2, OUTPUT);
 pinMode(IN_3, OUTPUT);
 pinMode(IN_4, OUTPUT); 
  
  Serial.begin(115200);
  
// Connecting WiFi

  WiFi.mode(WIFI_AP);
  WiFi.softAP(ssid);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
 
 // Starting WEB-server 
     server.on ( "/", HTTP_handleRoot );
     server.onNotFound ( HTTP_handleRoot );
     server.begin();    
}

void goAhead(){ 

      digitalWrite(IN_1, LOW);
      digitalWrite(IN_2, HIGH);
      analogWrite(ENA, speedCar);

      digitalWrite(IN_3, LOW);
      digitalWrite(IN_4, HIGH);
      analogWrite(ENB, speedCar);
  }

void goBack(){ 

      digitalWrite(IN_1, HIGH);
      digitalWrite(IN_2, LOW);
      analogWrite(ENA, speedCar);

      digitalWrite(IN_3, HIGH);
      digitalWrite(IN_4, LOW);
      analogWrite(ENB, speedCar);
  }

void goRight(){ 

      digitalWrite(IN_1, HIGH);
      digitalWrite(IN_2, LOW);
      analogWrite(ENA, speedCar);

      digitalWrite(IN_3, LOW);
      digitalWrite(IN_4, HIGH);
      analogWrite(ENB, speedCar);
  }

void goLeft(){

      digitalWrite(IN_1, LOW);
      digitalWrite(IN_2, HIGH);
      analogWrite(ENA, speedCar);

      digitalWrite(IN_3, HIGH);
      digitalWrite(IN_4, LOW);
      analogWrite(ENB, speedCar);
  }

void goAheadRight(){
      
      digitalWrite(IN_1, LOW);
      digitalWrite(IN_2, HIGH);
      analogWrite(ENA, speedCar/speed_Coeff);
 
      digitalWrite(IN_3, LOW);
      digitalWrite(IN_4, HIGH);
      analogWrite(ENB, speedCar);
   }

void goAheadLeft(){
      
      digitalWrite(IN_1, LOW);
      digitalWrite(IN_2, HIGH);
      analogWrite(ENA, speedCar);

      digitalWrite(IN_3, LOW);
      digitalWrite(IN_4, HIGH);
      analogWrite(ENB, speedCar/speed_Coeff);
  }

void goBackRight(){ 

      digitalWrite(IN_1, HIGH);
      digitalWrite(IN_2, LOW);
      analogWrite(ENA, speedCar/speed_Coeff);

      digitalWrite(IN_3, HIGH);
      digitalWrite(IN_4, LOW);
      analogWrite(ENB, speedCar);
  }

void goBackLeft(){ 

      digitalWrite(IN_1, HIGH);
      digitalWrite(IN_2, LOW);
      analogWrite(ENA, speedCar);

      digita
void loop() {
    server.handleClient();
    
      command = server.arg("State");
      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();
      else if (command == "0") speedCar = 400;
      else if (command == "1") speedCar = 470;
      else if (command == "2") speedCar = 540;
      else if (command == "3") speedCar = 610;
      else if (command == "4") speedCar = 680;
      else if (command == "5") speedCar = 750;
      else if (command == "6") speedCar = 820;
      else if (command == "7") speedCar = 890;
      else if (command == "8") speedCar = 960;
      else if (command == "9") speedCar = 1023;
      else if (command == "S") stopRobot();
}

void HTTP_handleRoot(void) {

if( server.hasArg("State") ){
       Serial.println(server.arg("State"));
  }
  server. send ( 200, "text/html", "" );
  delay(1);
}


//**********//program By Sakshyam Bastakoti /**********//


Step 6: Testing and Controlling the Car

  1. Once the code is uploaded, connect your smartphone or laptop to the Wi-Fi network created by the ESP8266.
  2. Open the app given below and enter the IP address of the ESP8266.
  3. You can now control the car by navigating buttons such as /FORWARD, /BACKWARD, /LEFT, and /RIGHT.





   Android  Application Download Link :




Conclusion:

Building a Wi-Fi-controlled car is an excellent way to explore the world of wireless communication, motor control, and IoT. Once you’ve completed the basic setup, you can further enhance the project by adding features such as speed control, obstacle detection, or even a camera for remote video streaming.

It’s a fun and educational project that bridges mechanics, electronics, and programming into a single build. Enjoy your creation!.

Previous Post Next Post