Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
Ndeye FAYEThérèse SèneOrden BAKPETEAlexandre GELLIS
Published

Bee-Hive Project : Smart Hive monitoring !

Revolutionize beekeeping with BeeHive Project! Our advanced sensor-equipped system monitors bee colonies, offering precision insights.

IntermediateFull instructions provided793
Bee-Hive Project : Smart Hive monitoring !

Things used in this project

Hardware components

Arduino MKR WAN 1310
Arduino MKR WAN 1310
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×2
Weight sensor
×1
SOL2W solar cell
×1
Lipo Rider Pro
×1
Li-Ion Battery 1000mAh
Li-Ion Battery 1000mAh
×1
Adafruit Waterproof DS18B20 Digital temperature sensor
Adafruit Waterproof DS18B20 Digital temperature sensor
×2
Adafruit TPL5110 Low Power Timer Breakout
×1

Software apps and online services

The Things Stack
The Things Industries The Things Stack
Arduino IDE
Arduino IDE
Ubidots
Ubidots
KiCad
KiCad
Beep Monitor

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Helping Hand Tool, with Magnifying Glass
Helping Hand Tool, with Magnifying Glass
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

KiCAD after routage

Schematics

Electrical Diagram

Code

FINAL CODE

C/C++
Here is the ultimate source code in C++ that consolidates all system components, enabling the retrieval and transmission of data to our platforms.
#include <MKRWAN.h>
#include "DHT.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include "HX711.h"
#include <ArduinoLowPower.h>


// PIN DHT22
#define DHTPIN0 0
#define DHTPIN1 1 
#define DHTTYPE    DHT22
DHT dht1(DHTPIN0, DHTTYPE);
DHT dht2(DHTPIN1, DHTTYPE);

// WEIGHT SENSOR 
#define LOADCELL_DOUT_PIN  11
#define LOADCELL_SCK_PIN  12
HX711 scale;
float calibration_factor = 13350;

//DSP SENSOR
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer1, insideThermometer2;

// LED  allumer au dbut dmarrage 
#define LED_BUILTIN 8

// Pour le calcul de la batterie 
#define pin_mes_batt A0
#define valeur_max_batt 3.17 //680k*4.2/(220k+680k)
#define valeur_min_batt 2.26 //680k*3.0/(220k+680k)
#define tension_alim 3.3

//Pour le calcul de la valeur de la photorsistance 
#define pin_ldr A1
#define valeurDeLaResistanceFixe 10000  //10k en srie avec la photorsistance 
float k= 0.5;

//Connection Lora TTN
LoRaModem modem;
String appEui = "1903200303022001";
String appKey = "91DB73DE6796DF58F5CC6988F52D6057";
bool connected;
int err_count;
short con; 

//Variable  utiliser pour le TPL5110
const int DELAY_PIN = 9;  // Broche "delay"
const int DONE_PIN = 10;   // Broche "done"

void setup() {
  Serial.begin(115200);
  //*********ALLUMAGE DE LA LED AU DEMARRAGE 10 sec*****************//
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);   
  delay(10000);                       
  digitalWrite(LED_BUILTIN, LOW);

  //Calibrage du capteur de poids 
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  scale.set_scale();
  //scale.tare(); //Reset the scale to 0
  long zero_factor = scale.read_average(); 
  scale.set_scale(calibration_factor);
  //scale.set_offset(zero_factor);
  modem.begin(EU868);
  delay(1000);      // apparently the murata dislike if this tempo is removed...
  connected=false;
  err_count=0;
  con =0;
  //Mettre le TPL5110
  pinMode(DELAY_PIN, OUTPUT);
  pinMode(DONE_PIN, OUTPUT);
  // Dsactiver le TPL5110 au dmarrage
  //digitalWrite(DELAY_PIN, LOW);
  //digitalWrite(DONE_PIN, LOW);
}

//Fonction pour activer le TPL5110
void activateTPL5110() {
  digitalWrite(DELAY_PIN, HIGH);  // Activer le dlai du TPL5110
  delay(50);                      // Attendre une courte priode pour permettre au TPL5110 de dtecter le changement
  digitalWrite(DELAY_PIN, LOW); // Dsactiver le dlai du TPL5110
  delay(2000);
  
}
void desactivateTPL5110(){
  digitalWrite(DONE_PIN, HIGH);  // Activer le TPL5110
  delay(50); // Attendre la dure spcifie en millisecondes
  digitalWrite(DONE_PIN, LOW);   // Dsactiver le TPL5110
}

