A Lightning Detector for Arduino
You can download our e-book ‘Learn Arduino from Scratch’ from this link
In this tutorial, we will build a lightning detector using an Arduino Uno, a few resistors and some jumper wires. Most lightning detectors often cost too much for the normal hobbyist, however this does not mean one cannot enjoy lightning detection and the physics behind it. In this tutorial, using a surprisingly simple circuit we will be able to detect lightnings from around 10-20 km away, which is to say the least impressive.
The aim is to construct a simple circuit to detect lightnings with an Arduino and produce meaningful results.
Background
When a lightning strikes, a huge amount of energy is released in different forms. The most obvious are light and sound, the latter being a by-product of the rate of temperature increase of the immediate particles surrounding the lightning bolt, which then causes the sound. But, that is not all. Lightnings emit large amount of electromagnetic radiation in the VLF (Very Low Frequency) and LF (Low Frequency) range, typically ranging from 3kHz to 300kHz. VLF and LF are similar to light waves, your WiFi waves and also your microwave oven waves, but with the difference of operating at lower frequencies. eg. WiFi normally operates at around 2.4GHz, that’s 2.4 billion oscillations per second. VLF and LF operates at lower frequencies, and with an Arduino we can capture frequencies around 7kHz. The advantages in using this kind of radiation for lightning detection is that normally nothing gives out large bursts as seen in lightnings, around this frequency; and being an electromagnetic wave it travels at the speed of light, which means the sensor will detect lightnings as they happen (a few micro seconds after).
Our little Arduino will have an antenna (sort of), a piece of wire that will pick fluctuations in electromagnetic spectrum specifically around the 7-9kHz. These fluctuations will induce a small voltage +ve or -ve in the wire. We can pick these fluctuations using Arduino’s analog pins.
Prerequisites
- 2x10k Ohms Resistor (ebay)
- 1x 3.3M Ohms Resistor (ebay)
- 4x Jumper Wires (ebay)
- 1x Arduino (ebay) (I’m using Uno but any other will work as long as it can operate at 16Mhz)
- Breadboard (ebay) for simplicity đ
As you might already know, the pins on the Arduino board allow for voltages between 0v and 5v, anything below 0v and above 5v will not be read,hence data will be lost. More importantly, voltages below 0v will potentially damage the pin. This will create a little problem for us because the voltages produced in the wire fluctuate below and above 0v. To solve this problem we set the pin voltage in the middle of the 5v range, at 2.5v and this will be accomplished using a little trick, a voltage divider. In doing so, we will be setting the pin to a steady 2.5v and the voltage fluctuations will have an origin of 2.5v, hence no damage or loss of data.
The circuit is pretty straight forward, we have 2x 10k Ohm resistors in series from 5v (red wire) to GND (black wire), this is basically the voltage divider. Then a 3.3M Ohm (MegaOhm) resistor is connected between the 2x 10k Ohm resistor. In series with the 3.3M Ohm resistor attach a wire to pin A4 (blue wire), this will give us exactly 2.5v on pin A4. Then attach a wire which will act as an antenna (green wire) of around 6-8 inch in length. This should be connected from one end only as shown above.
Sketch
Here comes the hardest part to explain. As mentioned above, the frequency we need to pick up from the lightnings, is around 7kHz and to read a semi-decent wave the sample rate has to be 4x as much, giving us 4 readings per wavelength. That is, 28,000 samples per second.
The Arduino analog pins can only give us 9,600 samples per seconds. With that sample rate we will only be able to capture waves at 2kHz or a bit more, which is far from good. Thanks to the ATMEGA chip, it can be configured to speed up the ADC process by a certain factor, while retaining a good resolution. This is called the prescaler, and can be configured through code. There are a number of prescaler dividing factors but we will use factor 16 which in theory will give us a sampling rate of 77kHz. In practice any form of calculation will lower this sampling rate thus I was only able to get around 46kHz which is still very good for this project.
So moving forward, the sketch uses a 512 byte array to store voltage valves from pin A4. It constantly reads the pin value and writing it to the next location in the array. As soon as a lightning is detected the whole array is sent over the serial port. This can be plotted on the graph plotter in Arduino IDE or maybe sent over to another Arduino or ESP8266 to publish the data online. It’s probably best to monitor it via the Arduino IDE at first, so if there are some glitches, they can be tackled there and then.
Results
The following are some results.
Grab the source code from Github: https://github.com/klauscam/Arduino-Lightning-Detector
Please feel free to comment below if you need any further clarifications.
Update 2
To use the Arduino IDE serial plotter please replace this function
void sendData() { // Serial.print(">>>"); // Serial.println(batchStarted); for (int i=0;i<data;i++){ Serial.println(storage[i]); } // Serial.print("<<<"); // Serial.println(batchEnded); // Serial.println("END"); toSend=false; }
Update 3
Note that the device is very sensitive to EMF fluctuations. This includes AC power supplies. Place the device away from any AC supply and any socket outlets. We have also noticed that it behaves abnormal when connected to a laptop while charging. We recommend to use a laptop running on batteries only for optimum performance.
Hey, i could not understand the language much it would be better if u also included a video tutorial for how to make it.
Hey,, Could you please show a pic of the circuit in real life, not animation……..
And where can we see the results???
Where to find them in the IDE??
Please answer!!!!!
What is this error ” Exception in thread “AWT-EventQueue-0″ java.util.NoSuchElementException” huh???
Creepy!!!!! Please help me i need to do this for my school science fair!!!!!
Ultron,
Are you still having issues? I’ve managed to get it to work, but haven’t confirmed the data. My numbers are 0 to about 125. Let me know; I’d be happy to send you my code if you’re interested.
Blinker
How come your range is from 0 to 125. Did you use a voltage divider?
Hi Ultron,
I am sorry I couldnât respond earlier, I was out of town with a very limited internet access.
You can view the results in the Serial Monitor provided in the IDE. You will see a bunch of numbers but if you plot them in a graph youâll get something light the ones above.
Regarding the circuit, its pretty straight forward and a real life photo would probably be more complicated to trace. If you need I can give you a schematic drawing of the circuit.
Hi,
i m getting readings all over the place. even with no antenna wire connected I get a variation between 460 and 600.
I must mention that because I didn t have a 3.3M resistor I used 3x 1M ohm resistors? could that be that big of a deal?
Can we use other resistors aside from the 3.3 Mohm? Because im low on components. Would some 10K resistors in parallel work?
Thanks for posting this! I enjoyed building it.
I am glad. We will soon have a software to analyze the data. So stay tuned đ
Blinker, yes i am still having issues and am unable to get the circuit to work. It shows the graph and the first time a blue line came on the graph from then nothing comes on the graph instead of this error – â Exception in thread âAWT-EventQueue-0âł java.util.NoSuchElementExceptionâ . Blinker can you please send me your code too, i have a school science fair to take care of. Thank you admin and blinker!!
Blinker, i am actually interested in the code and admin i can do with that schematic drawing….
SEND ME THE IN INFO HERE GUYS – [email protected]
Hello,
Thanks for the cool project! I was just hoping you could clarify a couple of things for me. I know a voltage divider cuts your voltage in half as long as both of the resistors are the same. So why did you choose 10k resistors instead of some other? Also what does the 3.3M resistor do and what effect would it have if I was to replace it with a higher or lower resistance?
This is really fun. I’m looking at trying to expand it so that when it detects a lightning strike it switches over to listening for thunder with a sound detector. I can then use the old speed of sound trick to estimate the distance of the strike. I don’t know how it’ll work but it should be fun to try!
Thanks again!
Guys pls the science fair is just 2 days away…. Pls send it!!!!!!!!!!!!!!!!!!!!
Hi Ultron,
The code compiles and works as expected. If you are trying to use the Arduino IDE serial plotter to display the graph you need to comment some lines.
Basically you need to replace the following function.
Thank you and just in time!!!
[* Shield plugin marked this comment as “spam”. Reason: Failed GASP Bot Filter Test (comment token failure) *]
Hi Blinker
am getting an error which says
Arduino: 1.6.5 (Windows 8.1), Board: “Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)”
lightning_detector.ino: In function ‘void sendData()’:
lightning_detector:6: error: ‘data’ was not declared in this scope
lightning_detector:7: error: ‘storage’ was not declared in this scope
lightning_detector:13: error: ‘toSend’ was not declared in this scope
‘data’ was not declared in this scope
This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.
if you can let me know whats the problem it would be helpfull
Thank you
Hey good work there. I would like to try it. But how did you get/produced lightning.
Replace it with what?
Hi,
This is a great project. My kids are very excited about putting it together.
By any chance do you know how to implement this on an Arduino 101? I have downloaded your code, but it does not work. I get the following error message:
âADCSRAâ was not declared in this scope
I think it is due to the 32bit curie chip, but I am not sure. I am new to Arduino and physical computing so I am not sure how to proceed.
It would be interesting to see this circuit and code modified to use a 16 x 2 display to display the strike intensity and number since last reset or per time period.
It would be difficult to load any libraries on the same Arduino since it uses almost all available RAM. How ever it would be interesting if we could add an ESP8266, receives data using serial.write, and stores them in an SD card to be served as a web page.
gr8 work! I tried it and worked . I have done a small modification using LED and it turns on whenever lighting is detected. I used IF statement. Thank you
How do u get this working!?
Hello,
Can you please tell me what you have used for an antenna and why? As I understood from what is written, you used a jumper wire, but I’m not sure.
Thank you!
Also, the values I am receiving for the pin are 0, 1, 2, 3 (mostly 2 and 3). From the plots above, it looks like the values of the voltage interpreted by Arduino as a number between 0 and 1023 are somewhat far from each other, at least with 10 units, as I understand from the code. So I don’t get what am I doing wrong. Today lightning stroke near my window and the only thing I saw different is that the value “3” was kept a little longer during the lighning. That’s all. Can you help me, please? There’s something I am missing, but I don’t know what. Thanks!
Hello , how do you use this output to trigger a switch or relay (on/off), to disconnect a device for instance, when storm is appraoching ?
Thanks
Hey. Can we test whether the device works or not in a lab when its not lightning outside. We need to finalise the project in few days but how are we supposed to give the demo. Pls respond asap. The idea and project is wonderful!!!!