vinay y.n
Published © GPL3+

LoRa Blynk app Interfacing

Sending The Data From The LoRa Modules To Blynk Servers Using Ai-Thinker LoRa Modules

IntermediateFull instructions provided6 hours503
LoRa Blynk app Interfacing

Things used in this project

Hardware components

FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)
DFRobot FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
Ai-Thinker Ra-02 LoRa Module
×2
433 Mhz Antenna
×2
LM1117 3.3 V REGULATOR
×1
LED (generic)
LED (generic)
×1
Resistor 1k ohm
Resistor 1k ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
PCB Holder, Soldering Iron
PCB Holder, Soldering Iron
Solder Flux, Soldering
Solder Flux, Soldering
Storage Case, General Purpose
Storage Case, General Purpose
Multitool, Screwdriver
Multitool, Screwdriver
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

Read more

Schematics

Transmitter Part Connection SCH

Receiver Part Connection SCH

Code

Receiver Code

Arduino
To compile the code you need to install the predefined Libraries
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
#include <LoRa.h>
#include <ArduinoJson.h>  //REQUIRES ARDUINO JSON V6

//define the pins used by the transceiver module
#define ss 15  //D8 Of NodeMCU
#define rst 16 //D0 Of Nodemcu
#define dio0 2  //D2 Of Nodemcu

String LoRaData;
String jsonBuffer;
float ta;// Temperature details 
float ha; // Humidity details
float rs; //Rssi details

char auth[] = "Your blynk app token id";// Your blynk app token id
char ssid[] = "Wifi name"; // your Wifi name
char pass[] = "wifi password"; // your wifi password

BlynkTimer timer;

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Serial.println("LoRa Receiver");
  LoRa.setPins(ss, rst, dio0);

  while (!LoRa.begin(433E6)) {
    Serial.println("LoRa Intialization problem");
    delay(500);
  }
  LoRa.setSyncWord(0xF3);
  Serial.println("LoRa Initializing OK!");
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, sendSensor);
}

void loop() {
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    while (LoRa.available()) {
      LoRaData = LoRa.readString();
      }
    StaticJsonDocument<300> doc;
    DeserializationError err = deserializeJson(doc, LoRaData);
    
    if (err == DeserializationError::Ok)
    {
      Serial.print("Temperature:");
      Serial.print(doc["DATA1"].as<float>());
      Serial.println();
      Serial.print("Humidity:");
      Serial.print(doc["Humidity"].as<float>());
      Serial.println();
      ta = (doc["DATA1"].as<float>()); // temperature details recieving 
      ha = (doc["Humidity"].as<float>());//Humidity details receiving
      rs = (LoRa.packetRssi());
      }
      }
      Blynk.run();
      timer.run();
      }
      
      void sendSensor()
      {
        Blynk.virtualWrite(V0,ta);
        Blynk.virtualWrite(V1,ha);
        Blynk.virtualWrite(V2,rs);
        }

Transmitter Code

Arduino
To compile the code you need Libraries.
#include <SPI.h>
#include <LoRa.h>
#include <ArduinoJson.h> //REQUIRES ARDUINO JSON V6
#include<String.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
unsigned long startMillis = 0; 
const long interval = 1000;
#define DHTPIN 4     // Digital pin connected to the DHT sensor
float t;
float h;
#define ss 5
#define rst 14
#define dio0 2
#define DHTTYPE  DHT11
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  LoRa.setPins(ss, rst, dio0);
  while (!Serial);
  Serial.println("LoRa Sender");

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

  LoRa.setTxPower(20);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }
  delay(1000);
  display.clearDisplay();
  display.setTextColor(WHITE);
  dht.begin();
}

void loop() {
  t = dht.readTemperature();
  h = dht.readHumidity();
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
  }
  display.clearDisplay();
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.print("Temperature: ");
  display.setTextSize(2);
  display.setCursor(0, 10);
  display.print(t);
  display.print(" ");
  display.setTextSize(1);
  display.cp437(true);
  display.write(167);
  display.setTextSize(2);
  display.print("C");
  display.setTextSize(1);
  display.setCursor(0, 35);
  display.print("Humidity: ");
  display.setTextSize(2);
  display.setCursor(0, 45);
  display.print(h);
  display.print(" %");
  display.display();
  
//Serializing the Data to transmit using LoRa

  StaticJsonDocument<100> testDocument;
  testDocument["DATA1"] = t;
  testDocument["Humidity"] = h;
  char buffer[100];
  LoRa.beginPacket();
  LoRa.print(buffer);
  LoRa.endPacket();
  serializeJson(testDocument, buffer);
  Serial.print("Sending packet:");
  Serial.print(buffer);
}

Credits

vinay y.n

vinay y.n

5 projects • 2 followers
Maker | Hardware Hacker | Electronics Enthusiast

Comments

Add projectSign up / Login