Wifi Controlled Robot Car Using Nodemcu and Blynk

10,342

11

29

Introduction: Wifi Controlled Robot Car Using Nodemcu and Blynk

Supplies

  • 1 x Nodemcu
  • 1 x Lm298 motor driver
  • 2 x Bo motors
  • 3 x wheels
  • jumper wires
  • 9v battery
  • 5v powerbank/battery

Step 1: Hardware Connection:

Getting to Know Your L298N Dual H-Bridge Motor Controller Module .An H-Bridge is a circuit that can drive a current in either polarity and be controlled by Pulse Width Modulation (PWM). What is Pulse Width Modulation? Pulse Width Modulation is a means in controlling the duration of an electronic pulse. Motors will last much longer and be more reliable if controlled through PWM.

  • Specifications:
  • Double H bridge Driver Chip: L298N
  • Logical voltage: 5V
  • Drive voltage: 5V-35V
  • Logical current: 0-36mA
  • Drive current: 2A (MAX single bridge)
  • Max power: 25W
  • Note: Built-in 5v power supply, when the driving voltage is 7v-35v. But i recommend you not to power up your microcontroller with on-board 5v power supply.

1:connect the bo motor to the motor driver as shown in the image above

2: connect the motor driver to nodemcu as given below:

  • GPIO2(D4)- IN3
  • GPIO15(D8)-IN1
  • GPIO0(D3)-IN4
  • GPIO13(D7)-IN2
  • GPIO14(D5)-Enb-A
  • GPIO12(D6)-Enb-B

3:Supply Connections :

  • +12v - Positive terminal of the battery to be connected.
  • GND - Ground terminal of the battery to be connected.
  • +5v - +5v input (unnecessary if your power source is less than +7v to +9v, if the power source is greater than +9v to +35v then it can act as a 5v out)
  • 4:Input Connections :
  • (Motor A) ENA - Enables PWM signal for Motor A
  • IN1 -Enable Motor A
  • IN2 - Enable Motor A
  • (Motor B) ENB - Enables PWM signal for Motor B
  • IN3: Enable Motor B
  • IN4: Enable Motor B

Note : Make sure you have all of your grounds connected together. (NodeMCU, Power Source, and Motor Driver)The PWM Pins are unnecessary if you do not want to control PWM features.

Click here for More High tech Engineering Projects

Step 2: Software Connection

  1. Blynk setup
  2. arduino setup

Blynk setup:

  • Open the blynk app
  • click on new project
  • select the Nodemcu board and wifi connection
  • click on the plus symbol present on the right corner of app and select joystick and the slider
  • now click on the joystick select the virtual pin v1 because i have written the code for v1 and slide the button from split to merge
  • set the value range from 0-1023 because it helps in easy control of robot for larger values
  • now select the slider , select the virtual pin v2,and set values from 0 - 1023.

Arduino IDE setup:

  • Click on the Icon to open the Arduino window
  • Open the File and click on the Preferences
  • Adding ESP8266 Board Manager
  • In the Additional Boards Manager enter below URL. http://arduino.esp8266.com/stable/package_esp8266... As highlighted in the figure and enter OK.
  • Selecting Board

Now open the tools in that select Board: “Arduino/Genuino Uno” and click on the Boards Manager as shown in the figure

  • ESP8266 Board Package

The Boards Manager window opens, scroll the window page to bottom till you see the module with the name ESP8266. Once we get it, select that module and select version and click on the Install button. When it is installed it shows Installed in the module as shown in the figure and then close the window.

  • Selecting ESP8266 Arduino Board

To run the esp8266 with Arduino we have to select the Board: “Arduino/Genuino Uno” and then change it to NodeMCU 1.0 (ESP-12E Module) or other esp8266 modules depending on what you have .This can be done by scrolling down, as shown in the figure

  • Connecting ESP8266 to the PC

Now Let’s connect the ESP8266 module to your computer through USB cable as shown in the figure. When module is connected to the USB, COM port is detected eg: here COM5 is shown in the figure.

Step 3: Code for Above

#include

#include

/* 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 */

int z;

/* define L298N or L293D enable pins */

int rightMotorENB = 14; /* GPIO14(D5) -> Motor-A Enable */

