Hello everybody,
Since 1 week, I try to find the solution with my project. First, I’ll present my project:
I have some beehives and I would like to connect them to check their weights, internal temperature and humidity . For that I use an ESP8266 with an Oled screen, a DHT11 sensor and 4 cells of weight with a HX711. Everything works fine and is displayed on my OLed screen.
When I try to connect with Blynk, I have a fault on my DHT11, and some time my DHT11 works but 1s and after is back to failled…
when I remove the line timer.setInterval(1000L, sendSensor); on my programm it’s working fine on the Oled but of course nothing is send to the Blynk server. I am an amateur in programming sorry for that…
I need your help…
I try a simple program find in : https://examples.blynk.cc/ for the DHT11 and I have the same issue
Many thanks for your help
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "secret";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "secret";
char pass[] = "secret";
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
#include <DHT.h>
#include <HX711.h>
// Capteur de poids setting
const int SCALE_DOUT_PIN = D5;
const int SCALE_SCK_PIN = D6;
HX711 scale(SCALE_DOUT_PIN, SCALE_SCK_PIN);
float weight = 0;
static float t, h;
#define DHTPIN D3 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
// Initialize the OLED display using Wire library
SSD1306 display(0x3c, D2, D1);
// SH1106 display(0x3c, D3, D5);
// Display Settings
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
void displayTempHumid(){
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
t = dht.readTemperature();
h = dht.readHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t)){
display.clear(); // clearing the display
display.drawString(5,0, "failed read from DHT");
return;
}
display.clear();
String weight = String(scale.get_units(1), 2);
display.drawString(0, 0, "hive connected");
display.drawString(0, 16, "Humidity: " + String(h) + "%\t");
display.drawString(0, 32, "Temp: " + String(t) + "C");
display.drawString(0, 48, "weight: " + String(weight) + "KG");
}
void sendSensor()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(6, t); //virtual pin V6 DHT11
Blynk.virtualWrite(5, h); // virtual pin V5 DHT11
//Blynk.virtualWrite(6, temp2); //virtual pin V7 DHT22
//Blynk.virtualWrite(5, hum2); // virtual pin V8 DHT22
//Blynk.virtualWrite(4, weight); // virtual pin V12
}
void setup(){
// Initialising the UI will init the display too.
Serial.begin(115200);
delay(10);
Blynk.begin(auth, ssid, pass);
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_16);
display.setTextAlignment(TEXT_ALIGN_LEFT);
scale.set_scale( -6000 / 0.3095 );
scale.tare();
dht.begin(); // initialize dht
timer.setInterval(1000L, sendSensor);
}
void loop(){
displayTempHumid();
display.display();
Blynk.run();
timer.run();
}```