LM317 variable power supply
Turn a 12 V adapter into an adjustable 1.25–10 V supply for your experiments.
Shop by category
Shop all componentsAn ESP32 running Wi-Fi all the time empties a battery in a day or two. Deep sleep switches almost everything off between readings, so a bare ESP32 chip draws only microamps while asleep, though a development board's USB chip and regulator still draw some current. The sketch wakes on a timer, reads the sensor, sends it to a ThingSpeak-style HTTP endpoint, and sleeps. An 18650 cell with a TP4056 charger lets you recharge it over USB. Battery life depends heavily on the board you use, so measure it.
Check Li-ion cell polarity before connecting it. A reversed or shorted cell can overheat.
Use a protected cell and a charger with protection, and never charge unattended.
Tick anything you already have and the total updates.
Follow the colours: red is power, dark grey is ground, blue is a signal.
One 18650 cell through the TP4056 module. Charge with a USB cable. Check polarity before connecting the cell: a reversed cell can destroy parts and is a fire risk.
deep_sleep.inoVerify & upload in Electrolark#include <WiFi.h>
#include <HTTPClient.h>
#include <DHT.h>
const char* WIFI_NAME = "YOUR_WIFI";
const char* WIFI_PASS = "YOUR_PASSWORD";
String URL = "http://api.thingspeak.com/update?api_key=YOUR_WRITE_KEY";
const uint64_t SLEEP_MINUTES = 10;
RTC_DATA_ATTR int wakeCount = 0; // survives deep sleep
DHT dht(4, DHT22);
void setup() {
Serial.begin(115200);
wakeCount++;
dht.begin();
delay(2000); // DHT22 needs about 2 s after power-up
float t = dht.readTemperature(), h = dht.readHumidity();
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_NAME, WIFI_PASS);
unsigned long start = millis();
while (WiFi.status() != WL_CONNECTED && millis() - start < 10000) delay(100);
if (WiFi.status() == WL_CONNECTED && !isnan(t)) {
HTTPClient http;
http.begin(URL + "&field1=" + String(t, 1) + "&field2=" + String(h, 0) + "&field3=" + String(wakeCount));
Serial.printf("sent %.1f C, wake %d, HTTP %d\n", t, wakeCount, http.GET());
http.end();
}
esp_sleep_enable_timer_wakeup(SLEEP_MINUTES * 60ULL * 1000000ULL);
esp_deep_sleep_start();
}
void loop() {}
A development board's USB chip and LED draw current even in deep sleep. Measure it, and for the best life choose a bare module or a low-power board.
Move it closer to the router, or give it a fixed IP address to join faster.
The DHT22 needs power for about two seconds before the first read. The sketch waits for that.
It depends on the board. A bare ESP32 can last months, but a typical development board often draws around a milliamp or more asleep, so a few weeks is more realistic.
Yes. Add a small solar panel to the TP4056's input, which suits an outdoor node.
Wi-Fi uses about 100 to 200 mA while active, which drains a battery within a day or two.
7 parts: ESP32-WROOM-32 38-Pin Development Board, DHT22 AM2302 Digital Temperature & Humidity Sensor, 18650 Li-ion Rechargeable Cell, 18650 Battery Holder, TP4056 1A Li-ion Charger Module with Protection, Solderless Breadboard and Dupont Jumper Wires (40 pcs). On this page you can tick the parts you already have and add only the rest to your cart.
No. This page has the complete, tested code (deep_sleep.ino).
About ₹782 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Using ESP32 deep sleep with a timer; Keeping data across sleeps in RTC memory; Charging and powering from an 18650 with a TP4056.
Check Li-ion cell polarity before connecting it. A reversed or shorted cell can overheat. Use a protected cell and a charger with protection, and never charge unattended.
Ideas that reuse this build: ESP32 MQTT temperature dashboard. They are listed under Take it further on this page.
Turn a 12 V adapter into an adjustable 1.25–10 V supply for your experiments.
Build your own USB power bank and learn how lithium charging works.
Free power for outdoor sensors: sunlight in, 5 V USB out.
Beeps when the mains goes off at night, so the fridge and the alarm clock do not quietly die.
Learning project. Check every circuit and the datasheet of each part before you power it up.