Hi friends,
I’d like to share with you this little project using Blynk and Local Server.
I have been enjoying a lot doing it. Thanks for this huge program called Blynk!!!
Please, keep in mind I’m just a beginner… the code is NOT perfect but it works!
I have been playing with a Dual H Bridge Stepper Motor Drive Controller Board and two DC Gear Motors.
The power supply is just two Li-ion Batteries 3.7V (7.4V to power the DC motors).
There’s a LM7805 to feed the Arduino and a small ASM1117 3.3V for the ESP8266.
I have done a small Shield with a piece of a PCB Board to join the ESP8266 and the Arduino Nano. (I’m really happy with this shield, It works really well)
You can see below my code:
//#define BLYNK_DEBUG
//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
// Set ESP8266 Serial object
#define EspSerial Serial
ESP8266 wifi(EspSerial);
int motorA ;
int motorB ;
int X=0;
int Y=0;
int factor=0;
int maximo=70;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
void setup()
{
// Set console baud rate
Serial.begin(9600);
delay(10);
// Set ESP8266 baud rate
EspSerial.begin(9600);
delay(10);
Blynk.begin(auth, wifi,"xxxxxxx","xxxxxxxxxxxxx","xxx.xxx.x.xx");
pinMode(motorA, OUTPUT);
pinMode(motorB, OUTPUT);
}
BLYNK_WRITE(V1)
{
int X1 = param.asInt();
X=X1;
}
BLYNK_WRITE(V2)
{
int Y1 = param.asInt();
Y=Y1;
}
BLYNK_WRITE(V0)// slider de 100 a 255!!!!
{
int vel = param.asInt();
maximo=vel;
}
void loop()
{
if(X == 128 && Y == 128) // Parados OK
{
motorA = 0;
motorB = 0;
analogWrite(5, motorA);
analogWrite(6, motorA);
analogWrite(10, motorB);
analogWrite(9, motorB);
}
if(X >= 129 && Y == 128) //Avance OK
{
motorA = X;
motorB = X;
motorA = map(motorA, 129,255 , 70,maximo);
analogWrite(5, motorA);
analogWrite(6,0);
motorB = map(motorB, 129,255 , 70,maximo);
analogWrite(10, motorB);
analogWrite(9,0);
}
if(X >= 129 && Y <= 127) //Avance Derecha OK
{
motorA = X;
motorB = X;
factor = Y;
factor= map(factor,0,127,35,0);
motorA = map(motorA, 129,255 , 70,maximo);
analogWrite(5, motorA);
analogWrite(6,0);
motorB = map(motorB, 129,255 , 70,maximo);
analogWrite(10, (motorB-factor));
analogWrite(9,0);
}
if(X >= 129 && Y >= 129) //Avance Izquierda OK
{
motorA = X;
motorB = X;
factor = Y;
factor= map(factor,129,255, 0,35);
motorA = map(motorA, 129,255 , 70,maximo);
analogWrite(5, (motorA-factor));
analogWrite(6,0);
motorB = map(motorB, 129,255 , 70,maximo);
analogWrite(10, motorB);
analogWrite(9,0);
}
if(X <= 127 && Y ==128) //Retroceso OK
{
motorA = X;
motorB = X;
motorA = map(motorA, 0,126 , maximo,70);
analogWrite(6, motorA);
analogWrite(5,0);
motorB = map(motorB, 0,126 , maximo,70);
analogWrite(9, motorB);
analogWrite(10,0);
}
if(X <= 127 && Y <=127) //Retroceso Derecha OK
{
motorA = X;
motorB = X;
factor = Y;
factor= map(factor,0,127, 35,0);
motorA = map(motorA, 0,126 , maximo,70);
analogWrite(6, motorA);
analogWrite(5,0);
motorB = map(motorB, 0,126 , maximo,70);
analogWrite(9, (motorB-factor));
analogWrite(10,0);
}
if(X <= 127 && Y >=129) //Retroceso Izquierda OK
{
motorA = X;
motorB = X;
factor = Y;
factor= map(factor,129,255, 0,35);
motorA = map(motorA, 0,126 , maximo,70);
analogWrite(6, (motorA-factor));
analogWrite(5,0);
motorB = map(motorB, 0,126 , maximo,70);
analogWrite(9, motorB);
analogWrite(10,0);
}
Blynk.run();
}
The code itself is really simple, using 2 Joysticks and a Large Slider I can control the movement forward, backward and turn on the left and right.
I use the Slider to fix the speed (the Slider works between 100 and 255) This way my daugther can play with the robot easily.
And some photos:
You can see the video here:
I’m using a Tablet with “Shared Access”.
I hope you like it!!!
Kind regards