void loop() {
  if ( !connected ) {
    Serial.print("Join test : ");
    Serial.println(++con);
    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;
      
    }
  }
  if ( connected ) {
    //activateTPL5110();
    // Mesure de la tension de la batterie sur la broche A0
    int valeur_batt = analogRead(pin_mes_batt); // Mesure de la tension de la batterie sur la broche A0
    float tension = (valeur_batt*tension_alim)/1023.0; // Transforme la mesure (nombre entier) en tension via un produit en croix, 1024 = Valeur max pour 5.79 du convertisseur
    float Pourcent=(tension-valeur_min_batt)/(valeur_max_batt-valeur_min_batt)*100; 
    short pourcent_ = (short)(Pourcent);

    // DHT22 INTERIEUR
    dht1.begin();
    float temp1=dht1.readTemperature();
    float hum1=dht1.readHumidity();
    short h1 = (short)(hum1*100); //Valeur  envoyer via LoraWaN
    short t1 = (short)(temp1*100);

    // DHT22 EXTERRIEUR
    dht2.begin(); 
    float temp2 = dht2.readTemperature();
    float hum2 = dht2.readHumidity();
    short h2 = (short)(hum2*100);
    short t2 = (short)(temp2*100);

    //Capteur de lumire LDR
    int val_R_fixe= analogRead(pin_ldr);
    float tension_photo=(val_R_fixe*tension_alim)/1023.0;
    long LDR = valeurDeLaResistanceFixe * (tension_alim - tension_photo) / tension_photo; // Valeur de la rsistance LDR
    float Lux = pow(valeurDeLaResistanceFixe/LDR,1.0/k );  //calcul pour convertir en lux 
    short lux=(short)(Lux*100);
    
    //VARIABLE POUR MESURER BDSP19B20 //
    sensors.begin();
    sensors.getAddress(insideThermometer1, 0);
    sensors.getAddress(insideThermometer2, 1);
    sensors.requestTemperatures();
    float temperature0 =  sensors.getTempC(insideThermometer1);
    float temperature1 = sensors.getTempC(insideThermometer2);
    short t_0 = (short)(temperature0*100);
    short t_1 = (short)(temperature1*100);

    //VARIABLE POUR MESURER LE POIDS //
    float poids = (scale.get_units()/2.2046)-4.4;
    short weight_kg = (short)(poids*100);
    
    //Envoie des donnes sur TTN
    int err=0; 
    modem.beginPacket(); 
    modem.write(t1);
    modem.write(t2);
    modem.write(h1);
    modem.write(h2);
    modem.write(t_0);
    modem.write(t_1);
    modem.write(weight_kg);
    modem.write(pourcent_);
    modem.write(lux);
    err = modem.endPacket();

    if ( err <= 0 ) {
      Serial.print("Error : ");
      Serial.println(err);
      // 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;
      //delay(20000);
      Serial.println("Message envoy");   
      LowPower.sleep(600000);
      //desactivateTPL5110();
    }
    //Afficher les valeurs dans le moniteur srie pour les tests
    Serial.println("Temperature DHT22 intrieure = " +String(t1) +" C");
    Serial.println("Temperature DHT22 extrieure = " + String(t2) +" C");
    Serial.println("Humidite DHT22 intrieure = " + String(h1) +" %");
    Serial.println("Humidite DHT22 extrieure = " + String(h2) +" %");
    Serial.println("Temperature1 BDSP19B20 = " + String(temperature0) +" C");
    Serial.println("Temperature2 BDSP19B20 = " + String(temperature1) +" C");
    Serial.println("Poids = " + String(poids) +" kg");
    Serial.println("Tension batt = " + String(tension) +" V");
    Serial.println("Pourcentage batt = " + String(Pourcent) +" %");
    Serial.println("Valeur LDR= " + String(LDR) +"Ohms");
    Serial.println("Valeur en lux= " + String(Lux) +"Lux");
  }
}

Github

Credits

Ndeye FAYE
1 project • 1 follower
Thérèse Sène
1 project • 1 follower
Orden BAKPETE
1 project • 1 follower
Alexandre GELLIS
1 project • 1 follower
Apprenti ingénieur en EII à POLYTECH SORBONNE. Passionné de sport et d'entrepreneuriat, je fusionne technologie et passion pour le SMMA.

Comments