vinay y.nCommon9899Akarsh Agarwal
Published © GPL3+

Harsh Weather Monitoring Using Arduino MKR 1300 With Hammond

Harsh Weather Monitoring Using Arduino MKR 1300 and Blynk

IntermediateFull instructions provided12 hours784
Harsh Weather Monitoring Using Arduino MKR 1300 With Hammond

Things used in this project

Hardware components

Arduino MKR WAN 1300
Arduino MKR WAN 1300
×2
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Grove - Light Sensor
Seeed Studio Grove - Light Sensor
×1
RGB Backlight LCD - 16x2
Adafruit RGB Backlight LCD - 16x2
×1
Rechargeable Battery, Lithium Ion
Rechargeable Battery, Lithium Ion
×1
Analog Accelerometer: ADXL335
Adafruit Analog Accelerometer: ADXL335
×1
Arduino 101
Arduino 101
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Schematics

tx part schematics

rx part

Code

Transmitter Part

Arduino
You need to use Arduino JSON to compile the code
#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
you need to use Arduino JSON to compile the 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;
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

Arduino
#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();
      
}

Credits

vinay y.n

vinay y.n

15 projects • 18 followers
Maker | Hardware Hacker | Electronics Enthusiast
Common9899

Common9899

33 projects • 24 followers
Akarsh Agarwal

Akarsh Agarwal

56 projects • 144 followers
Im an electronics engineering student

Comments

Add projectSign up / Login