Overview: WiFi Controlled Robot
This tutorial will show you how to build an Internet or WiFi Controlled robot using NodeMCU ESP8266 Board. There are many types of Robots or Robotic Car from simple ones like Toys to advanced ones like industrial Robotic Arms.
This WiFi Controlled Robot is made using Wemos D1 Chip as a control unit. To control the pair of Motors, we used L298n Motor Driver IC Module. We can power on the circuit using any battery as the power requirement is more than 5V. The Robot can be controlled using an Android App which is designed using an MIT APP Inventor Software.
We have already covered many types of Robots in earlier projects using different technologies, have a look at them:
1. Bluetooth Controlled Robot
2. Gesture Controlled Robot
3. Voice Controlled Robot
Bill of Materials
Here are the list of components that you need for making this Robotic Car Project. You can purchase all the components from Amazon link.
| S.N. | Components Name | Quantity | Purchase Links |
|---|---|---|---|
| 1 | NodeMCU ESP8266-12E Board or Wemos D1 Mini | 1 | Amazon | AliExpress |
| 2 | L298n Motor Driver IC Module | 1 | Amazon | AliExpress |
| 3 | Robot Chasis Kit | 1 | Amazon | AliExpress |
| 4 | 3.7V Samsung 18650 Battery | 2 | Amazon | AliExpress |
| 5 | Jumper Wires | 20 | Amazon | AliExpress |
| 6 | Breadboard | 1 | Amazon | AliExpress |
| 7 | USB Cable | 1 | Amazon | AliExpress |
Circuit Diagram & Hardware
Here is the schematic for this WiFi Controlled Robot Project designed using Fritzing software. We will control the two DC motors via L298 Motor Driver IC. You can use 200-300 RPM DC Motor for this application. The main control unit is Wemos D1 Board which connects and controls the entire circuit and equipment. And to power the circuit we will use a 6V DC Battery or a pair of Lithium-Ion batteries connected in series.
Connect the battery to the L298 Motor Driver power supply input. Connect all 4 inputs of L298 to ESP8266 D3, D4, D7 & D8 Pin. Supply 5V to Wemos through L298 5V Pin. Connect the output pins of L298 to left and right motors.
Assemble the robotic car with base and chassis. I used a pair of 3.7V Samsung 18650 Batteries to power the circuit. The batteries are connected in series and hence overall voltage is around 8V. I have used the transparent chassis made using glass fiber. You can use metallic or wooden anything that fulfills your requirement. Tightly screw all the components and mount them on the chassis. Use good quality and strong wheels so that the robot can move even on rough surfaces.
The Android App Design
Now we need to design an Android Application for ESP8266 WiFi Controlled Robot. The easiest way to design an Android Application is using MIT App Inventor. The MIT APP Inventor lets you develop applications for Android phones using a web browser and either the connected phone or emulator. The App Inventor servers store your work and help you keep track of your projects.
I have simply designed an Interface for this Robotic Project. The App has 5 pairs of Switch to Send the 0 and 1 command to Web Server.
Similarly the block editor which contains assignment and programming information is given below.
Build/Compile the Application and export it to your Android Phone. You can install the APK file on your phone.
Source Code/Program
The source code/program for WiFi Controlled Robot Robot is very simple and you can program the Wemos D1 Board using Arduino IDE.
In this code part, change the WiFi SSID & Password from these lines.
|
1 2 |
const char* ssid = "Azephyrad"; const char* password = "@guinevere@@@"; |
Copy the complete code from below and get your ESP8266 Board for programming.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
/* 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 micro-USB Data cable between the computer and the Wemos D1 Mini Board.
On the Arduino IDE, select Tools, and from the Board Part select Wemos D1 Mini Board. In case if you are using NodeMCU Board, you can select NodeMCU 1.0 Board. Then select the COM Port & hit the upload button to upload the code.
Testing the WiFi Controlled Robot
After uploading the code click on the serial monitor. So, the Serial Monitor will display the IP Address once it connects to the WiFi Network. Note this IP Address as it is required in the Android App.
Open the Android App installed on your phone and enter the IP Address that you noted earlier.
Now you can control the Robot. To move the Robot in the forward direction, press the UP arrow key, and to move it backward, press the DOWN arrow key. Similarly, to move the Robot left and Right press the Left and Right arrow keys.
This is how you can make your own WiFi Controlled Robot and control the Robot using the Android Application.













1 Comment
Nice project. Error1101: Unable to get response with specified UR: http://192.168.0.106/%5Bcommand%5D such error I get from all the buttons. Kindly through some light.