Introduction:
Controlling robots wirelessly is great fun. There are many methods available through which you can control your robot wirelessly.
They are:
- RF remote controller
- Bluetooth signal
- IR signal
- Wifi or IOT etc...
Things needed
- Arduino
- Nodemcu(Esp8266)
- 2 DC motors and Motor driver
- LCD display(may or may not added)
- Batteries or any other power source
- Blynk Application
- Jumper wires etc.
Step 1: Building the Body of Robot
I Build the robot with Sun-board and card board gluing them with super glue. I used old mobile batteries as source and stick them to body. here are some pictures of my build.
Step 2: Connection of different elements
- Connect two dc motors to the motor driver. for more about motor drivers follow this:https://www.ganeshgadgets.co.in/2017/09/line-follower-part-2-motor-driver.html
- Connect arduino to the motor driver. use enable of motor driver with PWM inputs of arduino.
- Power up nodemcu with arduino from 5v pin. Here the idea is when arduino receives digital output from nodemcu at its input pins it would do certain actions.
- 5 outputs from nodemcu(D0-D4) is fed to 5 pins of arduino(A0 toA5 -here digital pins are used so pin 14 to pin 19).
- Example when D0 of nodemcu is high, Arduino receives signal and command noter driver to go forward.
if ( digitalRead(a0) == HIGH ) //forward//
{
lcd.setCursor(0, 1);
lcd.print("FORWARD ");
digitalWrite(af, HIGH);
digitalWrite(ar, LOW);
digitalWrite(bf, HIGH);
digitalWrite(br, LOW);
}
- To view commands you can also add a LCD-16x2 module to the robot which is very helpful for troubleshooting. To interface 16x2 module: https://www.ganeshgadgets.co.in/2018/01/16x2-lcd-interface-with-arduino.html
Step 3: Programming Nodemcu and Arduino
- First of all you need to load blynk "standalone" code into the Nodemcu.for this you should follow my previous post: https://www.ganeshgadgets.co.in/2018/09/iot-switch-using-nodemcu-and-blynk-app.html.
- Open Blynk app create 5 buttons preferably push-button type and assign them from D0 to D4.
- Open Arduino and write following codes.
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 10, 11, 12, 13); //16x2 lcd interface
int en = 3;//a-right motor b-Left motor //
int af = 6;int ar = 7;
int bf = 5;int br = 4;
int a0=14 , a1=15 , a2= 16 ,a3= 17, a4= 18;//from nodemcu D0 to D4//
void setup() {
lcd.begin(16, 2);
pinMode(en,OUTPUT);
pinMode(ar,OUTPUT);pinMode(af,OUTPUT);
pinMode(bf,OUTPUT);pinMode(br,OUTPUT);
pinMode(a0,INPUT); pinMode(a1,INPUT); pinMode(a2,INPUT);
pinMode(a3,INPUT); pinMode(a4,INPUT);
digitalWrite(en,HIGH);
// loading();
}
void loop() {
if ( digitalRead(a0) == HIGH ) //forward//
{
lcd.setCursor(0, 1);
lcd.print("FORWARD ");
digitalWrite(af, HIGH);
digitalWrite(ar, LOW);
digitalWrite(bf, HIGH);
digitalWrite(br, LOW);
}
if (digitalRead(a1) == HIGH) //backward//
{
lcd.setCursor(0, 1);
lcd.print("BACKWARD");
digitalWrite(af, LOW);
digitalWrite(ar,HIGH);
digitalWrite(bf, LOW);
digitalWrite(br, HIGH);
}
if (digitalRead(a2) == HIGH) //RIGHT
{
lcd.setCursor(0, 1);
lcd.print("RIGHT ");
digitalWrite(af, LOW);
digitalWrite(ar,HIGH);
digitalWrite(bf, HIGH);
digitalWrite(br,LOW);
}
if (digitalRead(a3) == HIGH)//LEFT
{
lcd.setCursor(0, 1);
lcd.print("LEFT ");
digitalWrite(af, HIGH);
digitalWrite(ar,LOW);
digitalWrite(bf, LOW);
digitalWrite(br, HIGH);
}
if (digitalRead(a4) == HIGH)//STOP
{
lcd.setCursor(0, 1);
lcd.print("STOP ");
digitalWrite(af, HIGH);
digitalWrite(ar, HIGH);
digitalWrite(bf, HIGH);
digitalWrite(br, HIGH);
}
else
{
lcd.setCursor(0, 1);
lcd.print(" ");
digitalWrite(af, HIGH);
digitalWrite(ar, HIGH);
digitalWrite(bf, HIGH);
digitalWrite(br, HIGH);
}
} Conclusion:
You can easily build this. you can add lights to the robot and also other features using nodemcu. here is working video of the robot.
https://youtu.be/UsY_pJP5PVcAlso like and subscribe the channel.