i am total begginer .i want to control two dc motor with blynk for rc car .i get it to work with arduino uo board and now i want to connect to android through blynk .i searched web but dont get mush help.how do i connect it to blynk .i have a ESP 12E wifi module.can some body provide me a sketch and code for the same
i got this code from this forum but no physical connection of wires given.
//#define BLYNK_DEBUG
//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int motorA ;
int motorB ;
int X=0;
int Y=0;
int Steer=0;
int maximo=0;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "b41ff7f1659b4badb694be4c59601c2c";
void setup()
{
// Set console baud rate
Serial.begin(9600);
Blynk.begin(auth,"100Grand","Mob4life");
pinMode(motorA, OUTPUT);
pinMode(motorB, OUTPUT);
pinMode(0,OUTPUT);
pinMode(2,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
}
BLYNK_WRITE(V1)
{
int X1 = param[0].asInt();
X=X1;
int Y1 = param[1].asInt();
Y=Y1;
}
BLYNK_WRITE(V0)// slider de 100 a 255!!!!
{
int vel = param.asInt();
maximo=vel;
}
void loop()
{
if(X == 128 && Y == 128) // Stop
{
motorA = 0;
motorB = 0;
analogWrite(5, motorA);
analogWrite(4, motorA);
analogWrite(0, motorB);
analogWrite(2, motorB);
}
if(Y > 130 && X > 127 && X < 129) //Forward
{
motorA = Y;
motorB = Y;
motorA = map(motorA, 450,maximo,130, 255);
analogWrite(5, motorA);
digitalWrite(0,LOW);
motorB = map(motorA, 450,maximo,130, 255);
analogWrite(4, motorB);
digitalWrite(2,HIGH);
}
else if(Y < 126 && X > 127 && X < 129) //Reverse
{
motorA = Y;
motorB = Y;
motorA = map(motorA, 450,maximo,126, 0);
analogWrite(5, motorA);
digitalWrite(0,HIGH);
motorB = map(motorA, 450,maximo,126, 0);//something is wrong with HIGH signal
analogWrite(4, motorB);
digitalWrite(2,LOW);
}
if(Y > 130 && X < 126) //Steer Left
{
motorA = Y;
motorB = Y;
Steer = map(X, 450,maximo, 126,0);
Steer = X / maximo;
motorA = map(motorA, 450,maximo,130, 255);
analogWrite(5, motorA * (1 + Steer));
digitalWrite(0,LOW);
motorB = map(motorA, 450,maximo,130, 255);
analogWrite(4, motorB * (1 - Steer));
digitalWrite(2,HIGH);
}
if(Y > 130 && X > 130) //Steer Right
{
motorA = Y;
motorB = Y;
Steer = map(X, 450,maximo, 126,0);
Steer = X / maximo;
motorA = map(motorA, 450,maximo,130, 255);
analogWrite(5, motorA * (1 - Steer));
digitalWrite(0,LOW);
motorB = map(motorA, 450,maximo,130, 255);
analogWrite(4, motorB * (1 + Steer));
digitalWrite(2,HIGH);
}
Blynk.run();
}