sagar saini
Published © GPL3+

Sensor Monitoring Using LoRa & Arduino

A small cool and very informative project, to show "how Long range radio system can work with sensors". Let's build one with own.

IntermediateFull instructions provided2 hours2,328
Sensor Monitoring Using LoRa & Arduino

Things used in this project

Story

Read more

Custom parts and enclosures

Gerber files of Lora breadboard

BOM FILE

CPL FILE

Schematics

Transmitter circuit

Receiver circuit

Code

Transmitter code

Arduino
#include <SPI.h>
#include <LoRa.h>
#include <DHT.h>
#define DHTPIN 4                                                           // what digital pin we're connected to
#define DHTTYPE DHT11                                                       // select dht type as DHT 11 or DHT22
DHT dht(DHTPIN, DHTTYPE);

int counter = 0;

void setup() {
  Serial.begin(9600);
  while (!Serial);

  Serial.println("LoRa Sender");
  
  dht.begin();     //initialise DHT11

  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  LoRa.setSyncWord(0xF3);
  LoRa.setTxPower(20);
}

void loop() 
{
  float h = dht.readHumidity();                                              
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {                                                
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  Serial.print("Sending packet: ");
  Serial.println(counter);
  // send packet
  LoRa.beginPacket();
  LoRa.print("Data:");
  LoRa.print(counter);
  LoRa.print("> ");
  LoRa.print("Temperature: ");
  LoRa.print(t);
  LoRa.print(" ");
  LoRa.print("humidity");
  LoRa.print(h);
  LoRa.endPacket();

  counter++;

  delay(5000);
}

Receiver code

Arduino
#include <SPI.h>
#include <LoRa.h>



void setup() {
  //initialize Serial Monitor
  Serial.begin(9600);
  while (!Serial);
  Serial.println("LoRa Receiver");

  
  //replace the LoRa.begin(---E-) argument with your location's frequency 
  //433E6 for Asia
  //866E6 for Europe/Africa
  //915E6 for North America
  if(!LoRa.begin(433E6)) {
    Serial.println(".");
    while (1);
  }
   // Change sync word (0xF3) to match the receiver
  // The sync word assures you don't get LoRa messages from other LoRa transceivers
  // ranges from 0-0xFF
  LoRa.setSyncWord(0xF3);
  Serial.println("LoRa Initializing OK!");
}

void loop() 
{

  String LoRaData; 
  int packetSize = LoRa.parsePacket();
  if (packetSize) 
  {
    // received a packet
    Serial.print("Received packet '");

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

    // print RSSI of packet
 //   Serial.print("' with RSSI ");
//    Serial.println(LoRa.packetRssi());
    
   }
}

Credits

sagar saini

sagar saini

81 projects • 84 followers
I am Sagar Saini an electronic hardware enthusiast

Comments