#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
int inputPin = 4; // choose the input pin (for PIR sensor)
int motionDetectedCount = 0;
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600); // put your setup code here, to run once:
lcd.init();
lcd.backlight();
}
void loop() {
//Teperature sensor
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
int analogValue = analogRead(25);
float celsius = 1 / (log(1 / (4095. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("The bus inner temperature: ");
Serial.print(celsius);
Serial.print("\n ");
// Print something
lcd.setCursor(0, 0);
lcd.print("Temperature: ");
lcd.print(celsius);
delay(1000);
//motion sensor
int motionStatus = digitalRead(inputPin); // 读取PIR传感器的状态
if (motionStatus == HIGH) { // 如果检测到运动
motionDetectedCount++; // 增加运动检测计数
Serial.print("Motion detected! Total times: ");
Serial.println(motionDetectedCount);
// 加入一段延迟,防止同一运动事件被多次计数。
//运动传感器和温度传感器在这时段内无法计数
delay(5000);
}
}