In this tutorial, we are going to make a Wi-Fi-controlled car using the esp32 module and control it with a smartphone. We will send Car control commands from mobile app using web application over the wi-fi connection and We will control the motors using simple L298N driver module so we can control the motor speed as well as direction of both motor
I have explained in details each step along with code, and you will make own wifi control car at home very easily
Abstract
Wi-fi is controlled by using a Web application instead of the button method. Here only needs to move the button in the Web application to control the car in forward, backward, left, and right directions. So here the Web application is used as a transmitting device, and an integrated wi-fi module placed in the car is used as a receiver. A web application will transmit commands using wi-fi to the car so that it can move in the required direction, like moving forward, reverse, turning left, turning right, and stopping.
Introduction
Robot development starts with some basic ideas. It requires minimal human effort and can be used in many areas, such as military, surveillance applications, and industrial pick-and-place robots. In the modern world, modern humanoid robots are being developed. Robot cars are currently being developed using wireless technology Wireless technologies in robotics start with Bluetooth, WI-FI, and Zigbee communications. Based on our requirements and requests, they provided communication on the project. There are also many Android apps. However, we will only use the web application that we will be using in this project. It has a lot of features, such as buttons, indicators, sliders, plotting functions, etc. By using Wi-Fi technology, more robot cars can be connected and controlled, which is very useful for surveillance applications. In this case, indoor localization techniques are currently being developed to enable the deployment of this type of Wi-Fi-controlled robotic car.
Existing system
Nowadays, with the advancement of technology, various newly designed smart Wi-Fi robots are applied in various applications. WiFi networks were primarily used for home security purposes. Various applications are performed by the robot car. Other work on commands. B. Turn on the light when the robot receives a command from a Wi-Fi enabled device.
Proposed system
The car was controlled over a Wi-Fi network using a web application. The Wi-Fi robot car can be easily moved from one place to another using web application commands. WiFi network technology can be used to make your car perform a variety of tasks.
Hardware requirement
- Nodemcu esp32 controller
- 12v DC Motors (4 motor)
- Motor Driver L293D
- 12 Volt 2 Amp Battery
- Male to female Jumper wires
- ON / OFF switch
- 4 Wheels
- USB cable
- Laptop for coding
Block digaram
wifi_controlled_robot_car_using_esp32
Block diagram explanation
The car was controlled over a Wi-Fi network with a web application.
The Wi-Fi robot car can be easily moved from one place to another with the commands of the web application.
Using Wi-Fi network technology, you can make your car perform various tasks.
L298n motor
wifi_controlled_robot_car_using_esp32
Esp32 module pin diagram
Circuit diagram
wifi_controlled_robot_car_using_esp32
Software requirement
- Arduino IDE
- Web application
Code here
You can copy the code.
#include
#ifdef ESP32
#include
#include
#elif defined(ESP8266)
#include
#include
#endif
#include
#include
#include
struct MOTOR_PINS
{
int pinEn;
int pinIN1;
int pinIN2;
};
std::vector motorPins =
{
{22, 16, 17}, //RIGHT_MOTOR Pins (EnA, IN1, IN2)
{23, 18, 19}, //LEFT_MOTOR Pins (EnB, IN3, IN4)
};
#define UP 1
#define DOWN 2
#define LEFT 3
#define RIGHT 4
#define STOP 0
#define RIGHT_MOTOR 0
#define LEFT_MOTOR 1
#define FORWARD 1
#define BACKWARD -1
const int PWMFreq = 1000; /* 1 KHz */
const int PWMResolution = 8;
const int PWMSpeedChannel = 4;
const char* ssid = "MyWiFiRoBoT";
const char* password = "12345678";
AsyncWebServer server(80);
AsyncWebSocket wsCarInput("/CarInput");
const char* htmlHomePage PROGMEM = R"HTMLHOMEPAGE(
SUPOTRONIX INDIA
WiFi Robot Control
⇧
⇦
⇨
⇩
Speed:
)HTMLHOMEPAGE";
void rotateMotor(int motorNumber, int motorDirection)
{
if (motorDirection == FORWARD)
{
digitalWrite(motorPins[motorNumber].pinIN1, HIGH);
digitalWrite(motorPins[motorNumber].pinIN2, LOW);
}
else if (motorDirection == BACKWARD)
{
digitalWrite(motorPins[motorNumber].pinIN1, LOW);
digitalWrite(motorPins[motorNumber].pinIN2, HIGH);
}
else
{
digitalWrite(motorPins[motorNumber].pinIN1, LOW);
digitalWrite(motorPins[motorNumber].pinIN2, LOW);
}
}
void moveCar(int inputValue)
{
Serial.printf("Got value as %d\n", inputValue);
switch(inputValue)
{
case UP:
rotateMotor(RIGHT_MOTOR, FORWARD);
rotateMotor(LEFT_MOTOR, FORWARD);
break;
case DOWN:
rotateMotor(RIGHT_MOTOR, BACKWARD);
rotateMotor(LEFT_MOTOR, BACKWARD);
break;
case LEFT:
rotateMotor(RIGHT_MOTOR, FORWARD);
rotateMotor(LEFT_MOTOR, BACKWARD);
break;
case RIGHT:
rotateMotor(RIGHT_MOTOR, BACKWARD);
rotateMotor(LEFT_MOTOR, FORWARD);
break;
case STOP:
rotateMotor(RIGHT_MOTOR, STOP);
rotateMotor(LEFT_MOTOR, STOP);
break;
default:
rotateMotor(RIGHT_MOTOR, STOP);
rotateMotor(LEFT_MOTOR, STOP);
break;
}
}
void handleRoot(AsyncWebServerRequest *request)
{
request->send_P(200, "text/html", htmlHomePage);
}
void handleNotFound(AsyncWebServerRequest *request)
{
request->send(404, "text/plain", "File Not Found");
}
void onCarInputWebSocketEvent(AsyncWebSocket *server,
AsyncWebSocketClient *client,
AwsEventType type,
void *arg,
uint8_t *data,
size_t len)
{
switch (type)
{
case WS_EVT_CONNECT:
Serial.printf("WebSocket client #%u connected from %s\n", client->id(), client->remoteIP().toString().c_str());
break;
case WS_EVT_DISCONNECT:
Serial.printf("WebSocket client #%u disconnected\n", client->id());
moveCar(STOP);
break;
case WS_EVT_DATA:
AwsFrameInfo *info;
info = (AwsFrameInfo*)arg;
if (info->final && info->index == 0 && info->len == len && info->opcode == WS_TEXT)
{
std::string myData = "";
myData.assign((char *)data, len);
std::istringstream ss(myData);
std::string key, value;
std::getline(ss, key, ',');
std::getline(ss, value, ',');
Serial.printf("Key [%s] Value[%s]\n", key.c_str(), value.c_str());
int valueInt = atoi(value.c_str());
if (key == "MoveCar")
{
moveCar(valueInt);
}
else if (key == "Speed")
{
ledcWrite(PWMSpeedChannel, valueInt);
}
}
break;
case WS_EVT_PONG:
case WS_EVT_ERROR:
break;
default:
break;
}
}
void setUpPinModes()
{
//Set up PWM
ledcSetup(PWMSpeedChannel, PWMFreq, PWMResolution);
for (int i = 0; i < motorPins.size(); i++)
{
pinMode(motorPins[i].pinEn, OUTPUT);
pinMode(motorPins[i].pinIN1, OUTPUT);
pinMode(motorPins[i].pinIN2, OUTPUT);
/* Attach the PWM Channel to the motor enb Pin */
ledcAttachPin(motorPins[i].pinEn, PWMSpeedChannel);
}
moveCar(STOP);
}
void setup(void)
{
setUpPinModes();
Serial.begin(115200);
WiFi.softAP(ssid, password);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
server.on("/", HTTP_GET, handleRoot);
server.onNotFound(handleNotFound);
wsCarInput.onEvent(onCarInputWebSocketEvent);
server.addHandler(&wsCarInput);
server.begin();
Serial.println("HTTP server started");
}
void loop()
{
wsCarInput.cleanupClients();
}
Follow our steps
Step 1: Take all the necessary components.
Step 2: Make the connection according to the circuit diagram.
Step 3: Now our software part: open Arduino IDE and paste the code in this tool before you copying.
Step 4: Then take an esp32 board and connect the board with the help of using usb cable.
Step 5: Now click the upload button and your code is uploading
Step 6: Now take a smart phone and connect wifi.
Step 7: The WiFi car name is "MyWiFiCar" showing in your smart phone.
Step 8: The Password is 12345678
Step 9: Open the chrome and click the search button enter the IP address 192.168.4.1
Step 10: Now click the enter button, and now your car is successfully connected. Control your car.
Conclusion
In the operating system of the smart mobile phone in Android, we develop a remote control program. The program connected with wi-fi to communicate with the robot. Wireless control is the most important basic need for all people. Wireless network-controlled robots use wi-fi modules. The Arduino Blue Control web application will transmit commands using wi-fi to the car so that it can move in the required direction, like moving forward, reverse, turning left, turning right, and stopping.
More Projects Similar to Esp32
learn arduino How can you fix the Error when you compile the code of ESP32 ?
0 Comments