Loading...

Wifi controlled car using NodeMCU and Blynk Application | Arduino Geek


Hello everyone! Welcome to Arduino Geek. Today we will discuss about a Wifi controlled car using NodeMCU and Blynk Application. A wifi controlled car is a basic example of NodeMCU project. Previously we learn about a Bluetooth controlled car which I made using arduino. Like this a wifi controlled car is an IOT based project where we use the ESP8266 module (commonly known as NodeMCU) as the main functioning unit of the car. By using ESP8266 module we can connect the car to our smart phone via wifi connection. Also we can control the car from our smart phone by using Blynk application. In today’s blog I will tell you every necessary steps that you have to follow while building a wifi controlled car. Also I will tell you how to connect the car with your smart phone using wifi. So let’s get started.

Components –

(1) DC Geared Motor

(2) ESP8266 Module (NodeMCU)

(3) L298N Motor Driver

(4) Jumper Wire

(5) Wheels

(6) 12 Volt Lipo Battery

Structure Building –

The first step to build this car is to make its frame. To make the frame you need to take a wooden or plastic board of a relevant size. This board will be used as the chassis of the car. Do not use a board of large size, because it will increase the overall weight of the car. Then take the geared dc motors or the bo motors and then fix them at the four corners of the car. Do not use a normal dc motors in this project, because the output torque of a normal dc motor is much lesser than a geared dc motor. And if you use a normal dc motor your car will not able to move due to low torque. So it is always recommended to use a geared one.

After this take the wheels and fix it in the motors by using a shaft coupling. Now the basic structure for the car is ready. The next important thing is to incorporate the circuit in the car.

 

Circuit Connection –

To build the circuit we need two main things which are ESP 8266 module (NodeMCU) and L298N motor driver. At first take the L298N motor driver and fix it exactly middle of the car. Then take wires of the dc motors and connect it to the motor output of the L298N motor driver. There are two motor output in L298N motor driver. So you need to connect two dc motors in each motor output of the motor driver.

After connect the motors to the motor driver, you need to take the ESP 8266 module and then put it in front of motor driver. Now you have to build the connection between the ESP 8266 module and L298N motor driver. You can easily built the connection by following the listed steps –

(1) Connect the IN1 pin of motor driver with the D5 pin of the ESP8266 module.

(2) Connect the IN2 pin of motor driver with the D6 pin of the ESP8266 module.

(3) Connect the IN3 pin of motor driver with the D7 pin of the ESP8266 module.

(4) Connect the IN4 pin of motor driver with the D8 pin of the ESP8266 module.

After doing the above connections, you have to connect the battery in the circuit. You can use a 12 volt lipo battery or a 7.4 volt lipo battery. Here is the battery connection of the circuit –

(1) Connect the positive terminal of the battery with the 12 volt pin of the motor driver.

(2) Connect the negative terminal of the battery with the Gnd pin of the motor driver.

Blynk Application Setup –

Now download the Blynk application from the Google play store. Then open the Blynk application and create a new account. Provide a verified email address and a password, and then click on sign up. After the completion of sign up, you have to create a new project. Give a project name like “NodeMCU Car” and then select the device type “ESP8266”. Then click on create. At that moment you will receive a mail from the Blynk application. The mail contains the “Auth Token” for the specific project which you have created just now. You have to note down the auth token for using it in the coding section.

Now come back to the Blynk application and select the joystick. Resize the joystick according to the size of your screen. Then go to the joystick settings and select the “merge” option. After this select the pin “V1”. If you want to add more features in your project like “button”, “slider”, then you can follow the same steps as discussed earlier.

Coding –

Now you have to do the coding in ESP8266 module (NodeMCU). Connect the ESP8266 module (NodeMCU) with your computer. After this open the Arduino IDE software and write down the following code –


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define RightMotorSpeed       D5   //14
#define RightMotorDir         D6   //12
#define LeftMotorSpeed        D7   //13
#define LeftMotorDir          D8   //15

char auth[] = "  ";  //Blynk Authentication Token
char ssid[] = "  ";           //WIFI Name
char pass[] = "  ";           //WIFI Password

