In The previous Blog, I have tested the Hammond Enclosure Case using Water. The Results of the experiment concluded that the device will be not affected by the water due to its High-Quality Water and Dust Resistant Design. By taking the advantage of enclosure case I have used it to place my circuit inside the box And Tested Them for a couple of days In an open space, the devices are not affected by fog and dust, and high temperature.
Working Of The Final Project
I have made Two sections in this project, the Transmitter section, and Receiver section.
Transmitter Part
The Transmitter section contains The Temperature, Humidity sensor, Light sensor, Mems Microphone, Mems Accelerometer sensor. These sensors are interfaced with the Arduino MKR 1300 Board along with The external antenna. A lithium battery is used to power all the sensors and Microcontroller, this battery is able to standby for up to 7 days in this project. To protect the circuit from the harsh weather I have used Hammond Enclosure Case 1554UGY Water Tight ABS 200x120x90 Enclosure. The sensor details are collected and transmitted Over LoRa Using Arduino MKR 1300.
Transmitter Section Block Diagram
Transmitter Part Device
Receiver Section
The receiver part contains the Arduino MKR 1300 And Wi-Fi Module To receive the LoRa Data and Transmit the data again to the cloud Using the Internet, I call It has Gateway.
Receiver Block Diagram
Receiver Device
The LoRa Data is received And The Sensor details are collected Using the Arduino MKR 1300, if there is any severe variation in the environment data and its crosses the threshold values, The details are displayed on the app parallel shown on the LCD display.
If the temperature of the surrounding environment is high, The Buzzer will be ON in the receiver section and The LCD Turns RED, To notify the user, and Pop-up Notification displayed on the mobile.
When the box is opened or it broke the light intensity data of the sensor is high, then it will be finalized as the Box Opened and the Pop-Up Notification is displayed on the mobile.
During The operation when the transmitter is moved or if any high wind is detected a "Movement Detected" notification is displayed on the Mobile and in the receiver part Buzzer is activated with a different tone. This tone is different from The High-Temperature Alert.
In this project, I have used Blynk App to display the sensor details.
Schematic Diagrams
Transmitter
Receiver
CODES
Transmitter Part
#include <SPI.h>
#include <LoRa.h>
#include<String.h>
#include "DHT.h"
#define DUMP_REGS
#include <Wire.h>
#include "MPU6050.h"
#include <APDS9930.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
String str;
char cstr[500];
String message = "";
unsigned int mlength; // message length
APDS9930 apds = APDS9930();
float ambient_light = 0; // can also be an unsigned long
uint16_t ch0 = 0;
uint16_t ch1 = 1;
float light_data;
float h;
float t;
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
void setup()
{
Serial.begin(9600);
LoRa.begin(915E6);
dht.begin();
Wire.begin();
accelgyro.initialize();
if ( apds.init() )
{
Serial.println(F("APDS-9930 initialization complete"));
}
else
{
Serial.println(F("Something went wrong during APDS-9930 init!"));
}
// Start running the APDS-9930 light sensor (no interrupts)
if ( apds.enableLightSensor(false) ) {
Serial.println(F("Light sensor is now running"));
} else {
Serial.println(F("Something went wrong during light sensor init!"));
}
#ifdef DUMP_REGS
/* Register dump */
uint8_t reg;
uint8_t val;
for(reg = 0x00; reg <= 0x19; reg++) {
if( (reg != 0x10) && \
(reg != 0x11) )
{
apds.wireReadDataByte(reg, val);
Serial.print(reg, HEX);
Serial.print(": 0x");
Serial.println(val, HEX);
}
}
apds.wireReadDataByte(0x1E, val);
Serial.print(0x1E, HEX);
Serial.print(": 0x");
Serial.println(val, HEX);
#endif
delay(500);
}
void loop()
{
while(1)
{
accelgyro.getRotation(&gx, &gy, &gz);
light_details();
temperature();
message = String(h) +String(",") + String(t)+String(",")+ String(light_data)+String(",")+ String(gx)+String(",");
// message = message+ h +"," + t+","+ light_data +","+ gx +",";
delay(1000);
mlength = (sizeof(message)*4);
str = message;
delay(100);
LoRa.beginPacket();
LoRa.print(str);
delay(100);
Serial.println(str);
LoRa.endPacket(0);
}
}
void light_details()
{
if ( !apds.readAmbientLightLux(ambient_light) ||
!apds.readCh0Light(ch0) ||
!apds.readCh1Light(ch1) ) {
Serial.println(F("Error reading light values"));
}
else {
light_data = ambient_light;
}
}
void temperature()
{
h = dht.readHumidity();
t = dht.readTemperature();
}
Receiver Part
Arduino MKR 1300 Part
#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;
int buzzer = 5;
String str;
char cstr[100];
String message = "";
unsigned int mlength; // message length
char LoRaData;
void setup() {
lcd.begin(16, 2);
pinMode(buzzer,OUTPUT);
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();
Serial.print("light:");
Serial.print(data3);
Serial.println();
Serial.print("AXIS:");
Serial.print(data4);
Serial.println();
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.print(data2);
lcd.setCursor(8, 0);
lcd.print("Hum:");
lcd.print(data1);
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(data3) +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 >= 30)
{
Serial.println("high temperature");
digitalWrite(buzzer,HIGH);
int colorR = 255;
int colorG = 0;
int colorB = 0;
lcd.setRGB(colorR, colorG, colorB);
lcd.setCursor(0, 1);
lcd.print("High Temperature");
}
else
{
digitalWrite(buzzer,LOW);
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(" ");
}
if(data4 >=800 || data4 <0)
{
digitalWrite(buzzer,HIGH);
delay(250);
digitalWrite(buzzer,LOW);
delay(250);
digitalWrite(buzzer,HIGH);
delay(250);
digitalWrite(buzzer,LOW);
}
}}
Wi-Fi Module Part
#define BLYNK_PRINT Serial
#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[] = "xxxxxxxxxxxxx";// Your blynk app token id
char ssid[] = "xxxxxxxxxxxx"; // your Wifi name
char pass[] = "xxxxxxxxxxxxxxx"; // 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,8);
str5 = str1.substring(9,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("Light:");
Serial.print(data3);
Serial.println();
Serial.print("axis:");
Serial.print(data4);
Serial.println();
Blynk.virtualWrite(V0,data1);
Blynk.virtualWrite(V1,data2);
Blynk.virtualWrite(V2,data3);
Blynk.virtualWrite(V3,data4);
Blynk.run();
timer.run();
}
Project Working Video