Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino and ESP8266 Based Environmental Monitoring System with LoRa Communication

View and Edit Project In Cirkit DesignerImage of Arduino and ESP8266 Based Environmental Monitoring System with LoRa Communication

Circuit Documentation

Summary

The circuit in question is a multifunctional sensor and communication system that utilizes an Arduino 101 as the central processing unit. It interfaces with various sensors including a DHT11 temperature and humidity sensor, an MQ2 gas sensor, a flow rate sensor, and a PH meter. For wireless communication, it employs an ESP8266 NodeMCU and a LoRa Ra-02 SX1278 module. The circuit is designed to collect environmental data and transmit it over LoRa and ESP8266 networks.

Component List

Arduino 101

DHT11 Sensor V2

LoRa Ra-02 SX1278

ESP8266 NodeMCU

MQ2

Flow Rate Sensor

PH Meter

Wiring Details

Arduino 101

DHT11 Sensor V2

LoRa Ra-02 SX1278

ESP8266 NodeMCU

MQ2

Flow Rate Sensor

PH Meter

Documented Code

Arduino 101 Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <RTClib.h>
#include <SPI.h>
#include <LoRa.h>
#include <SoftwareSerial.h>

// LCD Setup
LiquidCrystal_I2C lcd(0x27, 16, 2);

// DHT Sensor Setup
#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

// Dust Sensor Setup
#define measurePin A0
#define ledPower 7
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;

// RTC Setup
RTC_DS1307 rtc;

// LoRa and ESP8266 Setup
#define NSS  10
#define RST  9
#define DIO0 8
SoftwareSerial espSerial(0, 1);  // RX, TX for ESP8266

// Buzzer Setup
const int buzzer = 9;

// Variables
int num = 0;

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

  // LCD Init
  lcd.init();
  lcd.backlight();

  // DHT Init
  dht.begin();

  // RTC Init
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  // LoRa Init
  LoRa.setPins(NSS, RST, DIO0);
  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }

  // ESP8266 Init
  espSerial.begin(9600);

  // Buzzer Init
  pinMode(buzzer, OUTPUT);

  // Dust Sensor Init
  pinMode(ledPower, OUTPUT);

  // Initial Display on LCD
  lcd.setCursor(0, 0);
  lcd.print("System Starting");
  delay(2000);
}

void loop() {
  // Time from RTC
  DateTime now = rtc.now();

  // Temperature and Humidity from DHT
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // Dust Sensor Reading
  digitalWrite(ledPower, LOW);
  delayMicroseconds(samplingTime);
  voMeasured = analogRead(measurePin);
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower, HIGH);
  delayMicroseconds(sleepTime);
  calcVoltage = voMeasured * (5.0 / 1024.0);
  dustDensity = 170 * calcVoltage - 0.1;

  // Buzzer Alert
  tone(buzzer, 1000);
  delay(1000);
  noTone(buzzer);
  delay(1000);

  // Display on LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Time: ");
  lcd.print(now.hour());
  lcd.print(":");
  lcd.print(now.minute());
  lcd.print(":");
  lcd.print(now.second());

  lcd.setCursor(0, 1);
  lcd.print("Temp: ");
  lcd.print(t);
  lcd.print(" C");

  lcd.setCursor(0, 2);
  lcd.print("Humidity: ");
  lcd.print(h);
  lcd.print(" %");

  lcd.setCursor(0, 3);
  lcd.print("Dust: ");
  lcd.print(dustDensity);

  // LoRa Communication
  LoRa.beginPacket();
  LoRa.print("Data: Temp=");
  LoRa.print(t);
  LoRa.print(", Humidity=");
  LoRa.print(h);
  LoRa.print(", Dust=");
  LoRa.print(dustDensity);
  LoRa.endPacket();

  // ESP8266 Data Reception
  if (espSerial.available()) {
    String data = espSerial.readString();
    Serial.println("Data from ESP8266: " + data);
  }

  // Update every 2 seconds
  delay(2000);
}

DHT11 Sensor V2 Code

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

(Note: The code for the DHT11 Sensor V2 is a placeholder and does not contain any functional code. It is likely that the actual sensor code is integrated within the Arduino 101 code.)