12 V and 24 V are everywhere: in cars, boats, caravans, solar systems and the control cabinets of smart homes. An ESP32 needs 3.3 V. This guide shows how to power it cleanly and efficiently from 12 or 24 V with a DIN-rail DC/DC converter, and how to let the ESP32 keep an eye on the battery voltage.
Why not a linear regulator or a USB adapter?
A linear regulator turns the voltage difference into heat. Dropping 24 V to 3.3 V at 200 mA wastes about 4 W, more than the ESP32 itself uses, and the regulator gets too hot to touch. A cigarette-lighter USB adapter works in a car, but it is not made for permanent mounting, and it often stops working when the voltage dips during engine start.
A switching converter like the DCC-1033 converts the voltage with up to 89 % efficiency, clips onto a TS35 DIN rail and takes anything from 4.8 to 36 V. The same unit works on 12 V and 24 V without changes.
Which converter to choose
| You want to power | Converter | Connect to |
|---|---|---|
| ESP32, ESP32-S3, ESP32-C3 and 3.3 V sensors | DCC-1033 (3.3 V) | The board's 3V3 pin |
| Arduino Uno, Raspberry Pi, 5 V sensors and USB devices | DCC-1050 (5 V) | The board's 5V pin |
| 12 V devices from a 24 V system | DCC-1120 (12 V) | The device's 12 V input |
For an ESP32, the DCC-1033 straight to the 3V3 pin is the most efficient choice. It bypasses the board's own linear regulator, which would otherwise waste energy as heat.
Wiring
| From | To | Note |
|---|---|---|
| Supply + (through fuse) | DCC-1033 pin 1 (IN +) | 4.8–36 V |
| Supply − | DCC-1033 pin 2 (GND) | Pin 3 is also GND |
| DCC-1033 pin 6 (OUT +) | ESP32 3V3 | 3.3 V |
| DCC-1033 pin 4 (GND) | ESP32 GND | Pin 5 is also GND |
| Supply + via 120 kΩ | ESP32 GPIO34, and 10 kΩ to GND | Optional voltage measurement |
The DCC series is not isolated: input and output share ground. That makes the voltage measurement simple, because the ESP32 and the battery have the same reference.
Tip: while you program the ESP32 over USB, disconnect the 3.3 V wire so the board is not powered from two sources at once.
In cars, boats and caravans
- Voltage swings: a 12 V system runs from about 11 V with the engine off to 14.4 V while charging, and a 24 V system up to about 29 V. The DCC-1033 handles all of this without changing anything.
- Fuse: always fit an inline fuse close to the battery, for example 1 A, so a short in the cable cannot start a fire.
- Protection: the converter has reverse-polarity protection and an input fuse, so a wire connected the wrong way will not destroy the ESP32. In vehicles, where the voltage can spike far above normal when a large load is switched off, an extra TVS diode on the input is good practice.
- Mounting: a short piece of TS35 DIN rail screwed to a panel or into a small enclosure gives a tidy, vibration-proof installation.
How much current does it draw from the battery?
A switching converter converts power, not current. With the ESP32 using about 150 mA at 3.3 V with WiFi on (about 0.5 W), the current from the battery is much lower than 150 mA:
| Supply | Approx. efficiency | Current from battery |
|---|---|---|
| 12 V | 85 % | about 50 mA |
| 24 V | 80 % | about 25 mA |
A 100 Ah leisure battery can therefore run an ESP32 with WiFi on for about two months. With a linear regulator the current from the battery would be the full 150 mA, three to six times more.
Arduino code: monitor the battery voltage
The voltage divider scales 36 V down to about 2.8 V, which the ESP32 can measure safely. The sketch prints the supply voltage every five seconds and warns when a 12 V lead-acid battery drops below 11.8 V.
// Elunits supply voltage monitor for ESP32
// Measures a 12/24 V supply through a 120k/10k divider on GPIO34.
#define FW_NAME "Elunits ESP32 supply monitor"
#define FW_VERSION "1.0.0"
const int VSENSE_PIN = 34; // ADC1 pin, input only
const float R_TOP = 120000.0; // from supply + to GPIO34
const float R_BOTTOM = 10000.0; // from GPIO34 to GND
const float CAL = 1.00; // adjust after comparing with a multimeter
const float LOW_WARNING = 11.8; // volts, for a 12 V lead-acid battery
float readSupplyVolts() {
uint32_t mv = 0;
for (int i = 0; i < 16; i++) mv += analogReadMilliVolts(VSENSE_PIN);
float vPin = (mv / 16.0) / 1000.0;
return vPin * (R_TOP + R_BOTTOM) / R_BOTTOM * CAL;
}
void setup() {
Serial.begin(115200);
delay(200);
Serial.println(FW_NAME " v" FW_VERSION); // first line: name and version
analogSetPinAttenuation(VSENSE_PIN, ADC_11db);
}
void loop() {
float v = readSupplyVolts();
Serial.printf("Supply: %.2f V", v);
if (v < LOW_WARNING) Serial.print(" LOW!");
Serial.println();
delay(5000);
}
Compare the reading with a multimeter once and adjust CAL, because the ESP32 ADC varies a few percent between chips. For a 24 V system, set LOW_WARNING to about 23.6 V.
Next step: switch loads
Put a TCR-102-12V or TCR-102-24V relay unit on the same DIN rail and the ESP32 can switch pumps, lights, heaters or a fridge, for example turning off non-essential loads when the battery runs low. See the guide How to control a relay from an ESP32 with the TCR-102.
Troubleshooting
- Green LED on the converter is off: check the fuse and that the input is at least 4.8 V.
- ESP32 restarts when WiFi connects: check that the 3.3 V and GND wires are short and solid. WiFi draws short current peaks.
- Voltage reading is far off: check the resistor values and that the divider ground goes to the same GND as the ESP32.
Downloads
Need a different output voltage, such as 1.5, 2.5 or 6.5 V? Contact us at post@elunits.com.