int leftMotorENB = 12; /* GPIO12(D6) -> Motor-B Enable *

/ You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon).

// Use your own WiFi settings

char auth[] = "**********";

char ssid[] = "type your network name here ";

char pass[] = "type your network password here";

// neutral zone settings for x and y

// joystick must move outside these boundary numbers to activate the motors

// makes it a little easier to control the wifi car

int minRange = 312;

int maxRange = 712;

// analog speeds from 0 (lowest) - 1023 (highest)

// 3 speeds used -- 0 (noSpeed), 350 (minSpeed), 850 (maxSpeed).

// use whatever speeds you want...too fast made it a pain in the ass to control

int minSpeed = 450;

int maxSpeed = 1023;

int noSpeed = 0;

void moveControl(int x, int y) {

// movement logic // move forward

// y je vetsi jak maxrange a současně x je vetsi jak minRange a současne mensi jak max range

if(y >= maxRange && x >= minRange && x <= maxRange) {

analogWrite(leftMotorENB,z);

analogWrite(rightMotorENB,z);

digitalWrite(leftMotorForward,HIGH);

digitalWrite(rightMotorForward,HIGH);

digitalWrite(leftMotorBackward,LOW);

digitalWrite(rightMotorBackward,LOW); } //MOVE FORWARD RIGHT

else if(x <= minRange && y >= maxRange ) {

digitalWrite(leftMotorENB,maxSpeed);

digitalWrite(rightMotorENB,minSpeed);

digitalWrite(leftMotorForward,HIGH);

digitalWrite(rightMotorForward,HIGH);

digitalWrite(rightMotorBackward,LOW);

digitalWrite(leftMotorBackward,LOW); } // move right

else if(x >= maxRange && y >= minRange && y<=maxRange)

{ analogWrite(leftMotorENB,z);

analogWrite(rightMotorENB,z);

digitalWrite(leftMotorForward,HIGH);

digitalWrite(rightMotorForward,LOW);

digitalWrite(rightMotorBackward,HIGH);

digitalWrite(leftMotorBackward,LOW);

}

// move forward LEFT

else if(x <= minRange && y >= maxRange ) {

digitalWrite(leftMotorENB,minSpeed);

digitalWrite(rightMotorENB,maxSpeed);

digitalWrite(leftMotorForward,HIGH);

digitalWrite(rightMotorForward,HIGH);

digitalWrite(rightMotorBackward,LOW);

digitalWrite(leftMotorBackward,LOW); }

// moveleft else if(x <= minRange && y >= minRange && y <= maxRange) {

analogWrite(leftMotorENB,z);

analogWrite(rightMotorENB,z);

digitalWrite(leftMotorForward,LOW);

digitalWrite(rightMotorForward,HIGH);

digitalWrite(rightMotorBackward,LOW);

digitalWrite(leftMotorBackward,HIGH); }

// neutral zone

else if(y < maxRange && y > minRange && x < maxRange && x > minRange)

{ digitalWrite(leftMotorENB,LOW);

digitalWrite(rightMotorENB,LOW);

digitalWrite(leftMotorForward,LOW);

digitalWrite(leftMotorBackward,LOW);

digitalWrite(rightMotorForward,LOW);

digitalWrite(rightMotorBackward,LOW); }

// move back

else if(y <= minRange && x >= minRange && x <= maxRange) {

analogWrite(leftMotorENB,z);

analogWrite(rightMotorENB,z);

digitalWrite(leftMotorBackward,HIGH);

digitalWrite(rightMotorBackward,HIGH);

digitalWrite(leftMotorForward,LOW);

digitalWrite(rightMotorForward,LOW); }

// move back and right

else if(y <= minRange && x <= minRange) {

digitalWrite(leftMotorENB,maxSpeed);

digitalWrite(rightMotorENB,minSpeed);

digitalWrite(leftMotorForward,LOW);

digitalWrite(rightMotorForward,LOW);

digitalWrite(rightMotorBackward,HIGH);

digitalWrite(leftMotorBackward,HIGH); }

// move back and left

else if(y <= minRange && x >= maxRange) {

digitalWrite(leftMotorENB,minSpeed);

digitalWrite(rightMotorENB,maxSpeed);

digitalWrite(leftMotorForward,LOW);

digitalWrite(rightMotorForward,LOW);

digitalWrite(rightMotorBackward,HIGH);

digitalWrite(leftMotorBackward,HIGH); } }

void setup() {

// initial settings for motors off and direction forward

pinMode(leftMotorForward, OUTPUT);

pinMode(rightMotorForward, OUTPUT);

pinMode(leftMotorBackward, OUTPUT);

pinMode(rightMotorBackward, OUTPUT);

/* initialize motor enable pins as output */

pinMode(leftMotorENB, OUTPUT);

pinMode(rightMotorENB, OUTPUT);

Blynk.begin(auth, ssid, pass); }

void loop() {

Blynk.run(); }

BLYNK_WRITE(V1)

{ int x = param[0].asInt();

int y = param[1].asInt();

moveControl(x,y); }

BLYNK_WRITE(V2)

{ z = param[0].asInt(); }

1 Hour Challenge

Participated in the
1 Hour Challenge

