Loading DesignSpark, please wait...

We apologise for the slowness of this page You are using Internet Explorer 6, upgrading your browser will greatly enhance your experience using DesignSpark

The gateway to online resources and design support for engineers, powered by RS ComponentsAllied


Detecting Lightning with an Arduino

Posted by Andrew Back on



This post takes a look at interfacing the novel AS3935 lightning sensor with an Arduino.

The AS3935 works by detecting radio frequency emissions generated by lightning activity, and uses algorithms to distinguish these from man-made “disturbers” and to calculate the energy from strikes. From which it's able to then estimate the distance to the head of the storm over a 1–40km range.

The manufacturers, AMS, say that the AS3935 can be used “to protect both humans and equipment from harm by providing early warning of impending danger.” Suggesting that potential applications include use in hiking, at marine and sporting events, and with telecoms equipment, uninterruptible power supplies (UPS) and power conditioners etc.

Breakout board

The sensor is housed in a 4x4mm package and draws only 60uA in listening mode, and will issue an interrupt when lightning is detected and can be interfaced using I2C or SPI.

The compact MLPQ-16 packaging is great for building into an end user product, but is not particularly friendly for experimenters and prototyping with only access to simple tools. Fortunately, Tautic Electronics have produced a development board that includes the required antenna and passive components.

Arduino library

The comprehensive datasheet provided includes all the information required to write your own code to interface with the AS3935, but this has been made much easier for Arduino users thanks to a library from Raivis Rengelis. This includes functions for:

  • power up/down and reset

  • calibrating the antenna

  • getting/setting the noise floor

  • getting/setting the number of strikes before interrupt is raised

  • returning the source of the interrupt (noise, disturber or lightning)

  • returning the distance to the head of the storm

The library also comes with an example sketch.


The main loop for lightning detection is very simple and the output from running the sketch can be seen below.


Not surprisingly, this isn't particularly exciting. Nor will use of the sensor ever be unless a lightning storm is nearby!

Note that with Arduino boards other than a Mega 2560 it may be necessary to change some pin definitions. When using an Arduino Ethernet I chose to use pin 9 for SPI Chip Select since 10 is used by the Ethernet chip, and pin 2 was used for interrupts since this is int.0 on the board.

A useful design


Here in the UK we don't get lightning storms that often and for the best chance of catching one the detector really needs to be powered up 24/7.

In order to turn into a useful design I'll probably house the Arduino and shield in an enclosure so that I can forget about them without fear of damage. Using the example sketch to develop one that logs data to a platform such as Cosm, thereby enabling strikes and their intensity/distance to be graphed over time.

Andrew Back




  • aeronautico Avatar aeronautico

    Posted by aeronautico at

    Please can you help me?
    When I try to run the code gives me the following:
    'AS3935' does not name a type to
    LightningDetector: 48: error: 'AS3935' does not name a type
    LightningDetector.pde: In function 'void setup ()':
    LightningDetector: 64: error: 'AS3935' was not declared in this scope
    LightningDetector.pde: In function 'void loop ()':
    LightningDetector: 102: error: 'AS3935' was not declared in this scope
    LightningDetector.pde: In function 'void printAS3935Registers ()':
    LightningDetector: 130: error: 'AS3935' was not declared in this scope
    Can you help me?
    Already used several versions of Arduino and the error is always the same

  • willmer Avatar willmer

    Posted by willmer at

    hi yall,

    i will like to interfacing the IC AS3935 with the AT89C51AC2 from ATMEL using I2C BUS , could somebody help me with the Code ?

    i'm not really into Programming.. and i really need some help.

    thx in Advance


  • tautic Avatar tautic

    Posted by tautic at

    @aldebaran - I tried sending a message to you through the contact function here on designspark, but I'm not sure it is working. Sorry to hear of the trouble with the board - i'm more than happy to help please send me an email at jayson at tautic dot com with the detail you've collected on the issue. Best Regards, Jayson

  • aldebaran Avatar aldebaran

    Posted by aldebaran at

    Greetings everyone: I purchased the The Franklin Lightning Sensor breakout board from these guys: https://tindie.com/shops/TAUTIC/as3935- ... sor-board/ As I wanted to use a PIC processor to control it, I wrote code to communicate with it using the compiler that came with my PIC development system. I chose the I2C interface as I ultimately intended to attach other sensors to that interface. I referred to all the data that I could find concerning the wiring, capabilities and protocol for that chip. That interface was rather difficult to understand from the confusing documentation provided by AMS. So I decided to use SPI as it is easier to debug via my logic analyzer. Tried everything but no luck. I checked all the wiring and power to make sure that it was correct and it was, so I don't believe that I have killed the chip. I went looking for help and examples but all the code that I could find as an example is locked up in libraries. I wrote up the entire thing, complete with pictures of the wave forms and sent it of to the chip manufacture several weeks ago: http://www.ams.com/eng/Products/RF-Prod ... sor/AS3935 No replies so far. So I tried to communicate with the tindie vendor of the breakout board and as far as I can find there is no way to communicate with them. I am at an impasse at the moment as I cannot tell if I am doing something wrong, if the chip is dead or something else. Can anyone help on this? Thanks in advance...

  • rgrokett Avatar rgrokett

    Posted by rgrokett at

    Just a note that Arduino UNO will work fine with the library and Tautic card.
    With the USB UNO, I didn't have to change the library or example code. I just connected the pins as follows:

    breakout pin arduino pin Uno

    VDD 5V - Mega 2560
    MOSI 51 11
    MISO 50 12
    SCLK 52 13
    IRQ 2 2
    SI GND
    CS 53 10

    Then plugged it in and build & installed the example. Connected to it over USB serial and got the above mentioned output. I am in Florida, so plenty of lightning... even a chance of a storm in a day or two from now!

  • stormy44 Avatar stormy44

    Posted by stormy44 at


    Do you think that is possible to use the AS3935 board with a arduino uno instead of a arduino mega ?

    thank you very much.


  • ascii68 Avatar ascii68

    Posted by ascii68 at

    link to AS3935 data -page Austria

    http://www.ams.com/eng/Products/RF-Prod ... ing-Sensor

    pdf manual can be downloaded. no free samples available from ams.
    price per chip 3.55USD..

    I consider to get one chip and make my own "breakout board" in conjunction
    with Cypress PSoC3 Kit 030 , while i have no Arduino at hand.

    greetz Markus

  • tautic Avatar tautic

    Posted by tautic at

    The link to the lightning board on tindie changed over night after an upgrade. You can now find them here: https://tindie.com/shops/TAUTIC/as3935- ... sor-board/

Leave a comment