yasmineJelassiEI2Iachraf mosbahFaouez BEN FREDJ
Published

BeeConnect

An embedded system that allows beekeepers to monitor their hives wherever they are, in real time through the cloud

IntermediateWork in progress422
BeeConnect

Things used in this project

Hardware components

DHT22 Temperature Sensor
DHT22 Temperature Sensor
×2
Adafruit Waterproof DS18B20 Digital temperature sensor
Adafruit Waterproof DS18B20 Digital temperature sensor
×2
SparkFun Power Cell - LiPo Charger/Booster
SparkFun Power Cell - LiPo Charger/Booster
×1
Resistor 100k ohm
Resistor 100k ohm
×1
Through Hole Resistor, 40.2 kohm
Through Hole Resistor, 40.2 kohm
×1
Rechargeable Battery, 3.7 V
Rechargeable Battery, 3.7 V
×1
Solar Panel, 2.5 W
Solar Panel, 2.5 W
×1
Arduino MKR WAN 1310
Arduino MKR WAN 1310
×1
LoRa LoRaWAN Gateway
Seeed Studio LoRa LoRaWAN Gateway
×1
weight sensor
×1

Software apps and online services

Ubidots
Ubidots
The Things Stack
The Things Industries The Things Stack
Arduino IDE
Arduino IDE
beep
KiCad
KiCad

Hand tools and fabrication machines

PCB Holder, Soldering Iron
PCB Holder, Soldering Iron
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Solder Wire, Lead Free
Solder Wire, Lead Free
Breadboard, 270 Pin
Breadboard, 270 Pin
Plier, Cutting
Plier, Cutting
Tape, Electrical
Tape, Electrical
Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Custom parts and enclosures

Electrical Schematic

Code

Global.ino

Arduino
This is the global code that allows us to get the system started (all sensors) and send Data to TTN
/****************************************************** Bibliothques **********************************************************/
#include <MKRWAN.h>
#include <Wire.h>
#include <DHT.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include "HX711.h"
#include "DFRobot_INA219.h"
#include "ArduinoLowPower.h"
/************************************************* Dclarations de pins **********************************************************/
#define brocheBranchementDHT1 5   // Si la ligne de donnes du DHT22 est branche sur la pin D6 de votre Arduino, par exemple
#define brocheBranchementDHT2 7
#define typeDeDHT DHT22          // Si votre DHT utilis est un DHT22 (mais cela pourrait aussi bien tre un DHT11 ou DHT21, par exemple)
#define analogPin A3
#define ONE_WIRE_BUS 4
const int LOADCELL_DOUT_PIN = 1;
const int LOADCELL_SCK_PIN = 0;
/************************************************** Dclarations de variables ****************************************************/
float ina219Reading_mA = 1000;
float extMeterReading_mA = 1000;

DHT dht1(brocheBranchementDHT1, typeDeDHT);
DHT dht2(brocheBranchementDHT2, typeDeDHT);

OneWire oneWire(ONE_WIRE_BUS); 

DallasTemperature sensors(&oneWire);

HX711 scale;

DFRobot_INA219_IIC     ina219(&Wire, INA219_I2C_ADDRESS4);

