Disclaimer and Social

This page may contain affiliate links. As an Amazon Associate I earn from qualifying purchases.

Sunday, April 28, 2019

Lightning Detection with Arduino

Summer heat and those amazing afternoon thunderstorms are already starting, so I'm thinking of adding a lightning detector to my DIY weather station. I've wanted a lightning sensor for a while, but they have always been expensive, tricky to calibrate, and had a bad reputation for hobby level users.

However, two things have changed this year and both make it possible for even an amateur like myself to connect a reliable lightning sensor to my Arduino - all for around $30 USD.

Lightning sensor detectors for Arduino DIY Weather Station
My DIY weather-station needed a lightning detector sensor for my Arduino base unit. Luckily there are several good options that are easy and cheap to buy and install.


First, vendors have recently begun selling reliable, easy-to-use boards based on the AS3935 detector chip. Even better, the supporting code libraries and tutorials are finally understandable to mere mortals. With that combination, I expect to see more options like this coming onto the market.

Second, I now know enough to hack into those cheap commercial lightning sensors, take the alert/alarm signals and feed them into my microcontroller - all without destroying the sensor. That might be simple for you, but it's a big deal for me.

(If you just want to watch the lightning strikes visit Lightningmaps.org or Blitzortung.org or make your own node at en.blitzortung.org/cover_your_area.php.)

BREAKOUT BOARDS - Just Add Lightning

The AS3935 detector chips have the ability to sense cloud-to-ground and cloud-to-cloud lightning up to 40 km (25 mi) away. They can tell you roughly how far away the strike occurred within a mile or so accuracy. They offer the ability to tune discrimination to avoid false positives from nearby electric events. And they can be accessed with the simple to use I2C or SPI communication protocols.

The new libraries do all the heavy lifting, accessing the registers and interpreting the obscure ones and zeroes into human readable data that can be sent directly to your controller board. You can easily display the information in any format you choose, like numbers, charts or graphs. You can sample and record the data. And you can trigger other events based on conditions.

So you can easily show the distance and number of lightning strikes, send out an alert over the internet or SMS, then turn off and disconnect your appliances. Or you could wait to trigger the events until there are more than five strikes, or they are closer than 10 km.

Sparkfun offers one of these AS3935 detector boards with a pre-written library and an excellent hook-up guide. For a beginner, Sparkfun is a good investment. Their products are solid and their tutorials are helpful. The other big hobby electronics suppliers will probably release a board this summer, but right now, this is the breakout board I would choose.

If you can't order from Sparkfun, there are other breakout boards on Amazon like the CJMCU version (affiliate) and the SwitchDoc (affiliate) version. Both of these versions use the same AS3935 chip, so you should be able to use mix any valid library and use it to interface with the board. The Switchdoc offers both a Python and traditional C libraries as well as Grove style connector and basic hooks into an app.

I needed to add the raw data to the custom display that I've already built. And by now, I am comfortable installing and configuring libraries, choosing and wiring I2C and SPI and parsing serial data. So the breakout board was the solution for me.

There is an excellent guide for hooking up the AS3935 breakout board to an ESP8266, (affiliate)  complete with JSON data transfer over WiFi. He even makes a sleek pyramid shaped light alarm. Full details including code are on GitHub.

But what if all you want is a simple trigger, like a button press, every time lightning strikes nearby. Maybe you need to checkout the pre-built commercial lightning sensors and hack one of them.

HACK AN EXISTING SENSOR

You can get standalone lightning detectors that range in price from under $30 to over $500. I've picked out two inexpensive and hackable lightning detectors on Amazon. By hackable, I mean that the units have an LED and speaker that get triggered when lightning is detected. You can tap into the wires leading to the speaker or LED and basically use the lightning detector as a button. When the LED or speaker is activated, the Arduino reads the signal and knows a lightning strike has occurred.

These also have a couple of additional advantages over the breakout boards: 1) They already work with no programming or wiring 2) They already have a weatherproof case designed for use outdoors. With a little thought, you could make a quick connect port to hook up to the Arduino, then disconnect and carry them on hikes like it was intended. Or you could even use a light-sensor or microphone on your Arduino  to monitor the detector's LED and speaker for a clever and totally non-invasive hack.

Their 02020 detector (affiliate) from AcuRite is a complete standalone unit. It has a built-in display that shows the distance and number of strikes. It allows you to do basic tuning for either outdoor use or a more electrically noisy indoor use. It does not send out WiFI or RF data. But it does have an alert LED and a speaker that are easy to connect to an Arduino.

The 06045M, (affiliate) also from AcuRite, is an even less expensive option. This unit has temperature and humidity sensors as well as the lightning detector. However, it does not have any graphic display, just an LED and buzzer to alert you to lightning strikes. Instead of displaying the data, it sends the data wirelessly to an AcuRite base station (see below for compatible base units).

Check out the video reviews of these two items.

I prefer the breakout board over these standalone sensor units for use with Arduino. The breakouts allow me to get more detailed information about the lightning events, then display it any way I want and make complex decisions for triggering events in my smart home system. But I like these standalone sensors because I still go hiking in areas where I can't get cell service. Nothing like cresting a mountain ridge 10 miles into a hike and seeing a huge, previously hidden lighting storm headed your way. One of the engineers over at Sparkfun is making a portable version out of their breakout board, and it looks promising. And at these prices, you could get both types.

READY TO GO KITS

What if you don't want to hack together a system, no soldering, no code, no UI design for displaying the information? What if you just want a ready-to-go system that already includes lightning detection and a complete display and communication system? Well, there are several excellent and relatively inexpensive choices that are ready to work out of the box.

