#include<WEMOS_DHT12.h>// https://github.com/milesburton/Arduino-Temperature-Control-Library// https://github.com/PaulStoffregen/OneWire#include<OneWire.h>#include<DallasTemperature.h>#define ONE_WIRE_BUS 23#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds */#define TIME_TO_SLEEP 5 /* Time ESP32 will go to sleep (in seconds) */#define LED_BUILTIN 2RTC_DATA_ATTRuint32_tloopcount=0;// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)OneWireoneWire(ONE_WIRE_BUS);// Pass our oneWire reference to Dallas Temperature.DallasTemperaturesensors(&oneWire);// the setup function runs once when you press reset or power the boardvoidsetup(){pinMode(LED_BUILTIN,OUTPUT);Serial.begin(115200);Wire.begin();sensors.begin();// some debug code for the one wire sensor// Serial.print("Found ");// Serial.print(sensors.getDeviceCount(), DEC);// Serial.println(" devices.");// Serial.print("One wire Pin ");esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP*uS_TO_S_FACTOR);}// the loop function runs over and over again forevervoidloop(){DHT12dht12;sensors.requestTemperatures();// get temp from DS18B20 (black wire probe)floatDS_C,DS_F;if(sensors.getDeviceCount()>0){// make sure there is a sensor.DS_C=sensors.getTempCByIndex(0);DS_F=(DS_C*1.8)+32;// convert C to FSerial.print("External Temp C: ");Serial.print(DS_C);Serial.print(" F: ");Serial.println(DS_F);}// Get temp from DHT12 sensor (blue one on the board)if(dht12.get()==0){Serial.print("Inside Temp C: ");Serial.print(dht12.cTemp);Serial.print(" F: ");Serial.print(dht12.fTemp);Serial.print(" H: ");Serial.println(dht12.humidity);}elseSerial.println("Error reading DH12");Serial.print("Sleeping now, Loop count ");Serial.println(loopcount++);//delay(60000);esp_deep_sleep_start();}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.