How to make a WIFI control tank using Nodemcu ESP8266 with Blynk app
Hello and welcome back. In this project, we will learn how to make a wifi control tank using the Nodemcu ESP8266 board with the Blynk application. For that, I used the robotic tank kit provided by the OSEPP. But don’t worry you can use any other tank or car. I also published a WIFI control car in a previous article. If you want you can read it using this link. I think you already know about the Blynk app. If not, see the articles under the Nodemcu tutorial. You can get a good idea about IoT through it. Then try this project. Ok, let’s go ahead.
Ok, let’s do this project step by step. The required components are given below.
- Robot tank — OSEPP
- Nodemcu ESP8266 board — Our Store / Amazon
- L298N motor driver — Our Store / Amazon
- Li-ion battery x 2 — Amazon
- Li-ion battery holder — Our Store / Amazon
- Breadboard — Our Store / Amazon
- Jumper wires — Our Store / Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.
Step 2
Secondly, attach the motor drive board to the top of the tank.
Step 3
Thirdly, connect the motors to the motor driver board.
Step 4
Then, attach the breadboard and connect the Nodemcu board to the breadboard. Otherwise, You can use a dot board for that.
Step 5
After that, connect the motor driver board to the Nodemcu board using the jumper wires. To do this, use the circuit diagram below.
Step 6
Next, attach the li-ion battery holder to the robot tank as you like. Then, connect it to the power connectors on the motor drive board.
Step 7
Now, connect the Nodemcu board to the computer.
Step 8
Ok, now let’s set up the Blynk app step by step. For that, follow the instructions below.
- First, download and install the Blynk app on your phone. Then sign up using your gmail address.
- Now, click on the “New Project” button. Then select the device and connection type. Also, enter the name of your project as you like. Finally click the “Conform” button. Now, you can see the empty project interface.
- Next, let’s add four buttons and one slider to the interface. For that, click the + icon in the upper right corner and add the widgets to the interface. After, customize the widgets as you like.
- OK, now configure these widgets one by one. For that, use the picture below.
- Forward -> V0 / Backward -> V1 / Left –> V2 / Right –> V3 / slider –> V4(0 – 255)
- OK, the blynk app is now ready.
Step 9
Now, let’ set up the Arduino IDE. For that, use the program below.
/*Nodemcu ESP8266 with WIFI control tank.
* This code created by the sritu hobby team.
* https://srituhobby.com
*/
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//Motor PINs
#define ENA D0
#define IN1 D1
#define IN2 D2
#define IN3 D3
#define IN4 D4
#define ENB D5
bool forward = 0;
bool backward = 0;
bool left = 0;
bool right = 0;
int Speed;
char auth[] = ""; //Enter your Blynk application auth token
char ssid[] = ""; //Enter your WIFI name
char pass[] = ""; //Enter your WIFI passowrd
void setup() {
//Initialize the serial monitor
Serial.begin(9600);
//Set the motor pins as the output pin
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(ENB, OUTPUT);
//Initialize the blynk communication
Blynk.begin(auth, ssid, pass);
}
//Get values from the widgets
BLYNK_WRITE(V0) {
forward = param.asInt();
}
BLYNK_WRITE(V1) {
backward = param.asInt();
}
BLYNK_WRITE(V2) {
left = param.asInt();
}
BLYNK_WRITE(V3) {
right = param.asInt();
}
BLYNK_WRITE(V4) {
Speed = param.asInt();
}
//Check widget values using the IF condition
void smartcar() {
if (forward == 1) {
Forward();
Serial.println("Forward");
} else if (backward == 1) {
Backward();
Serial.println("Backward");
} else if (left == 1) {
Left();
Serial.println("Left");
} else if (right == 1) {
Right();
Serial.println("Right");
} else if (forward == 0 && backward == 0 && left == 0 && right == 0) {
Stop();
Serial.println("Stop");
}
}
void loop() {
//Run the blynk library
Blynk.run();
smartcar();
}
//Motor control functions
void Forward() {
analogWrite(ENA, Speed);
analogWrite(ENB, Speed);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void Backward() {
analogWrite(ENA, Speed);
analogWrite(ENB, Speed);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void Left() {
analogWrite(ENA, Speed);
analogWrite(ENB, Speed);
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void Right() {
analogWrite(ENA, Speed);
analogWrite(ENB, Speed);
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void Stop() {
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
- Now, copy and paste the blynk Auth token into the program. It will be in your Blynk app registered mail. Check it.
- Next, enter the name and password of your WIFI connection.
Step 10
OK, now select board and port. After, Upload this code to the Nodemcu board.
Step 11
Now, put the batteries to the battery holder and switch ON this tank. After, run the Blynk app interface and enjoy this project.
The full video is below. So, see you in the next project.
How to make a WIFI control tank using Nodemcu ESP8266 with Blynk app