Can one LED both send and receive data between two ESP32 boards? Luca Soltoggio’s SecurePair project says yes, and it works with the same ordinary 5 mm LED you probably have in a parts drawer.
What the project does
SecurePair is an Arduino library for pairing devices and exchanging keys, then talking with encryption. The headline hack is the hardware: two ESP32 boards trade data using visible light, with a single LED on each board acting as both transmitter and receiver. Hackaday’s write-up is at hackaday.com, and the demo video shows the boards pairing across a gap with no radio involved in that step.
The library is not limited to light. It is also designed to work with ESP-NOW or LoRa, so a realistic setup pairs the boards optically first, then moves the encrypted traffic over radio. The examples use two boards, but more nodes can join the same conversation.
How can an LED listen?
An LED is a diode, and a diode that is hit by light leaks a tiny photocurrent, much like a cheap photodiode. Forward-biased, the LED emits. Reverse-biased or left floating on a GPIO, it senses. Firmware flips the pin between the two roles, so the same part blinks out bits, then flips to input and reads the other board’s blinks.
The gotcha is signal strength. A red 5 mm LED only produces microamps in ambient light, so you read it with the ESP32‘s 12-bit ADC (0 to 4095 counts at 3.3 V) instead of a plain digital read. Keep the two LEDs pointed at each other within a few centimeters, shield them from sunlight, and use a resistor around 220 ohms on the transmit side.
The timing is also tricky. Because the LED has to switch roles, you need a clear protocol with gaps between turns, or both boards will talk and neither will listen. Slow bit rates, a few hundred bits per second, are plenty for exchanging a short key.
Try it
Start with two ESP32 DevKit boards, two LEDs, and a pair of jumper wires on a breadboard. Pick any free GPIO such as pin 18 on each board, point the LEDs at each other, and read the library examples on GitHub before writing your own code. Both boards are in our Arduino-compatible lineup at circuit.rocks, with ESP32 DevKit modules usually priced from around PHP 350. If your reads look noisy, average 16 ADC samples per bit before you decide whether it is a 0 or a 1.
Frequently Asked Questions
How can one LED both send and receive data?
An LED also behaves like a weak photodiode. The firmware drives the pin to emit light when transmitting, then switches it to a sensing role and reads the small signal from the other board’s LED.
What parts do I need to try this?
Two ESP32 boards, two LEDs, a resistor around 220 ohms, a breadboard, and jumper wires. SecurePair is an Arduino library, so the Arduino IDE with ESP32 board support is enough.
What will I learn if I build this?
You learn how LEDs act as light sensors, how to read analog signals with the ESP32 ADC, how to design a turn-taking protocol, and how key exchange and encryption fit into an IoT pairing step.
