dual bright LEDs/How it works/03. The pin only switches it
How it works · 03 of 9

The pin only switches it

A colour pin reaches 1 kΩ and a transistor's base, nothing else. HIGH puts about 2.6 mA into the base from a 3.3 V pin, the transistor turns on, and VCC pushes the LED's current, over 150 mA from 5 V, through the 10 Ω and the LED to GND. None of that passes through your pin, which is why VCC may be 5 V on a 3.3 V board.

Two loops, one small and one large

Each colour is the same circuit. Follow the warm one: press the button.

The pin only switches it
VCC wired to
From your pin
0 mA
Through the LED
0 mA
The 3000K pin is LOW. No current into the base, so the transistor is off and nothing flows from VCC: the LED is dark. The 6500K side is the same circuit again.

The pin going HIGH lights nothing by itself. It pushes about 2.6 mA through the 1 kΩ into the transistor's base, and out of its emitter to GND. That small current is what turns the transistor on.

Only then does the large loop close: from VCC through the 10 Ω, through the LED, into the transistor's collector and out to GND. From 5 V that is about 168 mA, some sixty times what the pin gives. The transistor is a switch that a small current opens for a large one.

Why the pin cannot do it alone

An ESP32's pin is comfortable at about 20 mA, an Uno's is rated 40 mA at most, and a Pico's 12 mA at its strongest setting. Any of them wired straight to this LED would either light it dimly or be damaged trying. The S8050 on the board is rated 500 mA, and it takes a couple of milliamps from the pin to carry what the LED wants.

Why 5 V is safe on a 3.3 V board

VCC reaches the two 10 Ω resistors and the two capacitors. It never meets a colour pin. The only path from the LED side back towards your pin is the transistor's base-to-collector junction, and that points from the base to the collector, the wrong way for 5 V to flow into the pin. So a 3.3 V ESP32 can switch a 5 V supply here.

Nothing on the board holds a base LOW. Until a sketch drives a pin, its LED does whatever the pin does, which is why every sketch in this book sets both pins LOW before anything else.

When it does not work

Can I power the LEDs from the colour pin?

No, and there is no need. The pin only feeds the transistor's base through 1 kΩ, a couple of milliamps. The LED's current comes from VCC. With VCC unwired, the pins switch the transistors and nothing lights.

Will 5 V on VCC damage my 3.3 V ESP32?

No. VCC reaches the two 10 Ω resistors and the two capacitors, and meets neither colour pin anywhere on the board. The transistor's base-to-collector junction points away from the base, so the 5 V side cannot push current back into your pin.

An LED glows faintly before my sketch runs.

Nothing on the board holds a base LOW, so each LED does what its pin does during reset. A pin that floats or is pulled up then can light it until setup() drives the pin LOW. The book's sketches set both pins LOW first.

Where this goes next

What VCC does to the current, and why 5 V is as far as it goes.

Five volts is the limit →

Edit this page — content/books/dual-bright-leds/the-pin-only-switches-it.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Dual Bright LEDs

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum →