#define LDR_PIN 2
#include <LiquidCrystal_I2C.h>
#include <ArduinoJson.h>
DynamicJsonDocument doc(1024);
byte sensorPin = 14;
const int tempPin = 12;
String abc;
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup()
{
Serial.begin(115200);
pinMode(LDR_PIN, INPUT);
pinMode(sensorPin, INPUT);
lcd.init();
lcd.backlight();
}
void loop()
{
String JsonData;
int sensorValue = digitalRead(sensorPin);
int adc = analogRead(tempPin);
const float BETA = 3950.0; // should match the Beta Coefficient of the thermistor
float temp = 1 / (log(1 / (4096.0 / adc - 1)) / BETA + 1.0 / 298.15) - 273.15;
if (digitalRead(LDR_PIN) == LOW)
{
abc="Light";
}
else
{
abc="Dark ";
}
lcd.setCursor(0,0);
lcd.print("M_S: ");
lcd.print(sensorValue);
lcd.setCursor(0,1);
lcd.print("Temp: ");
lcd.print(temp);
lcd.setCursor(0,2);
lcd.print("Room Status: ");
lcd.print(abc);
doc["Motion Sensor"] = sensorValue;
doc["Temperature Sensor"] = temp;
doc["Light Sensor"] = abc;
serializeJson(doc, JsonData);
Serial.println(JsonData);
delay(1000);
}