Advertisement
pleasedontcode

ESP32 project with Low Power Mode

Aug 3rd, 2024
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 0.70 KB | Source Code | 0 0
  1. #include <WiFi.h>
  2. #include <DHT.h>
  3. #include <esp_sleep.h>
  4.  
  5. #define DHTPIN 4
  6. #define DHTTYPE DHT22
  7.  
  8. DHT dht(DHTPIN, DHTTYPE);
  9.  
  10. void setup() {
  11.   Serial.begin(115200);
  12.   dht.begin();
  13.   esp_sleep_enable_timer_wakeup(10 * 60 * 1000000); // Set to wake up every 10 minutes
  14. }
  15.  
  16. void loop() {
  17.   float temperature = dht.readTemperature();
  18.   float humidity = dht.readHumidity();
  19.  
  20.   if (isnan(temperature) || isnan(humidity)) {
  21.     Serial.println("Failed to read from DHT sensor!");
  22.     return;
  23.   }
  24.  
  25.   Serial.print("Temperature: ");
  26.   Serial.print(temperature);
  27.   Serial.print(" *C, Humidity: ");
  28.   Serial.print(humidity);
  29.   Serial.println(" %");
  30.  
  31.   esp_deep_sleep_start(); // Enter deep sleep mode
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement