Controlling a WIFI robot using an App in play store

Udara Kumarasena
4 min readJan 23, 2021

This is a simple way to make a WIFI robot controlled using a mobile application in play store.

Youtube Link — https://youtu.be/jb943yUxxLU

Needed components :-

Node MCU(ESP8266) -https://amzn.to/3s4BeB0
Robot Chasis -https://amzn.to/3bklnZg
Lipo Battery(7.4V) -https://amzn.to/35nK2YT
Motor Driver(L298) -https://amzn.to/3qavNPp
Buck Converter(DC to DC) -https://amzn.to/3q6QDyS
Jumper Wires -https://amzn.to/3saqml3
Bread Board -https://amzn.to/3s8vQwN
Lipo Battery Charger -https://amzn.to/3brjzOi

Make the circuit as shown in the diagram

The Code

#include <ESP8266WiFi.h>
WiFiClient client;
WiFiServer server(80);

const char* ssid = “Your SSID”;
const char* password = “Your Password”;

String data =””; //data obtained from app
int speed = 450; //initializing the speed

//Pins for the L298 motor driver
int leftMotorFront =D4;
int rightMotorFront = D8;
int leftMotorBack =D3;
int rightMotorBack = D7;

//Enable pins to the L298 driver
int rightMotorEnable = D5;
int leftMotorEnable = D6;

void setup()
{
//initializing output pins
pinMode(leftMotorFront, OUTPUT);
pinMode(rightMotorFront, OUTPUT);
pinMode(leftMotorBack, OUTPUT);
pinMode(rightMotorBack, OUTPUT);
pinMode(leftMotorEnable, OUTPUT);
pinMode(rightMotorEnable, OUTPUT);

//starts the server communication
Serial.begin(115200);
connectWiFi();
server.begin();
}

void loop()
{
client = server.available();
if (!client) return;
data = checkClientInfo (); //calling the checkclint Info function
Serial.println(data);

if (data.startsWith(“HIGH”)) { //checking whether the first few letters of the incomimg data is HIGH
speed = 1023;
String navi_command= data.substring(5, data.length());
Serial.println(navi_command);
if (navi_command == “forward”) MotorFront(); //If data is forward the MotorForward function is run
else if (navi_command == “back”) MotorBack(); //If data is back the MotorBackward function is run
else if (navi_command == “left”) MotorTurnLeft(); //If data is left the MotorTurnLeft function is run
else if (navi_command == “right”) MotorTurnRight(); //If data is right the MotorTurnRight function is run
else if (navi_command == “stop”) MotorStop(); //If data is stop the MotorStop function is run
}

else if (data.startsWith(“MEDIUM”)) { //checking whether the first few letters of the incomimg data is MEDIUM
speed = 680;
String navi_command1= data.substring(7, data.length());
Serial.println(navi_command1);
if (navi_command1 == “forward”) MotorFront();
else if (navi_command1 == “back”) MotorBack();
else if (navi_command1 == “left”) MotorTurnLeft();
else if (navi_command1 == “right”) MotorTurnRight();
else if (navi_command1 == “stop”) MotorStop();
}

else if (data.startsWith(“LOW”)) { //checking whether the first few letters of the incomimg data is LOW
speed = 540;
String navi_command2= data.substring(4, data.length());
Serial.println(navi_command2);
if (navi_command2 == “forward”) MotorFront();
else if (navi_command2 == “back”) MotorBack();
else if (navi_command2 == “left”) MotorTurnLeft();
else if (navi_command2 == “right”) MotorTurnRight();
else if (navi_command2 == “stop”) MotorStop();
}
}

//Function for the robot to move forward
void MotorFront(void)
{

digitalWrite(leftMotorFront,HIGH);
digitalWrite(rightMotorFront,HIGH);
digitalWrite(leftMotorBack,LOW);
digitalWrite(rightMotorBack,LOW);
analogWrite(leftMotorEnable,speed);
analogWrite(rightMotorEnable,speed);
}

//Function for the robot to move backward
void MotorBack(void)
{

digitalWrite(leftMotorBack,HIGH);
digitalWrite(rightMotorBack,HIGH);
digitalWrite(leftMotorFront,LOW);
digitalWrite(rightMotorFront,LOW);
analogWrite(leftMotorEnable,speed);
analogWrite(rightMotorEnable,speed);
}

//Function for the robot to turn left
void MotorTurnLeft(void)
{

digitalWrite(leftMotorFront,LOW);
digitalWrite(rightMotorFront,HIGH);
digitalWrite(rightMotorBack,LOW);
digitalWrite(leftMotorBack,HIGH);
analogWrite(leftMotorEnable,400);
analogWrite(rightMotorEnable,450);
}

//Function for the robot to turn right
void MotorTurnRight(void)
{

digitalWrite(leftMotorFront,HIGH);
digitalWrite(rightMotorFront,LOW);
digitalWrite(rightMotorBack,HIGH);
digitalWrite(leftMotorBack,LOW);
analogWrite(leftMotorEnable,450);
analogWrite(rightMotorEnable,400);
}

//Function for the robot to stop
void MotorStop(void)
{

digitalWrite(leftMotorFront,LOW);
digitalWrite(leftMotorBack,LOW);
digitalWrite(rightMotorFront,LOW);
digitalWrite(rightMotorBack,LOW);
analogWrite(leftMotorEnable,0);
analogWrite(rightMotorEnable,0);
}

//Function to read the signal sent from the app
String checkClientInfo (void)
{
while(!client.available()) delay(1);
String request = client.readStringUntil(‘\r’);
Serial.println(request);
request.remove(0, 5);
request.remove(request.length()-9,9);
Serial.println(request);
return request;
}

//function to generate the IP address
void connectWiFi()
{
Serial.println(“Connecting to WIFI”);
// WiFi.config(staticIP,subnet,gateway,dns); ////Uncomment this when you are making the IP static
WiFi.begin(ssid, password);
while ((!(WiFi.status() == WL_CONNECTED)))
{
delay(300);
Serial.print(“..”);
}
Serial.println(“”);
Serial.println(“WiFi connected”);
Serial.println(“NodeMCU Local IP is : “);
Serial.print((WiFi.localIP()));
}

Type the SSID and the password of your wifi network on the code. Now, the code is ready. Disconnect the power input pins of the node MCU. Connect the Node MCU to the PC using a USB to micro-USB data cable. Go to tools and select the board as Node MCU 0.9 and select the respective port as shown below.

Click the upload button. After uploading, go to the serial monitor and change the settings in the bottom right corner as shown below.

Then an IP address can be seen in the serial monitor. Record it. Remove the USB cable and connect the power input pins of the node MCU.

Now connect your smart phone to the same WIFI network that the node MCU is connected. Install the Navibot app from the link given below.

Open the app and enter the IP address that you recorded from the serial monitor. Now, you are done.

You can control the Robot using the app now.

Protonest for more details.

Protonest specializes in transforming IoT ideas into reality. We offer prototyping services from concept to completion. Our commitment ensures that your visionary IoT concepts become tangible, innovative, and advanced prototypes.

Our Website: https://www.protonest.co/

Email: kumarasenau@gmail.com

--

--

Udara Kumarasena

I am a Sri Lankan who is passionate about using technology for a sustainable future.