Hi again, I can’t read the distance in the blynk app of my ultrasonic sensor. I’m using an Arduino UNO and an HC-RS04 ultrasonic sensor. This is my code:
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
char auth[] = "c046b3f28da144598e5119d4d2cfb74d";
SimpleTimer timer;
#define echoPin 3 // Echo Pin
#define trigPin 5 // Trigger Pin
long duration, distance; // Duration used to calculate distance
void MeasureCm()
{
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
Serial.print("Distance: ");
Serial.println(distance);
}
void setup() {
Serial.begin(9600);
Blynk.begin(auth);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
timer.setInterval(1000, MeasureCm);
}
BLYNK_WRITE(V8)
{
Blynk.virtualWrite(8,distance);// virtualpin 8 distance
}
void loop() {
Blynk.run(); // Initiates Blynk
timer.run(); // Initiates SimpleTimer
}
I read the distance in the serial monitor but in the app. I’m using a V level widget with V8 port in push. Somebody help me please.