Lightning! the Lightning Detector for Raspberry Pi Weather Station (Updated)




About: SwitchDoc Labs, LLC is a software and hardware engineering company producing specialized products and designs for the small computer industry maker movement (Raspberry Pi, Arduinos and others). The Chief Te...

In this Instructable you will learn:

  1. How to a connect a Lightning Detector to a Solar Powered Weather Station
  2. How to design and position the lightning detector for best perfomance
  3. How to gather data to see the Lightning story as it happens
  4. How to wire up a the lightning detector to an I2C Mux and a Raspberry Pi
  5. Building 3D Printed Parts for the pylon to hold the Lightning Detector
  6. Examine the Python software for running the Lightning Detector on a Raspberry Pi

Recently, we published an Instructable detailing how to build a solar powered Raspberry Pi weather station, WeatherPi.

Updated: February 6, 2016: Changed to new I2C Mux Board. Grove 4 Channel I2C Mux Board.

What is Weather Pi?

WeatherPi is a solar powered Raspberry Pi WiFi connected weather station designed for Makers by SwitchDoc Labs. This is a great system to build and tinker with. All of it is modifiable and all source code is included. The most important functions are:

  • Senses 20 different environmental values
  • Completely Solar Powered
  • Has a full database containing history of the environment (MySQL)
  • Monitors and reports lots of data on the solar powered system - great for education!
  • Self contained and monitored for brownouts and power issues
  • Can be modified remotely
  • Download your data to crunch it on your PC
  • Can be modified to do SMS (Text) messaging, Twitters, webpages and more
  • Has an iPad Based Control Panel
  • Easy to connect to Twitter, WeatherUnderground, etc

Enter the Lightning

This Instructable will show you how to add an Embedded Adventures MOD-1016 AS3935 Lightning Detector Breakout Board to the Solar Powered Raspberry Pi Weather Station.

Follow along on updates to the WeatherPi story on

What is the AS3935 and How Does It Work?

The Austrian Microsystems AS3935 is a programmable Lightning Sensor IC that detects the presence and approach of potentially hazardous lightning activity in the vicinity and provides an estimation on the distance to the head of the storm. The embedded lightning algorithm checks the incoming signal pattern to reject the potential man-made disturbers and various noise sources.

The AS3935 can also provide information on the noise level and inform the Raspberry Pi of high noise conditions.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Connect the Lightning Detector to WeatherPi

The complete Instructable for building WeatherPi, a solar powered Raspberry Pi based Weather Station, including the parts list and full wiring list is here.

Since we left our other MOD-1016 AS3935 breakout board on the WeatherPiArduino board for the time being, we decided to add an additional MOD-1016 AS3935.

Since the MOD-1016 has a fixed I2C address (0x03), we couldn't connect it up to the same I2C bus as the WeatherPiArduino board is on. So, using the I2C Multiplexer board, we put the second MO-1016 on bus 2.

We are always running into conflicts with addressing on the I2C device. Since there are no standards, sometimes multiple devices will have the same address, such as 0x03, and you are just out of luck in running both of them on the same I2C bus without a lot of jimmy rigging.

4 Channel Multiplexed I2C Breakout Board

To get around this addressing problem (specifically the conflict between an INA3221 and the Inside Humidity Sensor as well as having two identical lightning sensors - see below) we added an I2C Bus Multiplexer to the design which allows us to have many more I2C devices on the bus, irregardless of addressing conflicts. Below is our current list of I2C devices in WeatherPi.

ModuleAddressI2C Mux Bus #
BMP180 Barometric Pressure0x77Bus 0
Real Time Clock DS32310x68Bus 0
ATC EEPROM0x56 (or 0x57)Bus 0
ADS1015 Analog to Digital Converter0x49Bus 0
FRAM non-volatile storage0x50Bus 0
ADS1015 on SunAirPlus0x48Bus 1
INA3221 3 Channel Voltage/Current Monitor on SunAirPlus0x40Bus 1
Embedded Adventures Lightning Detector0x03Bus 0
Embedded Adventures Lightning Detector0x03Bus 2
AM2315 Outdoor Temp/Humidity0x5CBus 1
Grove I2C 4 Channel I2C Bus Mux0x73On All Busses
HTU21D-F Humidity Sensor0x40Bus 0

Note that a number of devices have the same address. This is fixed by using the Grove I2C Mux Breakout Board.

Wiring List

