Detecting external parasites such as Varroa mites is very important To save The bees. In this Project, In this project, I have to build a smart hive, in the hive entry I created a bee counter system using IR LED and Photodiode. once the bee is found entry and counted in the hive, then pure icing sugar is sprinkled over the bee then a small vibration will create to shake the bee, this system helps to remove external Predators entering the hive. a small pure icing sugar sprinkler system and parasites will be created using vibrators .along with this system I created temperature, humidity, and monitor to ensure the condition is suitable for Bee and alerts the caretaker about the variation. to send all these data (Environment data, brood combs status ) to the caretaker, I will use the Arduino MKR WAN 1310 for the LoRa® network.
I have tried to connect the MKR WAN 1310 to TTN But failed constantly and created a Single Channel Blynk-based LoRa Gateway. It transfers all the data to the cloud using MKR1300 And Esp8266.
There are two sections in this project Transmitter and receiver part.
The transmitter part collects data inside the hive and transmits it to the receiver, in parallel it controls all the input and output devices inside the hive.
Receiver Part collects the data from the transmitter using LoRa and Transfers the data to the Blynk App using the wifi module.
Transmitter Part Code
#include <Servo.h>
#include <SPI.h>
#include <LoRa.h>
#include<String.h>
#include "DHT.h"
#define DUMP_REGS
#include <Wire.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
String str;
char cstr[500];
String message = "";
unsigned int mlength; // message length
uint16_t ch0 = 0;
uint16_t ch1 = 1;
float h;
float t;
int sensor1 = 5;
int sensor1_status = 0;
int sensor2 = 4;
int sensor2_status = 0;
int motor = 7;
int shake = 3;
Servo myservo; // create servo object to control a servo
unsigned long _Intial = 0;
const long _interval = 500;
int pos = 0; // variable to store the servo position
void setup() {
pinMode(sensor1,INPUT);
pinMode(sensor2,INPUT);
pinMode(motor,OUTPUT);
pinMode(shake ,OUTPUT);
Serial.begin(9600);
myservo.attach(6); // attaches the servo on pin 9 to the servo object
LoRa.begin(915E6);
dht.begin();
Wire.begin();
delay(500);
}
void loop()
{
while(1)
{
sensor1_status = digitalRead(sensor1);
sensor2_status = digitalRead(sensor2);
temperature();
// message = String(h) +String(",") + String(t)+String(",")+ String(light_data)+String(",")+ String(gx)+String(",");
message = String(h) +String(",") + String(t);
delay(1000);
mlength = (sizeof(message)*4);
str = message;
delay(100);
LoRa.beginPacket();
LoRa.print(str);
delay(100);
Serial.println(str);
LoRa.endPacket(0);
switch (sensor1_status)
{
case 0:
Serial.println("Entry");
digitalWrite(motor,HIGH);
delay(200);
myservo.write(90); // tell servo to go to position in variable 'pos'
delay(1000);
digitalWrite(motor,LOW);
myservo.write(0);
Vibration();
break;
case 1:
Serial.println("NO FOUND Entry");
digitalWrite(motor,LOW);
myservo.write(0); // tell servo to go to position in variable 'pos'
break;
}}
}
void Vibration()
{
for (int AB = 0; AB <= 3 ; AB++) {
digitalWrite(shake,HIGH);
_delay();
digitalWrite(shake,LOW);
_delay();
}
}
void _delay()
{
_Intial = millis();
while((millis() - _Intial) <= _interval)
{
}
}
void temperature()
{
h = dht.readHumidity();
t = dht.readTemperature();
}
Receiver Code
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>
#include "rgb_lcd.h"
#include<String.h>
rgb_lcd lcd;
int colorR = 0;
int colorG = 0;
int colorB = 255;
int data1;
int data2;
int data3;
int data4;
int data5;
String str;
char cstr[100];
String message = "";
unsigned int mlength; // message length
char LoRaData;
void setup() {
lcd.begin(16, 2);
lcd.setRGB(colorR, colorG, colorB);
LoRa.begin(915E6);
Serial.begin(9600);
Serial1.begin(9600);
}
void loop()
{
String str1="",str2="",str3="",str4="",str5="";
int packetSize = LoRa.parsePacket(),i=0,len;
if (packetSize)
{
while (LoRa.available())
{
colorR = 0;
colorG = 255;
colorB = 0;
lcd.setRGB(colorR, colorG, colorB);
str1=str1+((char)LoRa.read());
}
len=str1.length();
if(len-10 > 0)
{
str1=str1.substring(0,len);
str2=str1.substring(0,6);
str3 =str1.substring(6,12);
str4 = str1.substring(12,17);
str5 = str1.substring(18,24);
data1 = str2.toInt();
data2 = str3.toInt();
data3 = str4.toInt();
data4 = str5.toInt();
}
Serial.print("HUM:");
Serial.print(data1);
Serial.println();
Serial.print("Temp:");
Serial.print(data2);
Serial.println();
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.print(data2);
lcd.setCursor(8, 0);
lcd.print("Hum:");
lcd.print(data1);
lcd.setCursor(0, 1);
lcd.print("RSSI:");
lcd.print(LoRa.packetRssi());
Serial.print("RSSI:");
Serial.print(LoRa.packetRssi());
Serial.println();
// lcd.setCursor(0, 1);
// lcd.print("RSSI:");
// lcd.print(LoRa.packetRssi());
//
// lcd.setCursor(8, 1);
// lcd.print("axis:");
// lcd.print(data4);
message = String(data1) +String(",") + String(data2) +String(",")+ String(LoRa.packetRssi()) +String(",") + String(data4) +String(",");
// message = message+ h +"," + t+","+ light_data +","+ gx +",";
delay(1000);
mlength = (sizeof(message)*4);
str = message;
//Serial.print("length:");
//Serial.print(mlength);
//Serial.println();
//str.toCharArray(cstr,mlength);
//Serial1.println(cstr);
Serial.println(str);
Serial1.print(str);
if(data2 >= 35)
{
Serial.println("high temperature");
int colorR = 255;
int colorG = 0;
int colorB = 0;
lcd.setRGB(colorR, colorG, colorB);
lcd.setCursor(0, 1);
lcd.print("High Temperature");
}
else
{
int colorR = 0;
int colorG = 255;
int colorB = 0;
lcd.setRGB(colorR, colorG, colorB);
lcd.setRGB(colorR, colorG, colorB);
lcd.setCursor(0, 1);
lcd.print(" ");
}
}}
Blynk Interfacing Part
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL3R8KVhDTR"
#define BLYNK_TEMPLATE_NAME "Save The Bees Design Challenge"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include<String.h>
#include <SoftwareSerial.h>//libraries needed in communicating with gps and nodemcu
int RXPin = D2;//tx pin of mkr1300 connected to this pin
int TXPin = D1;//rx pin of mkr1300 connected to this pin
SoftwareSerial data_serial(RXPin, TXPin);//declaring the rx,tx pins
int incomingByte = 0;
int data1;
int data2;
int data3;
int data4;
int data5;
String LoRaData;
String jsonBuffer;
float ta;// Temperature details
float ha; // Humidity details
float rs; //Rssi details
char auth[] = "xxxxxxxxxxxxxxxxxx";// Your blynk app token id
char ssid[] = "xxxxxxxxx"; // your Wifi name
char pass[] = "xxxxxxxxxxxxxxxxxx"; // your wifi password
BlynkTimer timer;
void setup() {
Serial.begin(9600);
data_serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop() {
String str1="",str2="",str3="",str4="",str5="";
int i=0,len;
char commandbuffer[400];
if (data_serial.available())
{
delay(500);
while( data_serial.available() && i< 99)
{
commandbuffer[i++] = data_serial.read();
}
//commandbuffer[i++]='\0';
}
Serial.println((char*)commandbuffer);
str1=str1+((char*)commandbuffer);
len=str1.length();
Serial.println(len);
if(len-15 > 0)
{
str1=str1.substring(0,len);
str2=str1.substring(0,2);
str3 =str1.substring(3,5);
str4 = str1.substring(6,9);
str5 = str1.substring(10,15);
data1 = str2.toInt();
data2 = str3.toInt();
data3 = str4.toInt();
data4 = str5.toInt();
}
Serial.print("hum:");
Serial.print(data1);
Serial.println();
Serial.print("temp:");
Serial.print(data2);
Serial.println();
Serial.print("RSSI:");
Serial.print(data3);
Serial.println();
Blynk.virtualWrite(V0,data1);
Blynk.virtualWrite(V1,data2);
Blynk.virtualWrite(V2,data3);
//Blynk.virtualWrite(V3,data4);
Blynk.run();
timer.run();
}
Testing Video