#include <LiquidCrystal_I2C.h>
#define LED_pin 2
#define PMS_digitalin 12
#define NTC_analogin 14
LiquidCrystal_I2C LCD = LiquidCrystal_I2C(0x27, 22, 21);
void setup() {
pinMode(LED_pin, OUTPUT);
pinMode(PMS_digitalin, INPUT);
pinMode(NTC_analogin, INPUT);
LCD.init();
Serial.begin(9600);
}
void loop() {
// When a motion is detected, keep reading the temperature from the temperature
// sensor and print the temperature on the LCD display
int PMS_in = digitalRead(PMS_digitalin);
if (PMS_in == 1) {
int LED_status = digitalRead(LED_pin);
int NTC_in = analogRead(NTC_analogin);
float celsius = 1 / (log(1 / (4095. / NTC_in - 1)) / 3950 + 1.0 / 298.15) - 273.15;
LCD.setCursor(0, 0);
LCD.print("Temperature:");
LCD.setCursor(0, 1);
LCD.println(celsius);
// If the temperature is below 10 ℃ when a motion is detected, turn on LED and
// print the “LED On” on the LCD display.
if (celsius < 10) {
digitalWrite(LED_pin, HIGH);
LCD.setCursor(0, 2);
LCD.println("LED On");
}
}
// When the OUT pin of the motion sensor goes LOW, turn off LED and clean the
// LCD display.
else {
digitalWrite(LED_pin, LOW);
LCD.clear();
}
delay(1000);
}