#include <OneWire.h>
#include <DallasTemperature.h>
const int TEMP_THRESHOLD_UPPER = 25;
const int TEMP_THRESHOLD_LOWER = 20;
const int SENSOR_PIN = 9;
const int MOTION_SENSOR_PIN = 2;
const int BUZZER_PIN = 3;
int motionStateCurrent = LOW;
int motionStatePrevious = LOW;
OneWire oneWire(SENSOR_PIN);
DallasTemperature sensors(&oneWire);
float temperature;
void setup() {
Serial.begin(9600);
sensors.begin();
pinMode(MOTION_SENSOR_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
sensors.requestTemperatures();
temperature = sensors.getTempCByIndex(0);
if(temperature > TEMP_THRESHOLD_UPPER){
Serial.println("temp : it is hot");
} else if(temperature < TEMP_THRESHOLD_LOWER){
Serial.println(" temp: it is cold");
}
delay(500);
motionStateCurrent = digitalRead(MOTION_SENSOR_PIN);
if ( motionStateCurrent == HIGH) {
Serial.println("Motion detected!");
digitalWrite(BUZZER_PIN, HIGH);
}
else
{
Serial.println("Motion stopped!");
digitalWrite(BUZZER_PIN, LOW);
}
}