Define BLYN1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

#define trig D2

#define echo D1

long duration;

int distance;

// You should get Auth Token in the Blynk App.

char auth[] = "UYV-W8iNZ-tROd_V2fqsbg6mdDMR1xcW";

// Your WiFi credentials.

// Set password to "" for open networks.

char ssid[] = "MARIBEL MONTERO";

char pass[] = "16466070";

BlynkTimer timer;

void sendSensor()

digitalWrite(trig, LOW); // Makes trigPin low

delayMicroseconds(2); // 2 micro second delay

digitalWrite(trig, HIGH); // tigPin high


delayMicroseconds(10); // trigPin high for 10 micro seconds

digitalWrite(trig, LOW); // trigPin low

duration = pulseIn(echo, HIGH); //Read echo pin, time in microseconds

distance = duration * 0.034 / 2; //Calculating actual/real distance

Serial.print("Distance = "); //Output distance on arduino serial monitor

Serial.println(distance);

if(distance <= 5)

Blynk.tweet("My Arduino project is tweeting using @blynk_app and it’s awesome!\n #arduino
#IoT #blynk");

Blynk.notify("Post has been twitted");

Blynk.virtualWrite(V0, distance);

delay(1000); //Pause for 3 seconds and start measuring distance again

//ESP8266 Blynk Joystick Car

#define RightMotorSpeed D5 //14

#define RightMotorDir D6 //12

#define LeftMotorSpeed D7 //13

#define LeftMotorDir D8 //15


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()

// Debug console

pinMode(trig, OUTPUT); // Sets the trigPin as an Output

pinMode(echo, INPUT); // Sets the echoPin as an Inpu

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);

// Setup a function to be called every second

timer.setInterval(1000L, sendSensor);

void loop()

Blynk.run();

BLYNK_WRITE(V1)

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

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

moveControl(x,y);

You might also like