These are just the additions to the wiring list for the AS3935 Breakout Board connected to Bus2 of the I2C Mux and placed in the 3D Printed Pylon. The full wiring list for WeatherPi is in the Instructable.

Grove I2C Mux Board (GI2CM)
JP5 - I2C Bus2External AS3935 Breakout Board (ASBB)
GI2CM JP5/Pin 3: VDU2

3.3V From Pi/Screw Connector

3.3V From Pi/Screw Connector


External AS3935 Breakout Board (ASBB)

External AS3935 Breakout Board (ASBB)

JP5 - I2C Bus2


3.3V From Pi/Screw Connector

3.3V From Pi/Screw Connector


GI2CM JP5/Pin 2: GND

GND for ASBB Board

GI2CM JP5/Pin 5: SC2

SCL for ASBB Board

GI2CM JP5/Pin 4: SD2

SDA for ASBB Board

PiA+ GPIO/Pin 15: GPIO 22

IRQ Line to Raspberry Pi

Here is what the I2C bus looks like on the Raspberry Pi. This is the output from the example code with the I2C 4 Channel Mux (hence there are 4 independent busses shown for the I2C bus).
Note that WeatherPi uses Bus 0, Bus 1 and Bus 2.

Bus 2 is only used for connecting to the external MOD-1016 AS9535 Lightning detector. Running the test software for the I2C Mux Breakout Board gives the following results:

Test SDL_Pi_TCA9545 Version 1.0 - SwitchDoc Labs

Sample uses 0x73
Program Started at:2015-05-19 02:45:59

-----------BUS 0-------------------
addr = 0x73 returndata = 0x81 
tca9545 control register B3-B0 = 0x1
ignore Interrupts if INT3' - INT0' not connected
tca9545 control register Interrupts = 0x8
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- -- 49 -- -- -- -- -- -- 
50: 50 -- -- -- -- -- 56 -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- -- 
70: -- -- -- 73 -- -- -- 77                         


-----------BUS 1-------------------
addr = 0x73 returndata = 0xa2 
tca9545 control register B3-B0 = 0x2
ignore Interrupts if INT3' - INT0' not connected
tca9545 control register Interrupts = 0xa
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: 40 -- -- -- -- -- -- -- 48 -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- 73 -- -- -- --                         


-----------BUS 2-------------------
addr = 0x73 returndata = 0x84 
tca9545 control register B3-B0 = 0x4
ignore Interrupts if INT3' - INT0' not connected
tca9545 control register Interrupts = 0x8
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          03 -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- 73 -- -- -- --                         


Step 2: Testing the Lightning Unit

Not surprisingly, this lightning detection device is very sensitive to RFI (Radio Frequency Interference) sources. If you have your device next to a monitor, it will not work well. If you have it next to a cell phone, it will not work well. As you will see below, we had to mount the detector well away from the Raspberry Pi and Solar Power Controller to get it to work well.

When we found the AS3935 device, we were pretty excited about using it in a design. One of the issues we quickly found ourselves facing was how to test the AS3935 in our own design. As noted in a previous step, we could cause noise to happen by placing close to monitors and cell phones (which actually tests a lot of the hardware and software, but nothing really about sensitivity in a measured, calibrated way), but we wanted something more accurate to test it with. We could cause interrupts (mostly of the noise floor type), but few lightning bolts.

We ended up buying the AS3935 Touch Sensor Development Tools Franklin Lightning Sensor IC Development Kit from It set us back $230, which was more than we wanted to pay, but we quickly used it to diagnose a number of the problems in the design and the device placement.

As we were finishing this Instructable, an actual thunderstorm came by SwitchDoc Labs. Unfortunately, We had the AS3935 all taken apart in pieces, so we grabbed the development kit and turned it on and were quickly rewarded with a number of lightning bolt detections.

Later on in the weekend, a real thunderstorm rolled through about 6km away and produced this data, shown on RasPiConnect. The WLAN Down messages are from an ongoing problem with WiFi disconnects. We reset the WiFi dongle if there is a disconnect and log the event.

These detections were after we moved the lightning detector out into the pylon (actually, we just added another one rather than unsolder the one on the WeatherPiArduino - we will do that later next week).

Step 3: 3D Print Your Lightning Pylon

Problem Mounting the AS3935 Inside the Box

We installed the MOD-1016 containing the AS3935 on the header provided on the WeatherPiArduino board. You can see it installed in the center of the picture below.

The AS3835 Breakout Board Installed on WeatherPiArduino