int minRange = 312;
int maxRange = 712;

int minspeed = 450;
int maxspeed = 1020;
int nospeed = 0;


void moveControl(int x, int y)
{
//Move Forward
    if(y >= maxRange && x >= minRange && x<= maxRange)
    {
        digitalWrite( RightMotorDir,HIGH);
        digitalWrite(LeftMotorDir,HIGH);
        analogWrite(RightMotorSpeed, maxspeed);
        analogWrite(LeftMotorSpeed , maxspeed);
    }


//Move Forward Right
    else if(x >= maxRange && y >= maxRange)
    {
        digitalWrite( RightMotorDir, HIGH);
        digitalWrite(LeftMotorDir,HIGH);
        analogWrite(RightMotorSpeed,minspeed);
        analogWrite(LeftMotorSpeed ,maxspeed);
    }

//Move Forward Left
    else if(x <= minRange && y >= maxRange)
    {
        digitalWrite( RightMotorDir,HIGH);
        digitalWrite(LeftMotorDir,HIGH);
        analogWrite(RightMotorSpeed,maxspeed);
        analogWrite(LeftMotorSpeed ,minspeed);
    }

//No Move
    else if(y < maxRange && y > minRange && x < maxRange && x > minRange)
    {
        analogWrite(RightMotorSpeed,nospeed);
        analogWrite(LeftMotorSpeed , nospeed);
    }

//Move Backward
    else if(y <= minRange && x >= minRange && x <= maxRange)
    {
        digitalWrite( RightMotorDir,LOW);
        digitalWrite(LeftMotorDir,LOW);
        analogWrite(RightMotorSpeed,maxspeed);
        analogWrite(LeftMotorSpeed ,maxspeed);
    }

//Move Backward Right
    else if(y <= minRange && x <= minRange)
    {
        digitalWrite( RightMotorDir,LOW);
        digitalWrite(LeftMotorDir,LOW);
        analogWrite(RightMotorSpeed,minspeed);
        analogWrite(LeftMotorSpeed ,maxspeed);
    }

//Move Backward Left
    else if(y <= minRange && x >= maxRange)
    {
        digitalWrite( RightMotorDir,LOW);
        digitalWrite(LeftMotorDir,LOW);
        analogWrite(RightMotorSpeed,maxspeed);
        analogWrite(LeftMotorSpeed ,minspeed);
    }
}
void setup()
{
    Serial.begin(9600);
    Blynk.begin(auth, ssid, pass);

    pinMode(RightMotorSpeed, OUTPUT);
    pinMode(LeftMotorSpeed , OUTPUT);
    pinMode( RightMotorDir, OUTPUT);
    pinMode(LeftMotorDir, OUTPUT);

    digitalWrite(RightMotorSpeed, LOW);
    digitalWrite(LeftMotorSpeed , LOW);
    digitalWrite( RightMotorDir, HIGH);
    digitalWrite(LeftMotorDir, HIGH);
}
void loop()
{
    Blynk.run();
}
BLYNK_WRITE(V1)
{
    int x = param[0].asInt();
    int y = param[1].asInt();
    moveControl(x,y);
}

In this following code you have to change some parameters like “wifi name”, “wifi password” and “Auth token”. You have to use the same auth token that you got on your email id during project creation.

Now you have to upload the code in the NodeMCU. But before this you have to follow some simple steps which are listed below –

(1) Go to the files option and select the preference.

(2) Then write down the library link of ESP8266 and then click on ok.

(3) After this go to the tools and open the board manager. In the board manager, you have to search the following phrase “ESP8266”. Now you have to install the ESP8266 library. After successful installation of ESP8266 library, click on close button.

(4) Again go to the tools and then select the correct board type which is “NodeMCU 1.0 (ESP-12E Module)”.

(5) Then select the correct port.

After completing all this steps, you have to upload the code to the ESP8266 module. So click on upload button and wait for a while.

After uploading the code, take the smart phone and open the wifi. Then connect the wifi with the ESP8266 module. Now go to the Blynk application and select the particular project that you have made. Then click on run button. Now you can run the car by the use of joystick.

 
close