Hi and Hello everyone!!
I’m a beginner in esp32+blynk try to do final year project. I try to do by my own for two ultrasonic sensor HC-SR04 connecting with Blynk. But the 2nd sensor cannot read and just show the exact same value like 1st ultrasonic sensor. Hope you guys can help me.Thanks in advance
Here is some information of the hardware and the code is attached below
• ESP32 + Wi-Fi.
• iPhone (IOS 16)
• Blynk server
• Blynk Library version 1.0
• Code.
#define BLYNK_TEMPLATE_ID "****"
#define BLYNK_DEVICE_NAME "CAT HOME MONITORING SYSTEM"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#define USE_ESP32S2_DEV_KIT
#include "BlynkEdgent.h"
#define trig 12
#define echo 13
#define trig1 14
#define echo1 15
BlynkTimer timer;
long tankDepth=24;
long tankDepth1=24;
void waterLevel(){
digitalWrite(trig,LOW);
delayMicroseconds(2);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
long t = pulseIn(echo, HIGH);
long cm = t / 29 / 2;
Serial.println(cm);
double level= tankDepth-cm;
if(level>0){
long percentage=((level/tankDepth))*100;
Blynk.virtualWrite(V0,percentage);
}
else{
Blynk.virtualWrite(V0,0);
}
delayMicroseconds(2);
digitalWrite(trig1,LOW);
delayMicroseconds(2);
digitalWrite(trig1, HIGH);
delayMicroseconds(10);
digitalWrite(trig1, LOW);
long t1 = pulseIn(echo1, HIGH);
long cm1 = t1 / 29 / 2;
double level1= tankDepth1-cm;
Serial.println(cm1);
if(level1>0){
long percentage=((level1/tankDepth1))*100;
Blynk.virtualWrite(V3,percentage);
}
else{
Blynk.virtualWrite(V3,0);
}
}
void setup()
{
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(trig1, OUTPUT);
pinMode(echo1, INPUT);
Serial.begin(115200);
delay(100);
BlynkEdgent.begin();
timer.setInterval(5000L, waterLevel);
}
void loop() {
BlynkEdgent.run();
timer.run();
}
and if it was me, I’d have called this percentage1…
but I don’t think either of these are causing your issue.
I’d be inclined to split void waterLevel() into two functions - one to measure tank 1 and the other to measure tank 2. You can then call them, independently to check that they work and give different results. You could then use two BlkynkTimers, or call the second function from the first one.
Also, have you checked the min/max values for datastreams V0 and V3 to ensure that they are both 0-100 ?
The delay between the two timers means that they start half a second apart from each other.
If you want more info on timers you should read this (although it’s probably best reserved for when you’re having a sleepless night and counting sheep isn’t working)…
Thanks a lot!! sure I’ll go through that…right now its 2.50 a.m. in Malaysia and counting sheep not worked…Thats why Im try to solve this problem…Haha
Nice to know you Sir.
Hi, percentage i think not going to show correct value. Becase ultrosonic sensor minimum value 19 sm, max value more than 400. I used map function.
I advice you to search for arduino map function