Aptanta Pratiangga 29744
Published

Simple Weather monitoring With Lora, Arduino and Sensors

A small cool and very informative project, to show "how Long range radio system can work with sensors"

IntermediateProtip1,094
Simple Weather monitoring With Lora, Arduino and Sensors

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×2
LORA RFM95
×2
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Ldr Sensor
×1
MyOctopus i2c Barometric Air Pressure Sensor BMP280
MyOctopus i2c Barometric Air Pressure Sensor BMP280
×1
5 mm LED: Red
5 mm LED: Red
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Solder Flux, Soldering
Solder Flux, Soldering
PCB Holder, Soldering Iron
PCB Holder, Soldering Iron

Story

Read more

Schematics

Schematics For Lora Reciever

Connect As per Schematics

Schematics For Lora Sender

Connect As Per Schematics

Code

Lora Sender Code

Arduino
Upload The Code To Lora Sender
#include <SPI.h>
#include <LoRa.h>

#include "DHT.h"
#include <Adafruit_BMP280.h>

#define DHTPIN 7
#define DHTTYPE DHT11
Adafruit_BMP280 bmp; 

float Pressure;
float Altitude;
int ldr = 4;
int counter = 0;
int Dummyvalue;

DHT dht(DHTPIN, DHTTYPE);
long randNumber; //Create Random Number To Avoid Transmission Loss For First Digit

void setup() 
{
  Serial.begin(115200);
  
 randomSeed(analogRead(0));
 dht.begin();
 
if (!bmp.begin()) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }

   pinMode(ldr, OUTPUT);
  while (!Serial);
  
  Serial.println(" Lora Weather Station By ZenoModiff ");

  if (!LoRa.begin(915E6)) {
    Serial.println("Starting LoRa failed!");
  }
  else
  {
   Serial.println("Starting LoRa Sucesses!");
  }
}
void loop()
{
 Serial.println();
 Serial.print("Sending packet: ");
 Serial.println(counter);
 randNumber = random(1000);

 
 int randNumber = random(100); Dummyvalue = randNumber;
 double ldrvalue = analogRead(ldr);
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 float f = dht.readTemperature(true);
 float pressure = (bmp.readPressure()/100); Pressure = pressure;
 int altitude =  (bmp.readAltitude(1019.66)); Altitude = altitude; 
  

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  String Datastring = String(Dummyvalue) + (";") + String(t) + (";") + String(h) + (";") + String(ldrvalue) + (";") + String (Pressure) + (";") + String (Altitude);
 
  Serial.println(Datastring);
  LoRa.beginPacket();      
  LoRa.print(Datastring);
  LoRa.print(counter);
  LoRa.endPacket();
  counter++;
  
  delay(3000);
  
}

Lora Reciever Code

Arduino
Upload The Code To Lora Reciever
#include <Wire.h> 
#include <SPI.h>
#include <LoRa.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() 
{  
  
  Serial.begin(115200);

  lcd.begin();
  lcd.setCursor(0,0);
  lcd.print("LoRa Weather");
  lcd.setCursor(0,3);
  lcd.print("Station");
  delay(2000);
  lcd.clear();
  lcd.print("By : Aptanta");
  lcd.setCursor(0,3);
  lcd.print("NIM : 2033429744");
  delay (2000);
  while (!Serial);

  Serial.println("LoRa Receiver By : Aptanta");

  if (!LoRa.begin(915E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
  
  String packet = "";
  
  int packetSize = LoRa.parsePacket();
  if (packetSize) {

    Serial.print("Received packet :-- ");

    while (LoRa.available()) {
    
    packet = LoRa.readString();
    }
    
    Serial.println(packet);
    Serial.println();

int firstcommaIndex   = packet.indexOf(';');
int secondCommaIndex  = packet.indexOf(';', firstcommaIndex+1);
int thirdCommaIndex   = packet.indexOf(';', secondCommaIndex+1);
int fourthCommaIndex  = packet.indexOf(';', thirdCommaIndex+1);   
int fifthCommaIndex   = packet.indexOf(';', fourthCommaIndex+1);
int sixthCommaIndex   = packet.indexOf(';', fifthCommaIndex+1);

String firstValue  =  packet.substring( 0, firstcommaIndex);
String secondValue =  packet.substring(firstcommaIndex+1, secondCommaIndex);
String thirdValue  =  packet.substring(secondCommaIndex+1, thirdCommaIndex);
String fourthValue =  packet.substring(thirdCommaIndex +1, fourthCommaIndex);
String fifthValue  =  packet.substring(fourthCommaIndex+1, fifthCommaIndex);
String sixthValue  =  packet.substring(fifthCommaIndex+1,  sixthCommaIndex);

Serial.print("Temp:-"); Serial.println(secondValue);
Serial.print("Humi:-"); Serial.println(thirdValue);
Serial.print("Ldr:-"); Serial.println(fourthValue); 
Serial.print("Pressure:-"); Serial.println(fifthValue);  
Serial.print("Altitude:-"); Serial.println(sixthValue); 
Serial.println();

/*since we can't print the first digit 
it is a dummy value sent by the LoRa String 
in case of transmission Loss*/

lcd.clear(); lcd.setCursor(0,0);
lcd.print("Temp:-"); lcd.println(secondValue);
delay(2000);

lcd.clear(); lcd.setCursor(0,0);
lcd.print("Humi:-"); lcd.println(thirdValue);
delay(2000);

lcd.clear(); lcd.setCursor(0,0);
lcd.print("Ldr:-"); lcd.println(fourthValue);
delay(2000);

lcd.clear(); lcd.setCursor(0,0);
lcd.print("Pres:-"); lcd.println(fifthValue);
delay(2000);

lcd.clear(); lcd.setCursor(0,0);
lcd.print("Alti:-"); lcd.println(sixthValue);
delay(2000);

}
}

Credits

Aptanta Pratiangga 29744

Aptanta Pratiangga 29744

1 project • 1 follower

Comments