Living in the Tampa Bay Area, lightning storms are a fact of life. In fact, lightning storms are so prevalent, we even named our hockey team after them (Go Bolts!).
Lightning storms can be very destructive, causing wildfires, power surges, and even asthma attacks. According to insurance industry statistics, lightning storms cause billions of dollars of damage every year. Given the severe disruptions these cause, I wanted to create my own device to alert me of an approaching storm.
In this post I'll show you how to build your own lightning detection device for under $150 that will use a microcontroller, a cellular module, and a lightning sensor to report to an online dashboard so you'll know when your electronics might be in danger of getting zapped.
Assemble the Lightning Detector DeviceThe first thing I needed to decide on for this project was a lightning sensor. While professional grade lightning detection systems can cost well over $1000, I just wanted something small and cheap to build with. Luckily, there are many inexpensive lightning sensors available online, most of which are based on the AS3935 sensor.
I chose this model off Amazon, since it supports I2C connection, which I am already familiar with from previous IoT projects.
For my MCU, I knew I wanted something that would carry my data to the cloud, had low power requirements, and was easy to assemble and program. The Feather Starter Kit for Swan was the perfect fit.
This kit includes the STM32L4R5 MCU that will run my custom firmware, the Blues Wireless Notecard to transport my data to the cloud, plus a carrier board that makes it easy to assemble the components and deploy my project.
The Notecard comes in two variaties: LTE cellular and WiFi. The LTE cellular notecard provides prepaid global cellular access, bundled with 10-years and 500MB of cellular data. Having this option is perfect for my lightning detector, since relying on WiFi during lightning storms is probably not the best bet.
One thing to consider is the carrier board (Notecarrier AF) does not include header pins, so you must purchase these separately and solder them yourself. As this was my first time soldering, I was very nervous! But after watching this video I felt more confident and it actually was pretty easy.
Here is the finished product, including the carrier board, sensor, and lipo battery:
The software development kit I used was PlatformIO. Being a newcomer to embedded development, this made the entire process very easy to get started.
I discovered PlatformIO by following the Swan Quickstart from Blues Wireless. This guide was amazingly helpful in getting my development environment set up.
For this project I relied on two libraries to interface with the hardware: the Notecard Arduino Library, and the AS3935 Arduino Library. Using PlatformIO, both of these were very easy to get installed. After that I simply ported the example code of the two libraries to my project.
Here is the full code I used to program the Swan for lightning detection.
Display Lightning Data in a Low-Code Datacake DashboardThe first step in building my dashboard was getting my data from the device to the cloud. This is where the Blues Wireless ecosystem shines. With the Blues Wireless Notecard, my data is automatically "pumped" into their cloud platform, Notehub. This quickstart includes everything you need to get data from your Notecard into Notehub.
The Notecard uses JSON commands to configure the device and to send data to the cloud. Here is an example of a command you would use to configure your Notecard:
> {"req":"hub.set", "product":"com.your-company.your-name:your_product"}
{}
Now use this command to initiate a connection between your Notecard and Notehub:
> {"req":"hub.sync"}
{}
Finally, you can send a single note to a notefile with this command:
> {"req":"note.add","file": "data.qo","body":{"temp":35.5,"humid":56.23}}
{"total":1}
What could be easier?
Now I needed to decide on how to make a dashboard. There are many platforms online, but I chose Datacake because of its minimal time to build a dashboard and its good looks. Datacake is a low-code platform, so you don't need much in the way of coding skills to make a slick data visualization dashboard with its help.
The only code I needed to write was Javascript to extract the relevant data from the HTTP request being sent to Datacake, in what they call a "Decoder function". They provided a nice example that was easy to follow along. Here is my code in case you're interested.
Now I needed to figure out how to transfer my data to my dashboard. In other words, I needed to "route" my data from Notehub to Datacake. Luckily Blues Wireless has a tutorial for exactly this use case. In addition to Datacake, Notehub supports routing data to Amazon AWS, Microsoft Azure, Snowflake, and may other cloud platforms.
My final dashboard included a map of lightning strikes, gauges to show the most recent strike distance and energy (a unitless measurement generated by the sensor), and charts to show the trend of the storm. Here is the public link.
The AS3935 lightning sensor includes a number of configuration settings (e.g. noise sensitivity, indoor/outdoor setting, etc.) that may enhance or diminish its ability to accurately detect lightning strikes.
As of the writing of this article, I'm still working out the best settings to use for the best performance. In my experience the default settings did not reliably detect every lightning strike (i.e. many non-detections).
Another issue was generating test data. Unlike the Storm character from X-Men, I was not born with the ability to control the weather. But not to worry, I've got the next best thing -- shell scripts! I wrote this handy shell script to generate dummy lightning strikes so I could test out my Datacake dashboard.
I opted to send my test data to Datacake directly instead of through the Notecard so as to not burn through my cellular data and Blues Consumption Credits.
In this post I showed how you can build a lightning detection device using the Blues Wireless Swan and Notecard, and display the data in a low-code Datacake dashboard.
Overall, this was a very fun project to work on. The Blues Wireless ecosystem made everything very easy for an embedded newbie like myself.
Happy hacking!
Comments