Building a Portable AS3935 Lightning Detector with the XIAO ESP32-C3
A handheld lightning sensing and ranging device built around the Seeed XIAO ESP32-C3, a Grove AS3935 Franklin sensor, and a 240x240 round display. For those rare moments when Britain actually has weather.
Building a detector for something that almost never happens is a very British project. The UK averages around 15 thunder days per year. Most of these consist of a single distant rumble heard through double glazing at 11pm while watching television, followed by a brief discussion about whether that was thunder or next door's wheelie bin. In Berkshire specifically, a proper summer storm is a national event worthy of a group chat message and at least three photos of the sky.
Nevertheless, the AS3935 lightning sensor is a genuinely interesting piece of hardware, the Seeed XIAO ESP32-C3 is a capable platform, and there is something deeply satisfying about building a device that will one day, possibly in September, make a noise and display a number. This project is a portable, handheld lightning detector and ranger with a round 240x240 display, an adaptive sensitivity system, and enough firmware complexity to justify writing a post about it.
This is a firmware-focused homage to the original Flash Bee handheld lightning device by gokux on Instructables, which established the physical design and handheld concept. The firmware is a clean PlatformIO project built on top of that spirit. Full source code is on GitHub at github.com/merlinmb/esp32c3_seed_lightning_detection.
How the AS3935 Actually Detects Lightning
Lightning is, among other things, a radio transmitter. A return stroke – the main visible discharge that flows upward from ground to cloud in under a millisecond – produces a broadband electromagnetic pulse with most of its energy concentrated in the band between 500kHz and 1MHz. The AS3935, which AMS named the Franklin detector after the man who invented the lightning rod, is designed specifically to pick up this RF signature.

Inside the chip is an LC tank circuit resonant at 500kHz. This is the antenna front end. When a sufficiently large RF pulse arrives in the right frequency range, the chip wakes up, measures the signal, runs it through its internal algorithm, and raises the IRQ line to tell your microcontroller that something happened.
Distance Estimation
The chip does not have GPS. It cannot triangulate. What it can do is measure the peak signal amplitude of each detected event. Lightning attenuates roughly with the square of distance, so a strike at 10km produces approximately a quarter of the signal of one at 5km. The AS3935 contains an internal Franklin algorithm that maps this measured amplitude to a bucketed distance estimate.
The output comes back in discrete steps: overhead (under 6km), then 5, 6, 8, 10, 12, 14, 17, 20, 24, 27, 31, 34, 37, and 40km, with anything beyond 40km reported as out of range. These are not precise measurements. They are informed estimates based on signal amplitude, which means atmospheric conditions, storm orientation, and local RF noise all affect accuracy. Treat the distance readout as a directional indicator rather than a precision ranging system.
Energy
The energy value is a 21-bit integer read from three consecutive I2C registers on the chip. It represents the raw signal intensity of the detected event. Higher values mean a stronger return stroke. The firmware uses this value to drive the arc gauge on the display edge and the rolling energy history bar at the bottom of the screen.
The maximum possible raw value is 2,097,151. In practice, most strikes come in well below that. The display maps the energy proportionally and colours the arc from dim orange for weak events through gold and eventually white for very strong ones.
Noise, Disturbers, and Adaptive Filtering
The chip classifies every interrupt into one of three categories: a genuine lightning strike (interrupt reason 1), a disturber (reason 2), or a noise floor violation (reason 3). Disturbers are man-made RF events that the chip mistakes for lightning -- motor switching, power line transients, fluorescent ballasts, the washing machine starting, and various other sources of electrical nuisance that are far more common in the UK than actual storms.
The firmware responds to disturbers by incrementally tightening the watchdog threshold and spike rejection settings. Over a quiet 15-second window with no events at all, those settings are gradually eased back to catch weaker distant strikes. When the noise floor is too high, it raises that threshold too and lowers it again after 60 seconds of quiet. The net effect is a detector that adapts to its environment without manual adjustment.
Antenna Tuning
The AS3935 contains a bank of 16 internal capacitors in 8pF steps, from 0 to 120pF. The resonant frequency of the LC antenna depends on which capacitor is switched in. On first boot, the firmware runs an automatic calibration: it enables LCO output mode, which routes the divided-down antenna frequency to the IRQ pin, then sweeps through all 16 capacitor values counting rising edges over a 200ms window for each.
The target is 3906Hz, which is 500kHz divided by 128 -- the chip's internal divider ratio for calibration output. The capacitor value that produces the closest frequency to that target is selected, saved to flash via Preferences, and reused on every subsequent boot. The serial output during this process looks like this:
[TUNE] cap=0 (0pF) 3812 Hz
[TUNE] cap=1 (8pF) 3874 Hz
[TUNE] cap=2 (16pF) 3906 Hz
[TUNE] cap=3 (24pF) 3936 Hz
...
[TUNE] Selected 16pF at 3906 HzThe Hardware
The device runs on three components:
- Seeed Studio XIAO ESP32-C3 -- the microcontroller. Small enough to fit inside the Flash Bee enclosure, fast enough to run the display and sensor simultaneously.
- Seeed Studio Round Display for XIAO -- a 240x240 circular TFT with a CHSC6X capacitive touch controller. The circular form factor is the right choice for a radar-style display.
- Grove AS3935 lightning sensor -- connected over I2C. The firmware scans all three possible I2C addresses (0x01, 0x02, 0x03) across two SDA/SCL pin pairs on boot, so it adapts to slightly different wiring without code changes.
For the physical enclosure, the original Flash Bee Instructables article is the reference. This repository covers firmware only.
The Display
The 240x240 round display shows everything on a single screen with no menus or mode switching:
- A rotating radar sweep animation
- The last detected distance as a large central number in km, OVERHEAD for close strikes, or -- while waiting for the first event
- A semi-circular arc gauge around the edge that fills proportionally to the last strike's energy, coloured from dim to white based on intensity
- Strike count and current energy value in the lower half
- A rolling energy history bar showing the last 20 strikes as columns, most recent in gold
- Live watchdog and spike rejection values at the top so you can see the adaptive tuning working in real time

When a genuine strike is detected, the screen flashes twice with a brief white pulse before returning to normal. Touch gestures handle two functions: hold for 2 seconds and release to clear the history, hold for more than 5 seconds to reboot.
Getting Started
Clone the repository and open it in PlatformIO:
git clone https://github.com/merlinmb/esp32c3_seed_lightning_detection.git
cd esp32c3_seed_lightning_detectionBuild and upload:
platformio run --target uploadOpen the serial monitor at 115200 baud to watch the boot sequence and antenna calibration:
platformio device monitorOn first boot the firmware initialises the sensor, runs the LCO frequency sweep across all capacitor values, prints the selected tuning, and then displays the main UI. Subsequent boots skip the calibration and load the saved value from flash. The whole startup sequence takes around three seconds.
Conclusion

Berkshire will produce exactly one thunderstorm between now and October. It will last eleven minutes, arrive at 9pm when I have already put the device away, and the AS3935 will correctly report OVERHEAD before I even reach the window. At which point I will take a photo, post it to the group chat, and someone will say it is just heat lightning.
The hardware works, the calibration is solid, and the display is satisfying to look at even when showing nothing but a spinning radar line and two dashes. If you are somewhere that actually gets lightning – Florida, central Europe, anywhere in Africa – this thing will earn its keep considerably faster than it will in southern England.
Full source, 3D model files, and platformio.ini are all at https://github.com/merlinmb/esp32c3_seed_lightning_detection.