Good morning group,
First and foremost i apologize for any mistakes in my english. I am trying to make a solar weather station using a NodeMCU board, a DHT22 sensor and the Blynk app. After uploading the code, everything seems to work just fine, for an hour or such. After that, the app seems to freeze and unless i restart the board it stays like that (sometimes not even the restart works). I have tried to increase the time between my dht22 sensor readings to half an hour, as i suspected that too often readings my cause the freeze, but just as i said, in a matter of hours, it became unusable. Below you have my code and a picture of the app.
Please feel free to butcher it as any advice is helpful. Thank you in advance.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "DHTesp.h"
#ifdef ESP32
#pragma message(THIS EXAMPLE IS FOR ESP8266 ONLY!)
#error Select ESP8266 board.
#endif
int Sensor_PIN = 0; //D3
DHTesp dht;
char auth[] = "xxxxx";
char ssid[] = "xxxxx";
char pass[] = "xxxxx";
float Temperature;
float Humidity;
BlynkTimer timer;
void myTimerEvent()
{
Temperature = dht.getTemperature();
Humidity = dht.getHumidity();
Blynk.virtualWrite(V5, Temperature);
Blynk.virtualWrite(V6, Humidity);
}
void setup()
{
Serial.begin(9600);
dht.setup(Sensor_PIN, DHTesp::DHT22);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1800000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run();
}
Add Serial.println to see temp in the serial monitor.
Change pin D2 to DO because D2 is GPIO 0 can’t be used as input.
1 Like
What version of the Blynk library are you using?
What happens if you power your NodeMCU from a regular 5v supply rather than your solar supply?
You should be able to take DHT22 readings every 10 seconds without a problem.
Also, I notice that you don’t have a line which defines your DHT type as DHT22.
Pete.
1 Like
I will update my code accordingly. Thank you
1 Like
I am using the Blynk 1.0 library. Also, if i power the NodeMCU from a regularly 5v power supply, nothing changes. I get the same problem. It works for a little while, then it stops receiving data from the sensor. I thought that this line describes my sensor as being dht22: dht.setup(Sensor_PIN, DHTesp::DHT22);
How should i define it otherwise? Thank you
I am using pin D3, as shown in the code
1 Like
Sorry, missed that line in your void setup, I was expecting something more like this:
You should be using version 0.6.1 with legacy Blynk.
Pete.
No , you have defined pin 0 ! So it’s GPIO 0
I will update the code as in the example you’ve showed me and give it a go. Thank you very much for your time. I am still a rookie when it comes to Arduino based projects but am keen to learn about it
1 Like
Thank you for your input. I will acknowledge that and as i previously said, i am still learning the basics but tried to make it the fun-IoT-way
1 Like
On the other hand, i am also trying to add a voltage sensor to the battery wich should return the state of the battery charged by the solar panel. How should i update the code for that? Thanks in advance
1 Like
I’d start by googling how to do it, then getting the code working without Blynk (just sending the data to the serial monitor) then add-in Blynk.virtualWrite to send the data to the app.
Pete.
2 Likes
Ok. So, for the moment, i have changed the port (int Sensor_PIN = D0;) and changed the update interval at 60 seconds. I have tested the functionality of the device and it works ok, both on solar energy and 5v power supply. I only have one more question for you guys. I heard that Li-Ion batteries, while subjected to heat (my “device” is basically a plastic box in the sun, with little holes for sensing the humidity) tend to… catch fire. Should i be concerned about this aspect?
1 Like
The batteries will almost certainly distort as a result of the heat. If you’ve gone for the flat battery packs then this often leads to them bulging and failing.
It also depends what over-charge regulation circuitry you’ve used.
Pete.