Commit 722f38f4 authored by Ravindu Dolawatta's avatar Ravindu Dolawatta

t

parent 8009d699
#include <OneWire.h>
#include <DallasTemperature.h>
#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>
#include <BH1750.h>
#include <AHT10.h>
#define ss 53
#define rst 11
#define dio0 8
#define CJMCU101 A0
#define soil A1
#define ONE_WIRE_BUS 2
int counter = 0;
float CJM, soildata, Leaf_temp, lux, h, t;
String msg;
unsigned long lastTime = 0;
unsigned long timerDelay = 10000;
BH1750 lightMeter;
AHT10Class AHT10;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
Wire.begin();
lightMeter.begin();
sensors.begin();
while (!Serial);
LoRa.setPins(ss, rst, dio0);
Serial.println("LoRa Sender");
if (!LoRa.begin(433E6)) {
Serial.println("Starting LoRa failed!");
while (1);
}
if (AHT10.begin(eAHT10Address_Low)) {
Serial.println("Init AHT10 Success!");
} else {
Serial.println("Init AHT10 Failed!");
}
}
void loop() {
counter++;
CJMCU101Read();
soilRead();
probe18b20Read();
BH1750luxRead();
AHT10Read();
if ((millis() - lastTime) > timerDelay) {
msg = "" + (String) CJM + ";" + (String)soildata + ";" + (String)Leaf_temp + ";" + (String)lux + ";" + (String)h + ";" + (String)t + "";
Serial.print("msg Data: ");
Serial.println(msg);
LoRa.beginPacket();
LoRa.print(msg);
LoRa.endPacket();
lastTime = millis();
}
}
void CJMCU101Read() {
CJM = analogRead(CJMCU101);
Serial.print("CJMCU101 Read : ");
Serial.println(CJM);
}
void soilRead() {
soildata = analogRead(soil);
Serial.print("Soil Read : ");
Serial.println(soildata);
}
void probe18b20Read() {
sensors.requestTemperatures();
Leaf_temp = sensors.getTempCByIndex(0);
Serial.print("Leaf temperature: ");
Serial.println(Leaf_temp);
}
void BH1750luxRead() {
lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
}
void AHT10Read() {
h = AHT10.GetHumidity();
t = AHT10.GetTemperature();
Serial.println(String("") + "Humidity(%RH):\t\t" + AHT10.GetHumidity() + "%");
Serial.println(String("") + "Temperature(℃):\t" + AHT10.GetTemperature() + "℃");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment