#include <OneWire.h>
#include <DallasTemperature.h>
#include "DHTesp.h"
const int oneWireBus = 12;
const int Buzzer = 14;
const int DHT_PIN = 4;
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);
DHTesp dhtSensor;
void setup(){
pinMode(Buzzer, OUTPUT);
Serial.begin(115200);
dhtSensor.setup(DHT_PIN,DHTesp::DHT22);
sensors.begin();
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
delay(2000); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
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(1000);
if(temperatureC > 45)
{
tone(Buzzer,1200);
delay(200);
noTone(Buzzer);
delay(200);
}
}
Loading
ds18b20
ds18b20