#include <OneWire.h>
#include <DallasTemperature.h>
const int oneWireBus = 4;
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);
const int PIR_SENSOR_OUTPUT_PIN = 13;
int warm_up;
void setup() {
pinMode(oneWireBus, INPUT);
pinMode(PIR_SENSOR_OUTPUT_PIN, INPUT);
Serial.begin(115200);
sensors.begin();
}
void loop() {
DS18D20();
delay(1000);
PIR();
}
void DS18D20(){
sensors.requestTemperatures();
float temperatureC = sensors.getTempCByIndex(0);
float temperatureF = sensors.getTempFByIndex(0);
Serial.print(temperatureC);
Serial.println("ºC");
Serial.print(temperatureF);
Serial.println("ºF");
delay(2000);
}
void PIR(){
int sensor_output;
sensor_output = digitalRead(PIR_SENSOR_OUTPUT_PIN);
if( sensor_output == LOW )
{
if( warm_up == 1 )
{
Serial.print("Warming Up\n\n");
warm_up = 0;
delay(2000);
}
Serial.print("No object in sight\n\n");
delay(1000);
}
else
{
Serial.print("Object detected\n\n");
warm_up = 1;
delay(1000);
}
}Loading
ds18b20
ds18b20