Beehive project issue

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();  
}```

By having these in your void loop, they are being called thousands of times per second. I’m surprised this actually works, as the DHT sensor is very slow, so doesn’t like to be read more than about once every few seconds.

Try restructuring your code so you only read the sensor every 5 seconds or so, and write the data to the OLED and Blynk at the same time.

Looks like a cool project. My father was a beekeeper for many years and I’m interested in the way that technology can be used to improve the process.

Pete.

Many thanks Pete, I will try to restruring my code with my smal programming level

Hi @christophebl, can you please provide some more info about how your weighing your bee-hive and perhaps a link to where you bought your hx711. I’m keen to put my bees (Australian Native Bees) on scales to monitor weight as well.

 timer.setInterval(4000L, sendSensor);
 timer.setInterval(5000L, displayTempHumid);


void loop(){
   Blynk.run();
   timer.run();  
}

Hi GG07

The load Cell I Have is this:
Capture
The link I have used:

IMG_4608

the weight is very good I can go up to 200KG

Back to my issue I do not how to restruturing my code… :frowning:

I replied just before

https://community.blynk.cc/t/beehive-project-issue/27245/5

Thanks very much for the info…now with your code,

Remove this and call this data from within a timer as pointed out by @Blynk_Coeur.

Don’t know what the difference is but I have declared it differently in my code…

float h;
float t;

Many thanks Alexis_Cabrera and GG07,
now it’s work perfectly with the DHT11 but How I can see those data in my OLed? Sorry I’m an amateur…

just add display.display() at the end off your void

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"); 
  display.display(); 
}

Yes perfect!! I’m so happy!! Now i will try send my weight float to blynk. Many thanks for your help!

When i will install all in my beebive I will send you some photos!

2 Likes

Well done…looking forward to seeing more of your project

If you’re looking for a cheap source for load cells, check out the local charity shops, car boot sales, flea markets etc for old Wii Fit balance boards. If the balance board is roughly the right size then you could even retain the plastic structure, and remove the existing circuit board and replace with your HX711 and MCU of choice.
Old bathroom scales also contain load cells, but may not be rated high enough for your needs.

I have a little project on the back burner where I intend to use an old Wii Fit to weigh my propane gas bottles to tell me when they’re getting low. Maybe if I could tear myself away from the forum I might actually get the project off the ground.

Pete.

3 Likes

Also check out for a similar project by Nathan Siedle, ex SparkFun CEO. He had it posted somewhere, most likely on their blog. You might learn something.

2 Likes

Here:

Pete.

1 Like

many thanks for the link Pete

This is wonderful that so many people have joined together to help one person get the project working I used to keep bees many years ago but we never had this tec then good luck with the project sounds good Bob - in the UK

1 Like

Hi Everybody,

I’m coming back to you because I still have another issue. I was looking for code samples to use the function modem sleep on my ESP to reduce my current consumption. By using the function WiFi.forceSleepBegin it working find but when I used it with Blynk nothing work correctly. I couldn’t find good example to automatically turn on and off the ESP wifi and send the data with blynk to my mobile.

One topic seems to me good but there is not more details: [SOLVED] Solar Powered Weather Station ESP8266 + Blynk

Many thanks for your help

Can you post your latest code?

Pete.

My code with sleep mode but is on the void loop… I do not know how to automaticlly add in the void setup

#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[] = "***********************";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "****************";
char pass[] = "*****************";



#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;

float t;
float 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, "ruche connectée"); 
  display.drawString(0, 16, "Humidité: " + String(h) + "%\t"); 
  display.drawString(0, 32, "Temp: " + String(t) + "C"); 
  display.drawString(0, 48, "Poids: " + String(weight) + "KG"); 
  display.display();
}
void sendWeight()
{
  
  String weight = String(scale.get_units(1), 2);
  Blynk.virtualWrite(V4, weight);

}

void sendSensor()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V6, t); //virtual pin V6 DHT11
  Blynk.virtualWrite(V5, h); // virtual pin V5 DHT11
  //Blynk.virtualWrite(6, temp2); //virtual pin V7 DHT22
  //Blynk.virtualWrite(5, hum2); // virtual pin V8 DHT22
  //Blynk.virtualWrite(V4, weight); // virtual pin V12
}

void setup(){
  // Initialising the UI will init the display too.
  Serial.begin(115200);
  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(5000L, sendSensor);
  timer.setInterval(5000L, displayTempHumid);
  timer.setInterval(1000L, sendWeight);
 }
 
void loop(){
  Blynk.run();
  timer.run();
  delay(40000);
  Serial.println("déconnecté");
  WiFi.disconnect();
 WiFi.forceSleepBegin();
  delay(20000);
  WiFi.forceSleepWake();
  
}