Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Basic HCSR04 Data to Blynk Value Widget Example
- // jasper_fracture // jasperfracture.com
- #include <BlynkSimpleEsp8266.h>
- char auth[] = "your_blynk_token_here";
- char ssid[] = "your_wifi_ssid_here";
- char pass[] = "your_wifi_password_here";
- // gpio pins for the ultrasonic sensor
- const int trigPin = 12; // pin D6 on board
- const int echoPin = 13; // pin D7 on board
- void setup()
- {
- // put your setup code here, to run once:
- Blynk.begin(auth, ssid, pass);
- }
- void loop()
- {
- // put your main code here, to run repeatedly:
- Blynk.run();
- }
- // your basic HCSR04 code to return value in inches
- // much of this code was borrowed from the Ping example
- int checkFront()
- {
- long duration, inches;
- pinMode(trigPin, OUTPUT);
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- pinMode(echoPin, INPUT);
- duration = pulseIn(echoPin, HIGH);
- inches = microsecondsToInches(duration);
- return inches;
- }
- long microsecondsToInches(long microseconds) { return microseconds / 74 / 2; }
- // Blynk function to push data to your phone app through V1
- // Be sure to set up a "Value Display M" or something similar in your app
- // Give the widget a label, set the input to V1, and set the reading frequency to something like 500 ms
- // The Blynk "virtualWrite" function will keep the data on your phone in synch with the hardware every .5 seconds
- BLYNK_READ(V1)
- {
- Blynk.virtualWrite(V1, checkFront());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement