IOT

WiFi Controlled Robot using ESP8266 & Android App

This guide will show you how to use the NodeMCU ESP8266 Board to make an Internet or WiFi-controlled robot. There are numerous different forms of robots or robotic cars, ranging from small toys to powerful industrial robotic arms.

The control unit for this WiFi Controlled Robot is a Wemos D1 Chip. We used the L298n Motor Driver IC Module to control the two motors. Since this circuit requires more than 5V, any battery can be used to power it. The robot may be controlled with an Android app created with the MIT APP Inventor software.

Hardware Required:

  • NodeMCU ESP8266-12E Board ow Wemos D1 Mini
  • L298n H-Bridge Motor Driver IC
  • 12V DC Motors-300 RPM
  • Robot Chasis
  • Robot Wheels
  • 3.7V Samsung 18650 Battery
  • Male/Female Jumper Wires
  • 830 Points Breadboard
  • Micro-USB Data Cable

Circuit Diagram & Hardware

The Fritzing program was used to create the schematic for this WiFi Controlled Robot Project. The two DC motors will be controlled by the L298 Motor Driver IC. For this project, a 200-300 RPM DC motor can be used. Wemos D1 Board is the main control device, which links and regulates the complete circuit and equipment. A 6V DC battery or a pair of Lithium-Ion batteries connected in series will be used to power the circuit.

Connect the battery to the power supply input of the L298 Motor Driver. Connect all four L298 inputs to the ESP8266 D3, D4, D7, and D8 pins. Through the L298 5V Pin, provide 5V to the Wemos. Connect the left and right motors to the L298 output pins.

Assemble the base and chassis of the robotic car. The circuit was powered by a pair of 3.7V Samsung 18650 batteries. Since the batteries are wired in series, the overall voltage is roughly 8 volts. I used a transparent glass fiber chassis for this project. You can utilize anything metallic or wooden that meets your needs. All of the components should be tightly screwed together and mounted on the chassis. Make sure the robot’s wheels are of good quality and can withstand difficult terrain.

Project PCB Gerber File & PCB Ordering Online

If you don’t want to assemble the project with jumper wires and instead prefer a PCB, here is the PCB for you. EasyEDA was used to create the PCB. The PCB Board for the Robotic Car looks like this.

Below is the Gerber File for the PCB. You can order the PCB by downloading the Gerber File from https://www.nextpcb.com/

Download Gerber File: WiFi Controlled Car PCB

You can now visit the official NextPCB website by going to https://www.nextpcb.com/.  As a result, you’ll be taken to the NextPCB website.

  • You can now upload the Gerber File and place an order on the website. The PCB quality is excellent. That is why the majority of people entrust NextPCB with their PCB and PCBA needs.
  • The components can be assembled on the PCB Board.

The Android App Design

For the ESP8266 WiFi Controlled Robot, we now need to create an Android application. MIT App Inventor is the simplest way to create an Android application. The MIT APP Inventor allows you to create Android apps using a web browser and either the actual phone or an emulator. The App Inventor servers maintain track of your projects and store your work.

For this Robotic Project, I just designed an Interface. The app features 5 switch pairs for sending 0 and 1 commands to the webserver.

Similarly, the block editor is seen below, which contains assignment and programming information.

  • Create the application and then export it to your Android device. The APK file can be installed on your phone.

Download: WiFi Controlled Robot APK File

Source Code/Program

The WiFi Controlled Robot Robot source code/software is quite simple, and you can program the Wemos D1 board using the Arduino IDE.

Change the WiFi SSID and Password from these lines in this code section.

const char* ssid = “Azephyrad”;const char* password = “@guinevere@@@”;

Get your ESP8266 Board for programming and copy the whole code from below.

/* include library */
#include <ESP8266WiFi.h>

/* define port */
WiFiClient client;
WiFiServer server(80);

/* WIFI settings */
const char* ssid = “Azephyrad”;
const char* password = “@guinevere@@@”;

/* data received from application */
String data = “”;

/* define L298N or L293D motor control pins */
int leftMotorForward = 2; /* GPIO2(D4) -> IN3 */
int rightMotorForward = 15; /* GPIO15(D8) -> IN1 */
int leftMotorBackward = 0; /* GPIO0(D3) -> IN4 */
int rightMotorBackward = 13; /* GPIO13(D7) -> IN2 */


