0% found this document useful (0 votes)
33 views6 pages

Define BLYN1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views6 pages

Define BLYN1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy