The idea is to read data from LDR, MQ135 and DHT11 sensors with an ESP-32 board, and send them to Blynk. However, the program only sends data from the DHT11 sensor to Blynk. It is worth mentioning that the program reads all data normally when it is not associated with the cloud. Can someone help me?
#define BLYNK_TEMPLATE_ID "TMPLarC887WR"
#define BLYNK_DEVICE_NAME "Quickstart Device"
#define BLYNK_AUTH_TOKEN "8R4MTmvaxY_97P5GuKOfVUlLz6nTsGs_"
#define BLYNK_PRINT Serial
#include "MQ135.h"
//inclusao cĂłdigo
#include "DHT.h"
#define DHTTYPE DHT11 // DHT 11
#define PinoGasAnalogica 15
#define PinoLDR 2
#define DHTPIN 4
#define DHTTYPE DHT11
int sensor_gas = 0;
float sensor_lumi;
float indice_temp;
float indice_fogo;
MQ135 mq135_sensor(PinoGasAnalogica);
DHT dht ( DHTPIN, DHTTYPE ) ;
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "OLIVEIRA_2.4G";
char pass[] = "061125104";
BlynkTimer timer;
BLYNK_WRITE(V0)
{
// Set incoming value from pin V0 to a variable
int value = param.asInt();
// Update state
Blynk.virtualWrite(V1, value);
}
BLYNK_CONNECTED()
{
// Change Web Link Button message to "Congratulations!"
Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(V3, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
}
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V2, millis() / 1000);
}
void leituras(){
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
sensor_gas = analogRead(PinoGasAnalogica);
sensor_gas = (sensor_gas / 4096);
sensor_lumi = analogRead(PinoLDR);
sensor_lumi = (sensor_lumi / 4096);
indice_temp = t / 50;
indice_fogo = sensor_gas * 2 + sensor_lumi * 0.5 + indice_temp * 1;
Blynk.virtualWrite(V4,t);
Blynk.virtualWrite(V5,h);
Blynk.virtualWrite(V6,sensor_gas);
Blynk.virtualWrite(V7,sensor_lumi);
Blynk.virtualWrite(V8,indice_fogo);
}
void setup()
{
// Debug console
Serial.begin(115200);
dht.begin();
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, myTimerEvent);
timer.setInterval(1000L, leituras);
}
void loop()
{
Blynk.run();
timer.run();
}
You can’t use the ADC2 pins in conjunction with WiFi, so you should swap to ADC1 pins…
Analog to Digital Converter (ADC)
The ESP32 has 18 x 12 bits ADC input channels (while the ESP8266 only has 1x 10 bits ADC). These are the GPIOs that can be used as ADC and respective channels:
I checked the read without uploading to the cloud and everything works normally. The problem is not in the reading, but in sending it to Blynk, as the “indice_fogo”, which takes data from the LDR and MQ135 sensor, is changed when some modification is made to the sensors.
tells your ESP32 to output data to the serial monitor at 115200 baud, but your screenshot shows that you have your serial monitor set to 8600 baud, hence the garbage in the serial monitor.
For us to be able to help we need to see your full updates code, so we can see what debug code you have added and where, and we also need to see the text that appears in your serial monitor - including what is shown at boot-up and the Blynk connection phase. Please copy the serial monitor text and paste it between triple backticks the same as for code. Please DO NOT post screenshots of your code or serial monitor output.
and also turned-on the timestamp option in the serial monitor and let it run for a few seconds worth of readings.
How are your V6 and V7 datastreams configured (especially the data type and Min/Max values) and what type of widgets do you have these datastreams connected to? Did you remember to choose a datastream when you added the widgets?
For some reason it now worked. The “sensor_gas” was declared as “int”, but it must be “float”, because when dividing by 4096, the value remained at zero. After I fixed that and the serial monitor (I don’t know if it has any relationship) it is sending all the data to Blynk.
Yep, sending zero to Blynk will show zero in the widget display.
It’s really useful to add lots of debug messages that track the value of variables and show you when certain conditions are met and sections of the sketch are executed, especially when you’re debugging code that isn’t producing the expected results.
Hello there.
I’ve been having the same problem with the LDR sensor, when I’m not using Blynk it measures normally; however, as soon as I begin using Blynk it begins reading 0.
I’ve been trying everything on this thread yet I’ve got no results, could you help me?
Here’s my code:
Well I did it thanks anyway.
Upon close inspection of this thread I was able to do it.
Thank you so much, I’ve been trying to this over a week.
Thank you so much once again.