Description:
Wifi Robot Car- In today’s tutorial, you will learn how to control a robot car using Arduino, Nodemcu esp8266 wifi module and Blynk application. The joystick widget will be used to control the Forward…Reverse….right …and left movement..while the slider widget will be used to control the speed of the dc motors in real-time…As this project is based on WIFI, it means this robot car can be controlled from anywhere around the world. For remote controlling, an IP camera can be used for live video streaming. I will make a separate video on how to use the IP cameras.
This is the 5th version of the Robot Car.while in the 4th version I used an ultrasonic sensor to make a safe distance maintaining robot car “Click here “. in this project, the speed of the robot car is automatically adjusted depending on the distance between the cars.
While in the 3rd version “Click Here ” I used the flex sensor and the joystick together to control the same robot car, in this project the flex sensor was used as the accelerator and the joystick was used to control the car’s forward, left, right and reverse movement, I named this project a wireless hand gesture + joystick robot car… While in the 2nd version “Click Here” I used only the joystick to control the speed and movement of the robot Car. The program used in this project was a little bit complex, so that’s why I decided to make another version of this robot and use a separate sensor for the speed controlling. So that’s why I created version 3.
While in the first version”click here” I used an Android cell phone to control the Robot Car using the HC-05 Bluetooth module.
Today’s tutorial is based on my previous tutorial, in this tutorial, I explained, how to assemble the robot parts and how to use the L298N motor driver to control the forward, left, right and reverse movement. In this tutorial, I also explained how to control the speed of a dc motor using the pulse width modulation. If you are a beginner and you have never used the L298N motor driver then I highly recommend you should first watch this tutorial and then you can resume from here.
The components and tools used in this project can be purchased from Amazon, the components Purchase links are given below:
Arduino Uno: https://amzn.to/2YxCle6
Mega 2560: https://amzn.to/2ze1kdu
Robot Car chassis kit: https://amzn.to/2tTpkgo
L298N Dual H-Bridge motor driver: https://amzn.to/2XF4sam
Nodemcu esp8266 wifi module: Best price https://amzn.to/2NAvmiB
lm7805 Voltage Regulator: https://amzn.to/2IZEl5x
330-ohm resistors pack: https://amzn.to/2NtlAeh
5v 2A adaptor: https://amzn.to/2GsNfcw
2n2222 NPN transistors: https://amzn.to/2EmXsIb
10k Resistor: https://amzn.to/2KTd6OW
lm7805 Voltage Regulator: https://amzn.to/2IZEl5x
330-ohm resistors pack: https://amzn.to/2NtlAeh
female DC power jack socket: https://amzn.to/2KEo1gt
470 UF capacitors: https://amzn.to/2xDCOzf
5×7 cm Vero board: https://amzn.to/2OHGbvn
female headers: https://amzn.to/2zqmtiJ
connection wires: https://amzn.to/2DpBuW7
Super Starter kit for Beginners: https://amzn.to/2KJvmKG
Jumper Wires: https://amzn.to/2KMoVXs
Bread Board: https://amzn.to/2MS4q8X
12v Adaptor: https://amzn.to/2Ntr6h1
PCB plate: https://amzn.to/2IUwpCt
Variable Supply: https://amzn.to/2MT4Qfj
Digital Multimeter: https://amzn.to/2Nvft9i
Vero Board / stripboard: https://amzn.to/2MTf9jD
Soldering iron kit: “best” You guys should definitely purchase this: https://amzn.to/2zfoNuJ
Solder wire: https://amzn.to/2ufUMWf
Wire Stripper: https://amzn.to/2KOqxfU
wirecutter: https://amzn.to/2ucIq14
PCB small portable drill machine: https://amzn.to/2Nu62XF
*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!
Circuit Diagram:
All the connections are exactly the same as explained in the L298N motor driver getting started Tutorial. “Click Here”.The only modification is the addition of the Nodemcu esp8266 wifi module. The Nodemcu tx pin is connected with the Arduino’s pin number 2 and the Nodemcu Rx pin is connected with the Arduino’s pin number 3 while the Nodemcu ground pin is connected with the Arduino ground. For the demonstration purchases, I will power the Nodemcu module using my laptop.
Blynk Application:
For the Blynk Application designing watch video tutorial.
Programming:
This project is based on two programs, this program is written for the Arduino while this program is written for the Nodemcu ESP8266 wifi module. First, let’s start with the Arduino programming.
Arduino 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
#include <SoftwareSerial.h> SoftwareSerial nodemcu(2,3); long int data; int firstVal, secondVal,thirdVal; String myString; // complete message from arduino, which consistors of snesors data char rdata; // received charactors String cdata; // complete data // for L298N motor driver int ena = 5; int enb = 6; int in1 = 8; int in2 = 9; int in3 = 10; int in4 = 11; void setup() { Serial.begin(9600); nodemcu.begin(9600); pinMode(ena, OUTPUT); pinMode(enb, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); analogWrite(ena, 0); analogWrite(enb, 0); } void loop() { if(nodemcu.available() == 0 ) { delay(100); // 100 milli seconds } if ( nodemcu.available() > 0 ) { rdata = nodemcu.read(); myString = myString+ rdata; //Serial.print(rdata); if( rdata == '\n') { Serial.println(myString); // new code String l = getValue(myString, ',', 0); String m = getValue(myString, ',', 1); String n = getValue(myString, ',', 2); firstVal = l.toInt(); // for left and right secondVal = m.toInt(); // forward and reverse thirdVal = n.toInt(); // speed myString = ""; if ( (firstVal == 2) && (secondVal == 2) ) // for joystic normal position { analogWrite(ena,0); analogWrite(enb,0); digitalWrite(in1,LOW); digitalWrite(in2,LOW); digitalWrite(in3,LOW); digitalWrite(in3,LOW); } else if ( (firstVal == 2) && (secondVal > 3) ) // Forward direction { analogWrite(ena,thirdVal); analogWrite(enb,thirdVal); digitalWrite(in1,HIGH); digitalWrite(in2, LOW); digitalWrite(in3,LOW); digitalWrite(in4,HIGH); }else if ( (firstVal == 2) && (secondVal < 1) ) // reverse direction { analogWrite(ena,thirdVal); analogWrite(enb,thirdVal); digitalWrite(in1,LOW); digitalWrite(in2, HIGH); digitalWrite(in3,HIGH); digitalWrite(in4,LOW); }else if ( (firstVal > 3) && (secondVal == 2) ) // Right { analogWrite(ena,thirdVal); analogWrite(enb,thirdVal); digitalWrite(in1,HIGH); digitalWrite(in2, LOW); digitalWrite(in3,LOW); digitalWrite(in4,LOW); } else if ( (firstVal < 1) && (secondVal == 2) ) // left { analogWrite(ena,thirdVal); analogWrite(enb,thirdVal); digitalWrite(in1,LOW); digitalWrite(in2, LOW); digitalWrite(in3,LOW); digitalWrite(in4,HIGH); } } } } String getValue(String data, char separator, int index) { int found = 0; int strIndex[] = { 0, -1 }; int maxIndex = data.length() - 1; for (int i = 0; i <= maxIndex && found <= index; i++) { if (data.charAt(i) == separator || i == maxIndex) { found++; strIndex[0] = strIndex[1] + 1; strIndex[1] = (i == maxIndex) ? i+1 : i; } } return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; } |
Nodemcu esp8266 wifi module 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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
#define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> #include <SoftwareSerial.h> #include <SimpleTimer.h> int pinValue1; int pinValue2; int pinValue3; int pinValue4; String v2arduino; // values to arduino char auth[] = "dfb3d11fbe874cd69ab413c8bb45f613"; // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "ZONG MBB-E8231-6E63"; char pass[] = "08659650"; SimpleTimer timer; String myString; // complete message from arduino, which consistors of snesors data char rdata; // received charactors int firstVal, secondVal,thirdVal; // sensors // This function sends Arduino's up time every second to Virtual Pin (1). // In the app, Widget's reading frequency should be set to PUSH. This means // that you define how often to send data to Blynk App. void myTimerEvent() { // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V1, millis() / 1000); } void setup() { // Debug console Serial.begin(9600); Blynk.begin(auth, ssid, pass); timer.setInterval(1000L,sensorvalue1); timer.setInterval(1000L,sensorvalue2); timer.setInterval(1000L,sensorvalue3); } void loop() { if (Serial.available() == 0 ) { Blynk.run(); timer.run(); // Initiates BlynkTimer toarduino(); } if (Serial.available() > 0 ) { rdata = Serial.read(); myString = myString+ rdata; // Serial.print(rdata); if( rdata == '\n') { // new code String l = getValue(myString, ',', 0); String m = getValue(myString, ',', 1); String n = getValue(myString, ',', 2); firstVal = l.toInt(); secondVal = m.toInt(); thirdVal = n.toInt(); myString = ""; // end new code } } } void sensorvalue1() { int sdata = firstVal; // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V2, sdata); } void sensorvalue2() { int sdata = secondVal; // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V3, sdata); } void sensorvalue3() { int sdata = thirdVal; // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V4, sdata); } String getValue(String data, char separator, int index) { int found = 0; int strIndex[] = { 0, -1 }; int maxIndex = data.length() - 1; for (int i = 0; i <= maxIndex && found <= index; i++) { if (data.charAt(i) == separator || i == maxIndex) { found++; strIndex[0] = strIndex[1] + 1; strIndex[1] = (i == maxIndex) ? i+1 : i; } } return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; } // in Blynk app writes values to the Virtual Pin V3 BLYNK_WRITE(V10) { pinValue1 = param.asInt(); // assigning incoming value from pin V10 to a variable } // in Blynk app writes values to the Virtual Pin V4 BLYNK_WRITE(V11) { pinValue2 = param.asInt(); // assigning incoming value from pin V10 to a variable } // in Blynk app writes values to the Virtual Pin V5, this is for the slider BLYNK_WRITE(V12) { pinValue3 = param.asInt(); // assigning incoming value from pin V10 to a variable } void toarduino() { v2arduino = v2arduino + pinValue1 + "," + pinValue2 + "," + pinValue3; Serial.println(v2arduino); delay(100); v2arduino = ""; } |
Watch Video Tutorial:
Some other Projects based on the Nodemcu and Blynk Application:
IOT 3 Phase Transformer Load monitoring using Arduino and Nodemcu
IOT Water Quality monitoring using Arduino,pH Sensor,Nodemcu ESP8266
Nodemcu ESP8266 DS18b20 Waterproof Temperature Sensor Monitoring
Wireless vibration sensor, iot vibration sensor, Industrial vibration sensor “nodemcu esp8266”
Esp8266 Iot battery monitor, battery voltage monitoring using nodemcu esp8266 wifi module