This turned out not to be a good location. Too much noise from all the other components surrounding it. We were getting interrupts telling us to adjust the noise floor and then you had to be right on top of it with the lightning simulator to get any response at all. We needed to move it away from the other electronics. In hindsight, we should have known that this would happen. The solution? Move it away from the box in a pylon. We thought of moving the WeatherPiArduino into a pylon, but we decided to just put an AS3835 in the pylon. See the 3D Print files above. Below is what the three parts look like on the screen in OpenSCAD and then it is followed by a picture of the pylon printed and installed on the WeatherPi Box. Here are the OpenSCAD files for the pylon.

The 3D Printed Parts of the Lightning Pylon

Step 4: The Software for the Lightning Detector

After quite the search and playing with a number of packages, we found a good package by Phil Fenstermacher. With a little fooling around and setting up interrupts, we got the software to work.

The full software for WeatherPi, which includes the AS3935 software is available on

Here is the setup software:


# ad3935 Set up Lightning Detector

# turn I2CBus 2 on

as3935 = RPi_AS3935(address=0x03, bus=1)


as3935LastInterrupt = 0
as3935LightningCount = 0
as3935LastDistance = 0
as3935LastStatus = ""

as3935Interrupt = False
# turn I2CBus 0 on
Next the processing software for the Interrupts.
def process_as3935_interrupt():

    global as3935Interrupt
    global as3935, as3935LastInterrupt, as3935LastDistance, as3935LastStatus

    as3935Interrupt = False

    print "processing Interrupt from as3935"
    # turn I2CBus 0 on
    # turn I2CBus 2 on
    reason = as3935.get_interrupt()

    as3935LastInterrupt = reason

    if reason == 0x00:
        as3935LastStatus = "Spurious Interrupt"
    elif reason == 0x01:
        as3935LastStatus = "Noise Floor too low. Adjusting"
    elif reason == 0x04:
        as3935LastStatus = "Disturber detected - masking"
    elif reason == 0x08:
        now ='%H:%M:%S - %Y/%m/%d')
        distance = as3935.get_distance()
        as3935LastDistance = distance
        as3935LastStatus = "Lightning Detected "  + str(distance) + "km away. (%s)" % now
        pclogging.log(pclogging.INFO, __name__, "Lightning Detected "  + str(distance) + "km away. (%s)" % now)

    print "Last Interrupt = 0x%x:  %s" % (as3935LastInterrupt, as3935LastStatus)


The Interrupt Handler. Short and Sweet, as interrupt handlers should be.
def handle_as3935_interrupt(channel):
    global as3935Interrupt

    print "as3935 Interrupt"

    as3935Interrupt = True

Setting up the Raspberry Pi GPIOs to receive interrupts.
#as3935pin = 18
as3935pin = 22

GPIO.setup(as3935pin, GPIO.IN)
#GPIO.setup(as3935pin, GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(as3935pin, GPIO.RISING, callback=handle_as3935_interrupt)

And the reporting software for reading the Interrupts.

        # process Interrupts from Lightning

        if (as3935Interrupt == True):


                        print "exception - as3935 I2C did not work"

Step 5: See the Real Results!

We have been running the AS3935 breakout board in the WeatherPi pylon for the past 5 days. We have had two thunderstorms come through during that time. The first storm was pretty week and just moved through north of SwitchDoc Labs. Our president, Laurel, was out playing golf (the benefits of power and position) and she called us to tell us that the lightning storm had come by, and we got to tell her that we already knew. Below are the lightning logs from our RasPiConnect control panel. Note that there was no wind measured during as we had the WeatherRack Weather Sensors disconnected as it was plugged into Project Curacao (and did pick up the wind), which is heading to the tropics shortly.

Next up was a big storm two days later that really rocked! You can see (reading the log backwards according to UTC timestamp) the storm approach and then go by and depart. Came within 6km of SwitchDoc Labs.

And it texts us reports too!

Step 6: Conclusion

Adding the lighting detector to the solar powered WeatherPi turned out to be quite straightforward in terms of software and wiring, but the real key to making it work was placing the sensor away from all the other electronics.

Our next project, a solar powered semi-autonomous robot called SunRover is also using this sensor. We will mount it in a pylon that is far away from the three computers in SunRover and especially away from the Raspberry Pi 2 (which is the main brain of the robot).