void setup()
{
Serial.begin(115200);
/* initialize motor control pins as output */
pinMode(leftMotorForward, OUTPUT);
pinMode(rightMotorForward, OUTPUT);
pinMode(leftMotorBackward, OUTPUT);
pinMode(rightMotorBackward, OUTPUT);

//connect to your local wi-fi network
WiFi.begin(ssid, password);

// Attempt to connect to WiFi network:
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(“.”);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
// Wait 3 seconds for connection:
delay(3000);
}

Serial.println(“”);
Serial.println(“WiFi connected”);
Serial.println(“IP address: “);
Serial.println(WiFi.localIP()); //You can get IP address assigned to ESP

/* start server communication */
server.begin();
}

void loop()
{
/* If the server available, run the “checkClient” function */
client = server.available();
if (!client) return;
data = checkClient ();

/************************ Run function according to incoming data from application *************************/

/* If the incoming data is “forward”, run the “MotorForward” function */
if (data == “forward”) MotorForward();
/* If the incoming data is “backward”, run the “MotorBackward” function */
else if (data == “backward”) MotorBackward();
/* If the incoming data is “left”, run the “TurnLeft” function */
else if (data == “left”) TurnLeft();
/* If the incoming data is “right”, run the “TurnRight” function */
else if (data == “right”) TurnRight();
/* If the incoming data is “stop”, run the “MotorStop” function */
else if (data == “stop”) MotorStop();
}

/********************************************* FORWARD *****************************************************/
void MotorForward(void)
{
digitalWrite(leftMotorForward, HIGH);
digitalWrite(rightMotorForward, HIGH);
digitalWrite(leftMotorBackward, LOW);
digitalWrite(rightMotorBackward, LOW);
}

/********************************************* BACKWARD *****************************************************/
void MotorBackward(void)
{
digitalWrite(leftMotorBackward, HIGH);
digitalWrite(rightMotorBackward, HIGH);
digitalWrite(leftMotorForward, LOW);
digitalWrite(rightMotorForward, LOW);
}

/********************************************* TURN LEFT *****************************************************/
void TurnLeft(void)
{
digitalWrite(leftMotorForward, LOW);
digitalWrite(rightMotorForward, HIGH);
digitalWrite(rightMotorBackward, LOW);
digitalWrite(leftMotorBackward, HIGH);
}

/********************************************* TURN RIGHT *****************************************************/
void TurnRight(void)
{
digitalWrite(leftMotorForward, HIGH);
digitalWrite(rightMotorForward, LOW);
digitalWrite(rightMotorBackward, HIGH);
digitalWrite(leftMotorBackward, LOW);
}

/********************************************* STOP *****************************************************/
void MotorStop(void)
{
digitalWrite(leftMotorForward, LOW);
digitalWrite(leftMotorBackward, LOW);
digitalWrite(rightMotorForward, LOW);
digitalWrite(rightMotorBackward, LOW);
}

/********************************** RECEIVE DATA FROM the APP ******************************************/
String checkClient (void)
{
while (!client.available()) delay(1);
String request = client.readStringUntil(‘\r’);
request.remove(0, 5);
request.remove(request.length() – 9, 9);
return request;
}

Connect the computer to the Wemos D1 Mini Board using the micro-USB Data cable.

Select Tools in the Arduino IDE, and from the Board Part select Wemos D1 Mini Board.  You can choose NodeMCU 1.0 Board if you’re using NodeMCU Board. Then, to upload the code, choose the COM Port and press the upload button.

Testing the WiFi Controlled Robot

Click the serial monitor after uploading the code. As a result, once the Serial Monitor connects to the WiFi Network, it will display the IP Address. This IP Address is important because it is required by the Android App.

  • Open the Android App on your phone and type in the IP Address you wrote down previously.
  • You can now command the Robot. Press the UP arrow key to move the Robot ahead, and the DOWN arrow key to move it backward. Similarly, use the Left and Right arrow keys to move the robot left and right.

Conclusion:

I hope all of you understand how to design a WiFi Controlled Robot and control the Robot using the Android Application. We MATHA ELECTRONICS will be back soon with more informative blogs soon.

Leave a Reply

Your email address will not be published.