The AS3935 lightning detector with Arduino creates a powerful storm alert system that detects lightning strikes up to 40 kilometres away — giving you advance warning of approaching thunderstorms. In India, where pre-monsoon storms can arrive rapidly and lightning-related fatalities are among the highest in the world (over 2,000 deaths annually), a DIY lightning detector is both a fascinating project and a potentially life-saving tool for outdoor workers, farmers, and event organisers.
Table of Contents
- How the AS3935 Chip Works
- Components Required
- Wiring AS3935 to Arduino
- Complete Arduino Code
- Understanding Distance Estimation
- Managing False Triggers and Noise
- Adding SMS Alert via GSM Module
- Frequently Asked Questions
How the AS3935 Chip Works
The AS3935 from ams (formerly Austria Microsystems) is a programmable lightning sensor that detects the radio frequency signature of lightning discharges. Lightning produces broadband RF emissions across a wide frequency range. The AS3935 uses a tuned antenna sensitive to frequencies around 500 kHz — the characteristic frequency range of lightning-induced electromagnetic pulses (sferics).
Key capabilities:
- Detection range: 1–40 km (grouped into 14 distance estimation steps)
- Storm distance update rate: 1 Hz
- Programmable detection threshold (to balance sensitivity vs false triggers)
- Separate disturber detection (flags man-made RF interference)
- Interrupt output pin signals lightning, disturber, or noise events
- SPI or I2C interface
- Operating voltage: 2.4–5.5V
Components Required
- Arduino Uno, Nano, or ESP32 development board
- AS3935 lightning detector module (SparkFun DEV-15441 or compatible)
- Active buzzer module (5V)
- LED (red, for visual alert)
- SIM800L GSM module (optional, for SMS alerts)
- 10K resistor (pull-up for interrupt pin)
- Jumper wires and breadboard
- Power supply (regulated 3.3V for AS3935)
Total cost estimate: ₹800–₹1,500 without GSM module, ₹1,800–₹2,500 with SMS capability. The AS3935 module itself costs ₹600–₹1,000 from online electronics suppliers in India.
Wiring AS3935 to Arduino
The AS3935 can operate in SPI or I2C mode. I2C mode is simpler for Arduino projects:
| AS3935 Pin | Arduino Uno Pin |
|---|---|
| VCC | 3.3V |
| GND | GND |
| SDA | A4 |
| SCL | A5 |
| IRQ (Interrupt) | D2 (with 10K pull-up to 3.3V) |
| SI (mode select) | 3.3V (selects I2C) |
Important: The AS3935 is a 3.3V device. Do NOT connect directly to 5V Arduino pins without a level shifter. The SparkFun module includes an on-board 3.3V regulator and level shifter, making it safe to use with 5V Arduino boards.
Complete Arduino Code
Install the SparkFun AS3935 library via Arduino IDE Library Manager: search for “SparkFun AS3935”.
#include <Wire.h>
#include <SparkFun_AS3935.h>
#define INDOOR 0
#define OUTDOOR 1
#define LIGHTNING_INT 0x08
#define DISTURBER_INT 0x04
#define NOISE_INT 0x01
SparkFun_AS3935 lightning(0x03); // I2C address
const int IRQ_PIN = 2;
const int BUZZER_PIN = 8;
volatile bool lightningFlag = false;
void IRAM_ATTR lightningISR() {
lightningFlag = true;
}
void setup() {
Serial.begin(115200);
Wire.begin();
pinMode(IRQ_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
attachInterrupt(digitalPinToInterrupt(IRQ_PIN), lightningISR, RISING);
if (!lightning.begin()) {
Serial.println("AS3935 not found!");
while (1);
}
lightning.resetSettings();
lightning.setIndoorOutdoor(OUTDOOR);
lightning.watchdogThreshold(2); // 1-10, higher = less sensitive
lightning.noiseLevel(2); // 1-7, higher = more noise filtering
Serial.println("AS3935 Lightning Detector Ready");
}
void loop() {
if (lightningFlag) {
lightningFlag = false;
int interruptVal = lightning.readInterruptReg();
if (interruptVal == NOISE_INT) {
Serial.println("Noise detected - not lightning");
} else if (interruptVal == DISTURBER_INT) {
Serial.println("Disturber detected - man-made interference");
} else if (interruptVal == LIGHTNING_INT) {
int distance = lightning.distanceToStorm();
long energy = lightning.lightningEnergy();
Serial.print("LIGHTNING! Distance: ");
Serial.print(distance);
Serial.print(" km, Energy: ");
Serial.println(energy);
// Alert based on distance
if (distance < 10) {
// Close strike - urgent alert
for (int i = 0; i < 5; i++) {
digitalWrite(BUZZER_PIN, HIGH);
delay(200);
digitalWrite(BUZZER_PIN, LOW);
delay(100);
}
} else {
// Distant strike - single beep
digitalWrite(BUZZER_PIN, HIGH);
delay(500);
digitalWrite(BUZZER_PIN, LOW);
}
}
}
}
Understanding Distance Estimation
The AS3935 estimates distance to a lightning strike using the signal strength of the detected electromagnetic pulse. The distance output is categorised in steps: 1 (overhead), 5, 6, 8, 10, 12, 14, 17, 20, 24, 27, 31, 34, 37, 40+ km. This is an estimate — lightning’s energy varies enormously between strikes, so a weak nearby strike and a powerful distant strike might register similar signal strengths.
For a practical storm alert system in India, use these distance thresholds:
- 40+ km: Distant storm, monitor
- 20-40 km: Storm approaching, prepare for shelter
- 10-20 km: Seek shelter immediately
- Under 10 km: Dangerous — remain indoors, do not use electrical appliances
- Overhead (1): Extreme danger — stay away from windows and plumbing
Managing False Triggers and Noise
The AS3935 can generate false triggers from urban RF interference common in Indian cities — mobile phone towers, inverters, two-wheelers with ignition systems, and fluorescent lights. Tune these parameters to reduce false alarms:
- watchdogThreshold (1-10): Higher values require stronger signal to trigger. Start at 2 for outdoor use, increase to 4-5 if getting many false triggers in urban environments.
- noiseLevel (1-7): Higher values reject more background noise. Increase if disturber count is high.
- Indoor/Outdoor mode: Always use OUTDOOR mode for garden or rooftop deployments. Indoor mode uses higher gain and is more sensitive but also more prone to false triggers from electrical interference.
- Spike rejection: Use lightning.spikeRejection(2) to reject 2 consecutive noise spikes before flagging an event.
Adding SMS Alert via GSM Module
For unmanned deployments on farms or construction sites, add an SMS alert using a SIM800L GSM module. The SIM800L costs around ₹200-₹400 and uses any standard Indian SIM card (Jio, Airtel, BSNL).
#include <SoftwareSerial.h>
SoftwareSerial gsmSerial(10, 11); // RX, TX
void sendSMS(String message, String phoneNumber) {
gsmSerial.println("AT+CMGF=1");
delay(100);
gsmSerial.println("AT+CMGS="" + phoneNumber + """);
delay(100);
gsmSerial.print(message);
delay(100);
gsmSerial.write(26); // Ctrl+Z to send
delay(1000);
}
// In lightning detection block:
// sendSMS("ALERT: Lightning " + String(distance) + "km away!", "+919876543210");
Frequently Asked Questions
Can the AS3935 distinguish between cloud-to-ground and cloud-to-cloud lightning?
No, the AS3935 cannot distinguish between lightning types. It detects the electromagnetic signature of any lightning discharge regardless of type. For safety purposes, both cloud-to-ground and cloud-to-cloud lightning present hazards, so this limitation is not practically significant for alert systems.
How do I reduce false triggers from inverters and UPS systems common in Indian homes?
Inverters and UPS units create significant RF interference, especially during switching. Increase watchdogThreshold to 4-5 and noiseLevel to 4-5. Place the AS3935 module as far as possible (at least 2 metres) from inverters, motors, and switching power supplies. Using a metal enclosure for the AS3935 module connected to earth ground also helps shield against local RF interference.
What is the effective range of the AS3935 in Indian monsoon conditions?
During Indian monsoon conditions with heavy rain and high humidity, the AS3935’s effective range may decrease by 20-30% compared to dry conditions. High humidity increases atmospheric attenuation of RF signals. However, 40 km detection range reduces to approximately 28-32 km in heavy monsoon rain — still more than sufficient for meaningful advance warning of approaching storms.
Is it safe to use an AS3935-based lightning detector on a rooftop?
Never install electronics on a rooftop during active thunderstorms. Install the sensor when conditions are safe. The sensor antenna should not be the highest point on your structure — a nearby taller object or a lightning rod installed per IS 2309 standards provides physical protection. Never assume an electronic lightning detector provides physical protection against lightning strikes.
Can I log AS3935 data to ThingSpeak to create a historical lightning map?
Yes. Upload each lightning event’s timestamp, distance, and energy level to ThingSpeak using an ESP32 instead of Arduino. MATLAB Analysis in ThingSpeak can then create time-series charts of lightning activity. Sharing your data with organisations like India Meteorological Department (IMD) or academic researchers via open data platforms contributes to improved lightning forecasting for India.
Add comment