Here are some additional ideas for projects based on the WeatherPi Lightning Detection system:

  • Replacing the WiFi with a GSM data connection (or just send text messages) Make it tweet lightning warnings! Make a custom Facebook posting with your lightning strikes
  • Adding a GPS receiver and store that data
  • You now have a mobile lightning detection system! When it gets back to WiFi all the stored data will be available.
  • Connect to the WeatherUnderground or similar services

Be the First to Share


    • Assistive Tech Contest

      Assistive Tech Contest
    • Reuse Contest

      Reuse Contest
    • Made with Math Contest

      Made with Math Contest

    14 Discussions


    3 years ago

    Updated February 6, 2016: Changed parts list and wiring diagrams to new Grove I2C 4 Channel Mux Board.



    2 years ago

    Regarding the Embeddedadventures' MOD-1016 module.
    I bought 3 and only 1 was able to detect SOME lightning. Sometimes it was sunshining and it detected lightning.
    Other 2 modules has never worked. Recently a lightning strikes hit two ladies ~2 km from me. No result. Nothing was detected. Neither the storm in my city.
    Last but not least: it is an adventure to get answer from Embeddedadventures.

    According to the comment policy I should be nice, but before you order anything ask them about support, warranty exchange etc. My experience is no support and rarely answer emails.

    1 reply

    Reply 2 years ago

    We understand your frustration. A couple of comments. 1) Sometimes the lightning detectors will detect power tools in the area, especially if they are old and dirty. Sparks you know.

    2) We are in the last stages of building a lightning simulator that SwitchDoc Labs will be offering. That makes it a lot easier to test.

    3) The embedded systems MOD-1016 is sensitive to I2C Loading. Test it with NOTHING else on the I2C bus. That will help isolate the problem. Our new lightning detector has an I2C buffer on board to eliminate that problem (still under development).



    i2cdetect -y 1 picks up the embedded adventures AS3935 board.

    Either your board is bad or you have it hooked up wrong. I’ve had very good luck with the Embedded Adventures board.


    1 reply

    John..Ok. Well, I ordered the Embedded Adventures board. Assuming that it shows up with ic2detect, any hints on how to get the demo program running. Even with the (assumed) bad board, wouldn't it at least show some error messages if I started the program up?

    Thanks, Steve


    4 years ago on Introduction

    hello..I am trying to run the demo as3935 program I downloaded from the GitHub depository you referenced in the instructable. I am a noobe with Python, and I cannot figure out how to get the program running to see if my as3935 is even working. Any suggestions would be appreciated. Thanks, Steve

    2 replies

    Hi Steve,

    First thing to do is connect things up and see if you even see the As3935 on your I2C bus. i2cdetect -y 1 will do it. If you see the AS3935 then you have that working!

    Tell me the exact repository you downloaded it from ( and I'll help you out.



    Hi John, Thank you very much for offering to help me. Here is information that you may need; I have this AS3935 break-out board;

    i2cdetect -y 1 did not show the board, but according to this it may not show up: This is the same repository I downloaded from.

    I first tried it on my RasPi 2, and when it was not detected there I switched to my "test bed" RasPi B+ with the same result. With the possibility that the board is bad and/or not compatible with the RasPi, I have ordered the same one you are using from Imbedded Adventures.

    I am attempting to integrate it into my weather station which is online here:

    Your instructable is great, and while I won't be building the entire station as you have, I may look into a way to get the lightning sensor and possibly a cam outside.

    Again, many thanks for any help you can give.

    Just4Fun Media

    4 years ago

    Interesting build! How water "proof" has your enclosure been?

    I would worry about my electronics in storms. Hopefully yours is working well!

    Have a great day! :-)

    1 reply

    The BUD enclosure is a good enclosure. Make sure you seal all the holes with silicon caulking into the enclosure. It would be good to seal the seams on the lightning pylon too. I've had BUD enclosures outside for up to a year with no problems.


    4 years ago on Introduction

    I just finished up soldering up my new red sensor system and it has provisions to add the AS3935 for local lightning detection. I am looking to added it, but was wondering did you need the $230 development board to trouble shoot the software or for actual placement and function. The cost seems a little steep and just want to spend the $25 for the actual card. My next project is going to be your weatherpi. Can't wait, now I have to buy two AS3935.

    1 reply

    Now that I understand the sensor much better, I would say it is not worth it to buy the $230 development board. I was writing an article about it and had no good way to test it, so I bought it. It is really steep! Now that I understand the sensor and how far away to mount the sensor from the electronics, I wouldn't buy it. I guess if I could have read my article before I bought it, I could have saved myself some money!


    4 years ago