infrared transmitter/How it works/03. The pin only opens the gate
How it works · 03 of 9

The pin only opens the gate

Your pin does not light the LED. It puts about 2.6 mA through 1 kΩ into a transistor's base, and the transistor lets VCC push 13 to 24 mA through the LED to GND. That is why a 3.3 V pin can switch a 5 V supply, and why the page this replaces was wrong to call the board an LED and its resistor.

Two currents, not one

There are two circuits on this board. A small one runs from your pin through the 1 kΩ into the transistor's base and out of its emitter to GND. A large one runs from VCC through the 150 Ω, the infrared LED and the transistor to GND. The small one switches the large one on.

The pin only opens the gate
VCC wired to
From your pin
0 mA
Infrared LED
0 mA
Red LED
0 mA
SIGNAL is LOW. No current into the base, so the transistor is off, and nothing flows from VCC at all: both LEDs are dark.

Press the button and watch the order. SIGNAL goes HIGH; about 2.6 mA flows into the base; the transistor conducts; and only then does current flow from VCC through both LEDs. Nothing in the large circuit passes through your pin.

Why it is always fully on

The S8050 on this board is sold graded to a gain of 200 to 350: each milliamp into its base lets at least 200 through its collector. Both LEDs together need about 27 mA from 5 V, so the base needs about 0.14 mA. A 3.3 V pin gives it about 2.6 mA, some nineteen times more. That margin is what keeps the transistor hard on, with only a small voltage across it, so nearly all of VCC is left for the LED and its resistor.

The base current is set by the 1 kΩ, not by VCC. So the pin gives the same 2.6 mA whether VCC is 3.3 V or 5 V, and a 3.3 V board switches a 5 V supply with nothing in between.

What VCC never touches

SIGNAL is connected to one resistor, and the resistor to the base. VCC reaches the collector through the LEDs, and a transistor's collector cannot push current back out of its base. So there is no path from VCC to your pin, at any voltage the block is built for. That is the other half of why 5 V is safe here, and it is the opposite of a block like the reed switch, whose SIGNAL is VCC.

One thing the board leaves out: nothing holds the base LOW. Until your sketch drives the pin, the transistor does whatever the pin does during reset, which is why every sketch in this book sets the pin LOW first.

When it does not work

Is 2.6 mA from my pin too much?

No. It is well inside what an ESP32, an ESP32-S3, a Pico or an Uno pin can give. From an Uno's 5 V pin it is about 4.3 mA, still small. The 1 kΩ on the board is what sets it, so there is nothing to add.

Why a transistor and not the pin straight into the LED?

A Pico's pin is set up for a few milliamps, not 24, and any pin could only drive the LED from its own voltage. The transistor lets the current come from any rail up to 5 V, with the pin giving a tenth of it.

Could I use analogWrite to dim it?

It works: the transistor follows the pin fast enough. But dimming only shortens the range, and a remote-control receiver cares about how fast the light flashes, not how bright it is on average. On an ESP32, a pin once used with analogWrite ignores digitalWrite afterwards on core 3.x; use analogWrite(pin, 0) and 255 there.

Where this goes next

What the one wire you choose decides, and where it stops.

Five volts is allowed here →

Edit this page — content/books/ir-transmitter/the-pin-only-opens-the-gate.mdx

Community

Questions about this product

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

Ask a question ↗

Infrared Transmitter

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 →