A Connected Hive

by UnCanard in Circuits > Arduino

2739 Views, 33 Favorites, 0 Comments

A Connected Hive

DSC_5253-scaled.jpg

A connected hive is a type of bee hive that uses technology to monitor the health and behavior of the bees inside. This is done through the use of sensors and other devices that are placed inside the hive.

The sensors are able to collect data on a variety of factors, such as the temperature inside the hive, the amount of honey being produced, and the activity levels of the bees. This data is then sent to a central database, where it can be analyzed by beekeepers and researchers.

One of the main benefits of a connected hive is that it allows beekeepers to monitor the health of their bees in real time. This can help them to identify problems early on and take action to address them, which can improve the overall health of the hive.

Additionally, the data collected by connected hives can be used to study the behavior of bees and better understand how they function. This can help researchers to develop new strategies for improving bee health and supporting the growth of healthy populations of bees.

Overall, connected hives offer a new way of studying and caring for bees, and they have the potential to revolutionize the way we manage these important pollinators.

Supplies

Hello World With TTN

We will use an arduino MKR WAN 1310 to send all the data from our sensors. It will use the lora network to send the values, this network allows to send data at long distance but with a very low flow. This network is very used in the world of IOT.

First we need to creat a account on the things network.

The Things Network is a community network based on LoRa technology that complies with the LoRaWAN standard. This technology allows objects to transmit small amounts of information while consuming very little energy. The community deploys gateways connected to the Internet.

  1. Create an account on TTN
  2. Create an application
  3. Registering a Device

Follow the official doc for more details:

https://docs.arduino.cc/tutorials/mkr-wan-1310/the-things-network

Make sure there is a gateway near the arduino

To send data from the arduino you can use this code :

#include <MKRWAN.h>
/*information for connection in LoraWan*/
LoRaModem modem;
char output[64];
String appEui = "0000000000000000";
String appKey = "4D740505194EA0BEE9F6EF3A786F5A64";

bool connected;
int err_count;
int con;
short value1, value2, value3 = 3; // data to send


void setup() {
   //Initialisaion Lora
   modem.begin(EU868);
}

void loop() {
 if ( !connected ) {
   int ret=modem.joinOTAA(appEui, appKey);
   if ( ret ) {
     connected=true;
     modem.minPollInterval(60);
     Serial.println("Connected");
     modem.dataRate(5);  // switch to SF7
     delay(100);         // because ... more stable
     err_count=0;
   }
 }
 con++;
 Serial.print("Join test : ");
 Serial.println(con);

 if ( connected ) {
   int err=0;
/*Envoie des valeurs*/
   modem.beginPacket();
   modem.write(value1);
   modem.write(value2);
   modem.write(value3);
   err = modem.endPacket(true); //Send packet

/*confirmation of transmission*/
   if ( err <= 0 ) {
     // Confirmation not received - jam or coverage fault
     err_count++;
     if ( err_count > 50 ) {
       connected = false;
     }
     // wait for 2min for duty cycle with SF12 - 1.5s frame
     for ( int i = 0 ; i < 120 ; i++ ) {
       delay(1000);
     }
   } else {
     err_count = 0;     
   }
 }
}

Connect All Sensors

Abeillez_Interupteur_bb.png
DHT22_Connection.PNG
DS18B20_connection.PNG
H40A_connection.PNG
HX711_connection.PNG
signal-2023-01-18-094031_002.jpeg

The set of pictures shows how to connect the components. Moreover, with the general connection diagram, you can see how to put the switch, the resistors and the Lipo Rider

We assemble the measuring gauge with two metal structures. This set will be placed under the beehive to measure its weight.

We connect the measuring gauge with the X711 Grove 101020712 amplifier.

Program All Sensors


DHT22 Temperature Sensor

#include <DHT.h>

#define PIN 6
#define DHTTTYPE DHT22

DHT dht(PIN, DHTTTYPE);

void setup() {
dht.begin();
}
void loop(){
/*reading data from the sensor*/
Serial.println(dht.readTemperature());
Serial.println(dht.readHumidity());
}



Waterproof DS18B20

// Sensor of the temperature DS18B20
uint8_t address_DS18B20[8];
DS18B20 ds(3);
int nbrCapteurTempDS18B20 = 2;
float tabTempDS18B20[2]; // one wire sensor table

void setup() {

}
void loop(){
tempDS18B20();
  for(int i = 0; i < nbrCapteurTempDS18B20; i++){
    Serial.println(tabTempDS18B20[i]); //reading the value of the component i
  }  
}

void tempDS18B20(void){
  int j = 0;
  for(int i = 0; i < 2; i++){
    tabTempDS18B20[nbrCapteurTempDS18B20] = -1;
  }
 
  while(ds.selectNext()){
    
    ds.getAddress(address_DS18B20);
    Serial.print("Address:");
    
    for (uint8_t i = 0; i < 8; i++) {
      Serial.print(" ");
      Serial.print(address_DS18B20[i]); 
    }
    Serial.print("\n");
    tabTempDS18B20[j] = ds.getTempC();
    Serial.print("Temperature: ");
    Serial.println(tabTempDS18B20[j]);
    j=j+1;
  }
}


