13.8 A signal is not a power supply
An LED on an ESP32 pin glows only dimly, although the meter reads 3.3 V on that pin, the same as on the 3V3 pin, where an identical LED lights brightly. We treat the pin as a circuit someone else built: we do not need to know everything inside it, only what it sends us and how much it can deliver, and the measuring routine of Working at the bench finds both. Ben Eater’s video shows the same puzzle with a 5 V “mystery signal”.
The pins of the ESP32
Figure 13.8.1 shows the 30 pins of the board from ESP32 setup. Power comes in at VIN (5 to 12 V, regulated down on the board) or from USB. The board’s own regulator provides 3.3 V at the 3V3 pin, and the two GND pins are its ground. Every other pin is a GPIO (general purpose input/output) that the program can switch, read or use for a special function. The number printed on the board, e.g. D23, is the GPIO number we write in the code.
Open Espressif’s ESP32 Series Datasheet1 once and find the pin list in its section Pins. The board is only a carrier for the chip, and the datasheet of the chip is where the limits of every pin are stated. Two of them we use in this chapter: a pin must never see more than the chip’s supply plus 0.3 V, 3.6 V on our board, and a pin set as an output delivers a limited current.
Step 1: Upload the mystery signal
Create a PlatformIO project called mystery in the same way as blink, and replace its two files with the ones below. Try not to read main.cpp closely yet; for now the board is a circuit that someone else built, and we find out what it does by measuring.
[env:esp32dev]
platform = espressif32@8.0.0
board = esp32dev
framework = arduino
upload_speed = 921600
monitor_speed = 115200The program, src/main.cpp, is listed in Step 6. Build and upload as in Step 6 of the PlatformIO chapter. The serial monitor prints high and low once a second.
Without PlatformIO at hand, flash the mystery signal from the browser in Chrome or Edge instead.
Step 2: Measure the signal
Unplug the USB cable. The pin rows of the ESP32 sit 0.9 inch apart and the board is 28 mm wide, so on one breadboard it covers the holes beside its pins. Put two full-size breadboards side by side, with the rail strip between them removed, and let the ESP32 straddle both, as in Figure 13.8.2: its D23 … 3V3 row in the bottom row of the upper board, its EN … VIN row in the top row of the lower board. Connect 3V3 to the top + rail and GND to the bottom − rail.
D23, black probe on the − rail, which GND feeds.
Plug the USB cable back in. With the meter on V⎓, black probe on the − rail and red probe in a free hole of the column of D23, the reading alternates between 0 V and about 3.3 V, one second each. That is the signal: a pin that says high or low with its voltage, like Ben’s mystery wires.
Step 3: Connect an LED to the signal
The signal switches between 0 V and 3.3 V, so an LED with a resistor should blink. With the resistor formula and 220 Ω we predict
\[ I = \frac{3.3 - 1.9}{220}~\text{A} = 6.4~\text{mA}, \]
clearly visible and well within what a pin may deliver. Unplug the USB cable. A yellow jumper takes D23 to a free column of the upper board, a 220 Ω resistor runs from there to the column of the LED’s long leg, and the LED crosses the centre gap with its short leg in the lower half, from where a black jumper goes down to the − rail. This is circuit A in Figure 13.8.3. Plug in.
The LED blinks, but it is dim, much dimmer than the LEDs of the previous chapters. Ben sees the same at 3:00 in the video.
Step 4: Build a known-good reference
Is the LED dim because 3.3 V is too little for it? Build circuit B next to circuit A, with an identical resistor and an identical LED, but fed from the 3V3 pin of the board, a power supply. Ben does the same with his USB supply.
D23, circuit B by the + rail, which 3V3 feeds. Both return to the bottom − rail, which GND feeds. A lights only dimly, B brightly.
LED B is bright. The two circuits are meant to be identical, both “have 3.3 V”, and one works while the other does not. We have a known-good copy right next to the faulty one.
Step 5: Troubleshoot
Ben’s fifth video finds the cause. Watch it, then do the same measurements on your own board, one at a time, and log each result.
Is the LED faulty? Unplug the USB, swap the two LEDs, plug in. If the dim LED moved to circuit B, the LED is faulty. It does not: A is still dim with the other LED. The LEDs are fine.
Are the resistors different? Take both out and measure them with the ohmmeter. Both read about 220 Ω. Put them back.
Is the voltage different? Take both LEDs out and measure the voltage at the free end of each resistor, black probe on the − rail. Both read 3.3 V (A only in its high second). Without a load, the two sources look the same.
Is the voltage different under load? Put the LEDs back and measure again, this time at D23 itself and at 3V3. The supply pin still reads 3.3 V. The signal pin, in its high second, reads only about 1.7 V. Connecting the LED pulled the signal down. Ben sees 5.1 V fall to 1.8 V at 6:50 in his fourth video.
Is the current different? This is the measurement Ben makes next. Unplug the USB, set the dial to the 20m range of A⎓; the red lead stays in VmAµA. Take LED A out and put the probes into the two holes where its legs were, red on the resistor side, so that the current has to pass through the meter (Figure 13.8.4). Plug in.
In the high second the meter shows only 0.03 or 0.04 mA; step down to the 2000µ range and it reads about 35 µA. Do the same in circuit B: about 6 mA, some 170 times more. Same voltage, same resistor, same LED, and 170 times less current. That explains the dim LED. Unplug, put the LEDs back and, as always, turn the dial back to V⎓.
What is inside the signal
A power supply is built to hold its voltage while it delivers current; the supply pin 3V3 comes from a regulator that can deliver several hundred milliamperes. A signal is built to tell us something with its voltage, and may be able to deliver very little. The simplest picture of a weak source is an ideal voltage \(U_0\) with a resistor \(R_i\) inside, in series with the output. A current \(I\) out of the pin takes \(R_i I\) inside, and the pin is left with
\[ U = U_0 - R_i I. \tag{13.8.1}\]
Figure 13.8.5 is that picture for our mystery pin, with \(U_0\) = 3.3 V and \(R_i\) = 45 kΩ.
With nothing connected, no current flows through the hidden resistor, it takes no voltage, and the pin shows the full 3.3 V. The voltmeter draws almost nothing (with its 10 MΩ, about 0.3 µA), so it sees the 3.3 V too. That is why the measurement without a load looked fine. With the LED connected, the voltage budget of the loop now has three parts: the hidden 45 kΩ, our 220 Ω and the LED. The LED needs about 1.7 V before it conducts at all, the 220 Ω takes next to nothing, and the hidden resistor takes the rest, so the current is
\[ I = \frac{3.3 - 1.7}{45\,000 + 220}~\text{A} \approx 35~\mu\text{A}, \]
enough for a faint glow and nothing more. The pin voltage, measured behind the hidden resistor, falls to the LED voltage, the 1.7 V we measured.
A voltage measured with nothing connected says nothing about how much current the source can deliver. Measure the voltage of a source again with its load connected. If it drops noticeably, the source is weaker than the circuit needs.
Step 6: Read the code
Now open main.cpp.
#include <Arduino.h>
const int signalPin = 23;
const int periodMs = 2000;
const bool driven = false; // false: pull-up only, true: driven output
// The high half of the signal. With driven = true it drives the pin as an output, connected to
// 3.3 V through the pin's output transistor. With driven = false it only switches on the pin's
// internal pull-up resistor of about 45 kOhm: a voltmeter still reads 3.3 V, but the pin
// can push only a few tens of microamperes into a load.
void signalHigh() {
if (driven) {
pinMode(signalPin, OUTPUT);
digitalWrite(signalPin, HIGH);
} else {
pinMode(signalPin, INPUT_PULLUP);
}
}
// The low half is the same in both modes: the output transistor connects the pin to GND.
void signalLow() {
pinMode(signalPin, OUTPUT);
digitalWrite(signalPin, LOW);
}
void setup() {
Serial.begin(115200);
Serial.printf("Signal on GPIO %d, period %d ms\n", signalPin, periodMs);
}
void loop() {
signalHigh();
Serial.println("high");
delay(periodMs / 2);
signalLow();
Serial.println("low");
delay(periodMs / 2);
}In its high half the program does not make the pin an output at all. INPUT_PULLUP turns the pin into an input and connects it to 3.3 V through a resistor inside the chip, the pull-up resistor. Its job is to hold an unconnected input at a defined level, and the ESP32 datasheet gives its typical value as 45 kΩ.2 The same resistor holds a button input high, see Buttons. It was never meant to feed an LED.
Change one thing: set driven to true at the top of main.cpp and upload again. Now the program makes the pin an output, and an output pin connects to 3.3 V through a transistor with a resistance of about 30 Ω. Predict, then measure: LED A is about as bright as LED B, the pin voltage under load stays near 3.1 V, and the current through the LED is about 5 mA, a little below the 6 mA of circuit B. In Figure 13.8.5, closing the switch does the same.
How much current can a pin deliver?
An output pin is a much stronger source than the pull-up, but not a power supply either. The ESP32 datasheet3 (Table 5-3, DC Characteristics) states that a pin at its strongest drive setting sources typically 40 mA while its voltage stays above 2.64 V, and the Arduino framework uses a weaker default setting that Espressif gives as about 20 mA. These are typical values, measured with one pin loaded; with many pins loaded at once each delivers less. As with the LED, we design well inside them.
Read with 13.8.1, the default setting loses 3.3 − 2.64 = 0.66 V at 20 mA, so the output transistor acts as \(R_i = 0.66/0.020~\Omega \approx 33~\Omega\). The load, 220 Ω and the LED, needs the pin voltage
\[ U = U_\text{LED}(I) + 220~\Omega \cdot I, \]
where \(U_\text{LED}(I)\) is the curve of First light: almost no current below 1.7 V and about 10 mA at 2.0 V, ten times the current for every 0.12 V more. The pin settles where source and load agree, the crossing of the two curves in Figure 13.8.6. Behind the pull-up the crossing lies at 1.71 V and 35 µA, behind the driven output at 3.13 V and 5.3 mA, and on the 3V3 supply at 6.0 mA.
3V3 supply, circuit B.
For this course we keep the current from any one pin at or below about 10 mA. That is plenty for an LED, and the pin voltage then stays close to 3.3 V. Anything that needs more, a relay, a motor, a servo, a strip of LEDs, gets its current from a supply, and the pin only sends the signal that controls it. The part that lets a weak signal switch a strong current is the transistor. On the car the same job is done by the motor driver of Driving a DC motor with the BTS7960: its inputs take a few milliamperes from the ESP32 pins, and it switches tens of amperes from the battery.
Which pins to use
Not every pin of Figure 13.8.1 is equally free. The table sorts them for our DevKit, following the ESP32 datasheet sections Pins and Boot configurations.
| GPIO | Use | Why |
|---|---|---|
| 4, 13, 14, 16 to 19, 21 to 23, 25 to 27, 32, 33 | Free | Ordinary input and output pins. |
| 0, 2, 5, 12, 15 | With care | Strapping pins: their level at reset decides how the chip starts. GPIO 2 also drives the onboard LED. |
| 34, 35, 36, 39 | Inputs only | No output driver and no internal pull-up or pull-down. |
| 1, 3 | Avoid | The USB serial connection used for uploads and the serial monitor. |
The pin map of the car uses only free pins and input-only pins. A strapping pin works as an ordinary pin once the board has started; the risk is a circuit that holds it at the wrong level during reset. A pull-up resistor on GPIO 12, for example, stops the board from starting at all. Why the BOOT button explains GPIO 0, and Which pins can read adds the rules for analog inputs.
Exercises
Exercise 1: The pin under load
Set driven = true and periodMs = 10000 in main.cpp, so that each half lasts five seconds, and upload. With circuit A of Figure 13.8.3 in place, measure the voltage at D23 against the − rail in the high half, first with LED A in place and then with it removed. Measure the LED current as in Step 5. Use 13.8.1 to estimate the resistance of the output driver from the drop in voltage and the current, and compare it with the 33 Ω of How much current can a pin deliver?. Then recalculate the LED current with your value, and check it once more with 100 Ω (never less) in place of the 220 Ω.
Exercise 2: Weak sources on the car
Which of these are signals and which are supplies: the servo’s signal wire, the 3V3 pin, the midpoint of the battery divider of Battery sensing, the VIN pin fed from the buck converter? For each signal, what is the largest current you would draw from it?
Exercise 3: The model in Falstad
In Figure 13.8.5, double-click the 45 kΩ resistor and try 4.5 kΩ and 450 Ω. For each value, note the pin voltage and the LED current. At what hidden resistance does the LED reach half of the current it gets from the supply pin?
Espressif Systems, ESP32 Series Datasheet, version 5.3: pin list in section 2, Pins; Table 5-3, DC Characteristics (3.3 V, 25 °C), for \(V_{IH}\) (at most VDD + 0.3 V), the source current \(I_{OH}\) and the pull-up \(R_{PU}\) (45 kΩ typical); Table 6-1, note 8, for the drive strength settings (default about 20 mA). espressif.com.↩︎
Espressif Systems, ESP32 Series Datasheet, version 5.3: pin list in section 2, Pins; Table 5-3, DC Characteristics (3.3 V, 25 °C), for \(V_{IH}\) (at most VDD + 0.3 V), the source current \(I_{OH}\) and the pull-up \(R_{PU}\) (45 kΩ typical); Table 6-1, note 8, for the drive strength settings (default about 20 mA). espressif.com.↩︎
Espressif Systems, ESP32 Series Datasheet, version 5.3: pin list in section 2, Pins; Table 5-3, DC Characteristics (3.3 V, 25 °C), for \(V_{IH}\) (at most VDD + 0.3 V), the source current \(I_{OH}\) and the pull-up \(R_{PU}\) (45 kΩ typical); Table 6-1, note 8, for the drive strength settings (default about 20 mA). espressif.com.↩︎