The AcuRite 01022M Pro (affiliate) as well as the 01024M Pro (affiliate) and even the inexpensive 01021M(affiliate)  all include lightning detection using the same 06045M (affiliate) lightning sensor discussed above. Plus, they all have lots of other weather sensors and a full color graphic display.

Keep in mind, you can have one of these commercial systems and still hack into your Arduino. Because the 06045M (affiliate) lightning sensor is a separate unit and hackable without destroying its connection to the rest of the system, this commercial option might be the best of both worlds.

You can use the fancy pre-built display in your living room to impress your guests, and be assured that the sensors and display will always work. Meanwhile, out in the shop you can hack directly into the sensor itself and connect it to your microcontroller. You can rework your code and wiring to your heart's content without giving up reliability.

For less than $100, I might even get one of these kits. Why? Because I spend so much time rewriting code, rewiring, upgrading the display UI, and just generally tinkering with my DIY weather station that I'm lucky if it's working 50% of the time. I've been known to hastily reassemble the station before a big weather event only to find out I didn't get everything right, or get strange results. With a backup I'm always ready and have a way to test my calibrations on the DIY version.

STARTING FROM SCRATCH

I started my weather station with a bare-bones kit from Sparkfun. The kit was very similar to the one from WeatherRack. (affiliate) It included a wind-speed anemometer, a wind direction vane and a rain gauge. "Modest Maker" has a whole series of videos on setting up this type of system. There is also a nice guide to setting up this type of kit on Instructables..

That's all I needed because I already had sensors for temperature, barometric pressure, humidity, light and UV plus the required controllers and displays. Sparkfun does sell a board with many of those extra sensors plus RJ11 connectors for their wind/rain kit. They even sell an all-in-one kit designed for the micro:bit board.

RAIN GAUGE
These kits use the "Tipping Bucket" style rain-gauge. Many use a magnetic reed switch tor Hall-effect that triggers every time the collector buckets tips. Others use a button under each side of the tipper bucket. Wikipedia has a good explanation of how tipping bucket gauges work. Hooking it up to an Arduino is simple, and you can even hack one from another system.

WIND SPEED
Most of these kits use a cup style anemometer (wind speed) gauge as well as a wind vane for sensing wind direction. However, there are some systems that combine the anemometer and vane into a single unit.

The wind speed gauge (anemometer) uses a magnetic reed switch or Hall-effect sensor that gets triggered whenever the cups of the anemometer make a revolution. There are simple explanations, as well as detailed explanations, but there are subtle gotchas that have to be accounted for; so a good in-depth guide to hooking one up to an Arduino is essential for getting accurate results.

WIND DIRECTION
The wind vane for sensing direction is one of the most complicated parts. Most hobby kits can sense eight or 16 sixteen possible wind directions. Most use a series of magnetic reed switches or Hall-effect sensors that feed the power signal to one or more return lines. Each return line has a different value resister. Depending on how much power gets back to the Arduino, you can tell which way the vane is pointing.

HUMIDITY
A few years ago the standard was the DHT-11 or the DHT-22 humidity sensors. There are lots of good tutorials still out their for using them. But I would not recommend them now. There are much better sensors out tthere for about the same price. Adafruit did a good introduction to these new sensors. On Amazon, (affiliate link) you can purchase the old DHT-11/22 in multi-packs, but if you scroll down you get to some of the new sensors, many of which also include temperature sensors or even barometric pressure sensors.

COMMUNICATION
Since I started playing with weather kits, I've also added Bluetooth, LORA and Wi-Fi capabilities. Right now, LORA is my favorite because it can send signals a good distance with low power draw. That means I can put the sensors in open areas away from buildings and still get reliable readings. And I can run the LORA board on a small solar battery charger even in extended periods of dreary weather.

If all you need is the temperature, humidity and pressure (or maybe display and WiFi controller) there are great inexpensive starter kits.(affiliate

But if you need a complete weather station kit, you can get a nice one from Switchdoc (affiliate) with all the basic sensors, controller, display and WiFi connection for displaying info on apps.

NOTE: As a DIYer, you already know that all these options will turn out to be more expensive, more troublesome, less reliable and less capable than the fully assembled ready-to-run versions. But they are yours to hack and modify however you want. Doing everything from scratch, solving the problems before creating more and planning the next upgrade is totally worth a few extra dollars and hours of labor because, well... because that's just what we do.

CONCLUSION

If it's so complex and bothersome, why make your own weather station at all. Regular visitors might remember some of the upgrades I've done over the years. I started with an onboard LCD display on an UNO. I upgraded the screen size to allow more data to be shown and added more sophisticated sensors. Then I got tired of going to the display to watch the storm data, so I started using Bluetooth to relocate to a remote screen. Once Bluetooth was working, I decided to write an app so I could monitor the wind and rain data from anywhere on my phone. Recently, I've decided to port the system over to a LORA gateway that can be accessed through Bluetooth or the internet so I can monitor the conditions even when I'm several states away.

If the previous paragraph intrigues you and inspires you, then building a weather station from scratch might be for you. It's fun and rewarding and I've used everything I learned on this project in other projects. But if it scares you or bores you, then just buy a pre-built system and enjoy watching the storms roll in.


As an Amazon Associate I earn from qualifying purchases.
Shop through our Amazon links to help support this site.

Also find me on:
 FACEBOOK -or- INSTRUCTABLES -or- YOUTUBE