Be the First to Share

    Recommendations

    • Micro:bit Contest

      Micro:bit Contest
    • Retro Tech Challenge

      Retro Tech Challenge
    • Made with Math Contest

      Made with Math Contest

    29 Comments

    0
    akshaypatil6325
    akshaypatil6325

    10 months ago

    what to put after # include
    i am getting an error like
    expect #include file name

    0
    COLOSSALC
    COLOSSALC

    Question 10 months ago

    Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"
    sketch_dec16a:211:8: error: expected constructor, destructor, or type conversion before '(' token
    pinMode(leftMotorENB, OUTPUT);
    ^
    sketch_dec16a:213:8: error: expected constructor, destructor, or type conversion before '(' token
    pinMode(rightMotorENB, OUTPUT);
    ^
    sketch_dec16a:215:1: error: 'Blynk' does not name a type
    Blynk.begin(auth, ssid, pass); }
    ^
    sketch_dec16a:215:32: error: expected declaration before '}' token
    Blynk.begin(auth, ssid, pass); }
    ^
    exit status 1
    expected constructor, destructor, or type conversion before '(' token
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

    0
    akshaypatil6325
    akshaypatil6325

    10 months ago

    I am getting an erro that
    error compiling for board NodeMcu1.0(ESP-12E Module)

    0
    ammaradnanali
    ammaradnanali

    10 months ago

    Arduino: 1.8.13 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"
    Executable segment sizes:
    IROM : 244916 - code in flash (default or ICACHE_FLASH_ATTR)
    IRAM : 27420 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...)
    DATA : 1312 ) - initialized variables (global, static) in RAM/HEAP
    RODATA : 1880 ) / 81920 - constants (global, static) in RAM/HEAP
    BSS : 25488 ) - zeroed variables (global, static) in RAM/HEAP
    Sketch uses 275528 bytes (26%) of program storage space. Maximum is 1044464 bytes.
    Global variables use 28680 bytes (35%) of dynamic memory, leaving 53240 bytes for local variables. Maximum is 81920 bytes.
    esptool.py v2.8
    Serial port COM1
    Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):
    File "C:\Users\ammar\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/upload.py", line 65, in <module>
    esptool.main(cmdline)
    File "C:/Users/ammar/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/esptool\esptool.py", line 2890, in main
    esp.connect(args.before)
    File "C:/Users/ammar/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/esptool\esptool.py", line 483, in connect
    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
    esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
    esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
    _
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
    im having this error plz help me

    0
    kuttanattu
    kuttanattu

    Question 10 months ago

    please say which are the #include used in the code. it is showing blank.

    0
    seamster
    seamster

    2 years ago

    Thank you for sharing! : )

    0
    Manitesla
    Manitesla

    Reply 11 months ago

    your welcome

    0
    kansalnaman23
    kansalnaman23

    1 year ago

    Arduino: 1.8.12 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, SSL+TLS_MEM+HTTP_CLIENT, Only Sketch, 115200"
    car:1:25: fatal error: Esp8266Wifi.h: No such file or directory
    #include <Esp8266Wifi.h>
    ^
    compilation terminated.
    exit status 1
    Esp8266Wifi.h: No such file or directory
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

    pls tell what is this directory Esp8266Wifi.

    0
    Manitesla
    Manitesla

    Reply 1 year ago

    1)Please make sure that u have selected Esp8266 board while uploading,
    2)Paste the below link in additional board manager url,, present in files ->preferences http://arduino.esp8266.com/stable/package_esp8266com_index.json

    After pasting it and saving,, go to board manager and download Esp8266 libraries from there.
    To know in detail visit my blog and scroll down to this project it shows the step i explained above with pictures,,

    0
    kansalnaman23
    kansalnaman23

    Reply 1 year ago

    Hello I need help that only 1 motor is moving in all the extreme position of joystick pls tell how to fix it

    0
    Manitesla
    Manitesla

    Reply 1 year ago

    1)The problem may be in the power supply you r using,, The batteries may not have power to power both the motors hence at extreme postion the motor may stop working
    2)may be problem with the motor try replacing the motor
    3)check blynk app see if x and y are set correct,, and check code to see if x and y values are sent to correct digital pins of motor driver

    0
    rohittechzone
    rohittechzone

    Question 1 year ago

    Hi In tryed my version with my own code but i can't control digital pins in esp8266 does it works in this? Please Help Me!!

    0
    Manitesla
    Manitesla

    Answer 1 year ago

    Ya the digital pins work with my code esp8266 as all digital pin only but only 1 pin is analog,, and my code is using the digital pins of the nodemcu Esp8266

    0
    Syukri012
    Syukri012

    1 year ago on Step 3

    Where is the step 3?😅

    0
    Manitesla
    Manitesla

    Reply 1 year ago

    Sorry, due to some mistake the step 3 code is been removed,
    Visit my blog Manitesla.blogspot.com
    To get the code and project detail

    0
    Syukri012
    Syukri012

    Reply 1 year ago

    Thanks😃🖒

    0
    ashwinn9898
    ashwinn9898

    2 years ago on Step 3

    HI
    i couldn't find the code fo this project ,please let me know!