LoRaModem modem;
/************************************************** Connexion  la carte ****************************************************/
//#include "arduino_secrets.h" 
String appEui = "9100000000000000";
String appKey = "08FB556EB3FD0C65E8C1D899AB94E83C";
bool connected;
int err_count;
int con; 
/************************************************** Setup ****************************************************/
void setup() { 
  pinMode(LED_BUILTIN, OUTPUT);   //LED_BUILTIN as an output.
  Serial.begin(115200);
  
  //while (!Serial);
  Serial.println("Welcome to MKR WAN 1300/1310 first configuration sketch");
  Serial.println("Register to your favourite LoRa network and we are ready to go!");
  modem.begin(EU868);
  delay(1000);      // apparently the murata dislike if this tempo is removed...
  connected=false;
  err_count=0;
  con =0;  
  
  dht1.begin();
  dht2.begin();
  
  sensors.begin(); 
  digitalWrite(LED_BUILTIN, HIGH);    // turn the LED on (HIGH is the voltage level)
  delay(3000);     // wait for 3 seconds
  digitalWrite(LED_BUILTIN, LOW);


  
  scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);
  //scale.set_scale(23955.f);                      // this value is obtained by calibrating the scale with known weights; see the README for details
  scale.set_scale(23450);                      // this value is obtained by calibrating the scale with known weights; see the README for details

  scale.tare();               // reset the scale to 0
  long zero_factor = 13100;
  scale.set_offset(zero_factor);

  while(ina219.begin() != true) {
        Serial.println("INA219 begin failed");
        delay(2000);
  }
  ina219.linearCalibrate(ina219Reading_mA, extMeterReading_mA);
}
/************************************************** Loop ****************************************************/
void loop() {
  char msg[2] = {0,1};
  
  // Lecture des donnes
  float tauxHumidite1 = dht1.readHumidity();              // Lecture du taux d'humidit (en %)
  float temperatureEnCelsius1 = dht1.readTemperature();   // Lecture de la temprature, exprime en degrs Celsius
  
  float tauxHumidite2 = dht2.readHumidity();              // Lecture du taux d'humidit (en %)
  float temperatureEnCelsius2 = dht2.readTemperature();   // Lecture de la temprature, exprime en degrs Celsius

  sensors.requestTemperatures();

  float poids = scale.get_units();   // Lecture de la temprature, exprime en degrs Celsius

  float val = 0;  // variable pour stocker la valeur lue
  float resultat= 0; // le resultat en volt
  short pourcentage=0; //la charge de la batterie en pourcentage
  val = analogRead(analogPin);  
  resultat = (val*3/930);  
  pourcentage =(short)((resultat*100/3));

  float BusVoltage = ina219.getBusVoltage_V();
  float ShuntVoltage = ina219.getShuntVoltage_mV();
  float Current = ina219.getCurrent_mA(); 
  float Power = ina219.getPower_mW();

  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 ) {
  // Affichage des valeurs
  Serial.print("Humidit DHT intrieure = "); Serial.print(tauxHumidite1); Serial.println(" %");
  Serial.print("Temprature DHT intrieure = "); Serial.print(temperatureEnCelsius1); Serial.println(" C");

  Serial.print("Humidit DHT extrieure = "); Serial.print(tauxHumidite2); Serial.println(" %");
  Serial.print("Temprature DHT extrieure = "); Serial.print(temperatureEnCelsius2); Serial.println(" C");

  Serial.print("TempratureSonde1 = "); Serial.print(sensors.getTempCByIndex(0)); Serial.println(" C");
  Serial.print("TempratureSonde2 = "); Serial.print(sensors.getTempCByIndex(1)); Serial.println(" C");

  Serial.print("Poids = "); Serial.print(poids); Serial.println("Kg");

  Serial.print("val : ");  Serial.println(val);
  Serial.print("Pourcentage batterie : ");  Serial.println(pourcentage);

  Serial.print("BusVoltage:   "); Serial.print(BusVoltage, 2); Serial.println("V");
  Serial.print("ShuntVoltage: "); Serial.print(ShuntVoltage, 3); Serial.println("mV");
  Serial.print("Current:      "); Serial.print(Current, 1);Serial.println("mA");
  Serial.print("Power:        "); Serial.print(Power, 1);Serial.println("mW");

  Serial.println();
    short temp1 = (short)(temperatureEnCelsius1*100);
    short hum1 = (short)(tauxHumidite1*100);

    short temp2 = (short)(temperatureEnCelsius2*100);
    short hum2 = (short)(tauxHumidite2*100);

    short tempo1 = (short)(sensors.getTempCByIndex(0)*100);
    short tempo2 = (short)(sensors.getTempCByIndex(1)*100);

    short po = (short)(poids*100);

    short bat= (short)(pourcentage*100);

    short powe= (short)(Power*100);
    
    int err=0;
    modem.beginPacket();
    
   // modem.write(msg,2);
    modem.write(temp1);
    modem.write(hum1);

    modem.write(temp2);
    modem.write(hum2);

    modem.write(tempo1);
    modem.write(tempo2);

    modem.write(po);

    modem.write(bat);

    modem.write(powe);
    
    err = modem.endPacket(true);
    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;
      // wait for 20s for duty cycle with SF7 - 55ms frame
      delay(100);
      LowPower.deepSleep(599900);
    }
  }
}

Payload fomatter on TTN that allows us to send Data to Ubidots

C/C++
Ubidots was used as the main HMI in the first place, but since it is not possible as a basic use to receive a lot of types od data, we decided to send our Data on Beep
function decodeUplink(input) {
   var decoded = {};
   
   decoded.temperatureinterieure = ((input.bytes[1] << 8) + input.bytes[0])/100;
   decoded.humiditeinterieure = ((input.bytes[3] << 8) + input.bytes[2])/100;
   
   decoded.temperatureexterieure = ((input.bytes[5] << 8) + input.bytes[4])/100;
   decoded.humiditeexterieure = ((input.bytes[7] << 8) + input.bytes[6])/100;
   
   decoded.temperaturesonde1 = ((input.bytes[9] << 8) + input.bytes[8])/100;
   decoded.temperaturesonde2 = ((input.bytes[11] << 8) + input.bytes[10])/100;

   decoded.poids = ((input.bytes[13] << 8) + input.bytes[12])/100;

   decoded.batterie = ((input.bytes[15] << 8) + input.bytes[14])/100;
   
   decoded.power = ((input.bytes[17] << 8) + input.bytes[16])/100;
  
  return {
    data: decoded,
    warnings: [],
    errors: []
  };
}

Payload fomatter on TTN that allows us to send Data to Beep

C/C++
function decodeUplink(input) {
   var decoded = {};
   
   
   decoded.key="qktf6zp9ka8qb1ll";
   
   decoded.t_0 = ((input.bytes[1] << 8) + input.bytes[0])/100;
   decoded.h_i = ((input.bytes[3] << 8) + input.bytes[2])/100;
   
   decoded.t_1 = ((input.bytes[5] << 8) + input.bytes[4])/100;
   decoded.h = ((input.bytes[7] << 8) + input.bytes[6])/100;
   
   decoded.t_2 = ((input.bytes[9] << 8) + input.bytes[8])/100;
   decoded.t_3 = ((input.bytes[11] << 8) + input.bytes[10])/100;

   decoded.weight_kg = ((input.bytes[13] << 8) + input.bytes[12])/100;

   decoded.bv = ((input.bytes[15] << 8) + input.bytes[14])/100; 
   decoded.l = ((input.bytes[17] << 8) + input.bytes[16])/100;
   
  return {
    data: decoded,
    warnings: [],
    errors: []
  };
}

Credits

yasmineJelassiEI2I
1 project • 0 followers
Contact
achraf mosbah
1 project • 0 followers
Contact
Faouez BEN FREDJ
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.