Single point load cell H40A & Amplificateur HX711 Grove 101020712


#include <HX711.h>

// HX711 circuit wiring
const int LOADCELL_DOUT_PIN = 1;
const int LOADCELL_SCK_PIN = 2;
const float TARE = 133024;

//definition for the weight
HX711 scale;

void setup() {
//Initialisation of the sensor of the weight
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
}
void loop(){
Serial.println(poids()); //reading the value
}

float poids (void){
  scale.power_up(); // wake up the sensor
  float reading = (scale.read()- TARE)/28413;
  if(reading < 0) reading = 0;
  Serial.print("poids reading : ");
  Serial.println(reading);
  scale.power_down(); // power down to save power
  return reading;
}


Power Supply by Solar Pannel

Accu Li-Ion 3,7 V 1050 mAh PR474446 + Lipo Rider Pro + Cellule solaire SOL2W

We have added a LipoRider board to power our arduine board. It manages the battery management, we can connect a solar panel to it.

To save energy, I use our system in deep sleep mode. The autonomy increases from a few days to more than a month.

//Low power mode in Arduino
#include "ArduinoLowPower.h"

void loop(){
/*
main program
*/

// go in low power mode
   LowPower.deepSleep(600000); // 3min for the test  || 1000 * 60 * 60 * 24 = 3600000 for 1 measurement / hour  (3min)
   delay(1000);  // Time to fully wake up the card
}

Creat PCB

signal-2022-12-12-112354.jpeg

After connecting all our sensors and finishing our prototype on the breadboard we can develop its PCB.

First you need to install Kikad to draw your own card. If you want a share my prototype of PCB here.

At the end you can print on your on drill or you can use a drilling company like pcbway.

Connect TTN to Beep

Untitled.png
Screenshot 2023-01-04 at 19-24-37 BEEP Moniteur abeille.png

Now we need to send all our measurements to beep so that they can be recorded and displayed on several graphs. To do that we need to implement each block in blue of the first attached diagram.

I) The first block is used to

Convert our binary frame to an integer.

  1. Go to TTN
  2. Go to your application -> endDivices -> payload-formatters -> uplink
  3. Set "Formatter type" to: "Custom Javascript formatter"
  4. Follow the names of the variables given by beep
  5. We'll see later where to find it but it's the key to our beep hive
  6. Creat Payload formater
function decodeUplink(input) {
  var decoded = {};
  decoded.key ="0sd6rz7kll3zcq0s";
 
  decoded.bv = (input.bytes[1] << 8 | (input.bytes[0])) / 100; // battery
  decoded.weight_kg = (input.bytes[3] << 8 | (input.bytes[2])) / 100; // weight
  decoded.t = (input.bytes[5] << 8 | (input.bytes[4])) / 100; // temp1
  decoded.t_0 = (input.bytes[7] << 8 | (input.bytes[6])) / 100; // temp2
  decoded.t_1 = (input.bytes[9] << 8 | (input.bytes[8])) / 100; // temp3
  decoded.h = (input.bytes[11] << 8 | (input.bytes[10])) / 100; // hum 1
  decoded.t_3 = (input.bytes[13] << 8 | (input.bytes[12])) / 100; //temp
  decoded.h_i = (input.bytes[15] << 8 | (input.bytes[14])) / 100; // hum 2
  decoded.l = (input.bytes[17] << 8 | (input.bytes[16])) / 100; // luminosity

  return {
    data: decoded,
  };
}


II) The second block is used to format the data sent by TTN to format them for beep. (Normally bepp understands TTN frames but I couldn't get it to work).

  1. On a server of your choice (AZUR, AWS) create a REST API which has as URI serverAdress/ttnToBeep
  2. Add formatter
  3. Recover only the "decoded_payload"
  4. function format(message){return message.uplink_message.decoded_payload;}
  5. Add a weebhook on TTN
  6. Go to application -> Integrations -> Weebhooks
  7. Click on "Add custom webhook"
  8. Give a Weebhook ID to your weeb hook ex: beep
  9. In "Base URL" add the endpoint of your server
  10. Tick uplick message to POST data when the device send datas
  11. You need Bearer Token nous pour nous identifier nous allons voir dans la partie III.2 comment le récuprer.
  12. When the message is received, make a POST request to "https://api.beep.nl/api/lora_sensors?key=0sd6rz7kll3zcq0s"
  13. with the key parameter that we added to the TTN payload formatter. More information here


III) For the last block for the last block which allows us to visualize our data on beep, we need to creat a acount on Beep. And add a mesurement device

  1. Creat account on beep
  2. At the connection we can retrieve the Bearer token with the network part of our browser
  3. Click on the hamburger menu on the top left corner
  4. Go to "Devices" section
  5. Creat new device with the "add own device"
  6. Give a name to your hive
  7. Copy the "Device unique identifier"
  8. Return to the "Payload Formatters" of TTN and copy your device unique identifier

Integration

signal-2023-01-18-093840.jpeg
signal-2023-01-18-093742_004.jpeg
vlcsnap-2023-01-13-11h16m33s603.png

I put all the components in a waterproof junction box. The sensors pass through glands. I put all the sensors in the right places in the hive.


Do not hesitate to contact me for any question