So I bought a two wheels chassis and wheels online, but unfortunately the package did not contain the spacers. I complained to the seller but I don't have so I thought I will make the spacer on my own using some pen or dot pen materials or find some other solutions for the spacers. Below is the three wheels parts that I have, NodeMCU module, battery holder and batteries, L298N motor driver module which are also required.
This is optional but if you want to build into the car a recharging system then you will also need the recharging circuit. I have opted to use LM317 adjustable voltage regulator. Below is shown LM317 lithium ion battery charger materials which includes, LM317 IC, 200Ohm resistor, 10KOhm potentiomter, three way switch, 0.1uF and 1uF capacitors, PCB power jack and pref-board.
Next comes the assembly. I first soldered the wires to the DC motors.
Then I assembled the wheels with the chassis.
Next I have to put power supply, NodeMCU module, onto the chassis. Shown below are some pictures taken during the assembling of the parts.
The lithium ion battery charger circuit in the above pictures was a DIY build. I don't know if this is working. My initial finding is that it seems working. In my four wheel Arduino Bluetooth car I bought and used lithium ion charger module. Here I relied on LM317 Lithium Ion Battery Charger for the robot car.
I have written a separate blog post on how I made this LM317 Lithium Ion Battery Charger For Robot Car which contains the circuit diagram for the LM317 lithium ion batteries charger.
I have recorded video of the whole assembling work of the WiFi robot car.
Two wheels WiFi control Arduino Car Circuit Schematic
I have drawn the following NodeMCU WiFi controlled car circuit schematic using the Proteus Professional electronics design software. For me this software has become my favorite because it is very easy to use and has lots of features. Some of the components shown in the circuit diagram are not available and I simply made those parts.
Three wheels WiFi control Arduino Car Program
Next we have to write program for the NodeMCU that connects and transfer data from NodeMCU via WiFi. The following the WiFi controllable Arduino car program code that I used.
#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);
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);
digitalWrite(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 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);
}
The above code is for controlling a robotic car using an ESP8266-based NodeMCU board. It sets up NodeMCU(ESP8266) WiFi web server that listens for commands sent by a web client (e.g., a mobile app or web browser) to control the movement of the robotic car. Here's a breakdown of the code:
The code defines several constants to specify the GPIO pins connected to various components of the robotic car, including motors and motor drivers:
ENA
: This is the GPIO pin connected to the enable/speed control of the right motors.ENB
: This is the GPIO pin connected to the enable/speed control of the left motors.IN_1
,IN_2
,IN_3
,IN_4
: These are GPIO pins connected to various input pins of an L298N motor driver module. These pins are used to control the direction of the motors.
The code includes necessary libraries for Wi-Fi and web server functionality:
ESP8266WiFi.h
: Library for connecting to Wi-Fi networks with the ESP8266.WiFiClient.h
: Library for handling client connections over Wi-Fi.ESP8266WebServer.h
: Library for creating a web server on the ESP8266.
command
: A string variable used to store the received command from the web client.speedCar
: An integer variable representing the speed of the car's motors (ranging from 400 to 1023).speed_Coeff
: An integer variable representing a speed coefficient used for adjusting the speed of one motor relative to the other.
The setup function initializes the GPIO pins as outputs and sets up Wi-Fi in Access Point (AP) mode with the SSID "NodeMCU Car." It also starts the web server on port 80.
There are several functions defined for different movements of the car, such as going forward, backward, turning left or right, and combinations of these movements.
The main loop function constantly checks for incoming client requests using server.handleClient()
. It reads the "State" parameter from the HTTP request to determine the desired action. Depending on the received command, it calls the corresponding movement function or adjusts the speed of the motors.
- The commands "F," "B," "L," "R," "I," "G," "J," and "H" correspond to forward, backward, left, right, forward-right, forward-left, backward-right, and backward-left movements, respectively.
- The commands "0" to "9" represent different speed levels for the motors.
- The command "S" stops the robot.
This function is called when the root URL ("/") is accessed. It checks if the "State" parameter is present in the HTTP request and prints its value to the serial monitor. It then sends a response with an empty HTML body.
In summary, this code turns the ESP8266 into a web server that listens for commands to control the movements and speed of a robotic car using a web interface. It provides a straightforward way to control the car's actions remotely via a web browser or a mobile app.
NOTE:
Just a rectification...
Using 4.8 v could damage your node mcu as it works on 3.3v but you connect same 5v to data cable points as it already has protection on board
thank you