Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Sketch for Lightning Sensor

Sketch for Lightning Sensor

Scheduled Pinned Locked Moved Development
58 Posts 14 Posters 31.6k Views 11 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • hekH hek

    Sweet. Would you want to create a pull request when you're ready with this example (including AS3935 library)?

    SparkmanS Offline
    SparkmanS Offline
    Sparkman
    Hero Member
    wrote on last edited by Sparkman
    #25

    @hek said:

    Sweet. Would you want to create a pull request when you're ready with this example (including AS3935 library)?

    Hi Henrik,

    Pull request submitted. Hopefully I did it correctly.

    Cheers
    Al

    1 Reply Last reply
    1
    • hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #26

      Nice that you finally got some lightings to test your sketch.

      Pull request looks all ok!

      1 Reply Last reply
      0
      • Tore André RosanderT Offline
        Tore André RosanderT Offline
        Tore André Rosander
        wrote on last edited by
        #27

        Is it possible to detect the distance to the lightningstrike?
        I was thinking to get some sort of detector to notify me if there is ligning registered X km away from my home.

        B SparkmanS 2 Replies Last reply
        0
        • Tore André RosanderT Tore André Rosander

          Is it possible to detect the distance to the lightningstrike?
          I was thinking to get some sort of detector to notify me if there is ligning registered X km away from my home.

          B Offline
          B Offline
          boozz
          wrote on last edited by
          #28

          @Tore-André-Rosander

          You would need a sound detector for the thunder. Time (in milliseconds) between lightning and thunder times 0.34[m].

          Same as you would do it with your own sensors (eyes and ears) :-)

          BR,

          Boozz

          1 Reply Last reply
          0
          • Tore André RosanderT Tore André Rosander

            Is it possible to detect the distance to the lightningstrike?
            I was thinking to get some sort of detector to notify me if there is ligning registered X km away from my home.

            SparkmanS Offline
            SparkmanS Offline
            Sparkman
            Hero Member
            wrote on last edited by
            #29

            @Tore-André-Rosander Yes, the sensor can detect the distance. See the details of the sensor here: http://playingwithfusion.com/productview.php?pdid=22&catid=1001. Although I'm starting to believe that it's actually a lightning repeller rather than a lightning sensor as we've had very little lightning in our area after I installed it :laughing:

            Cheers
            Al

            1 Reply Last reply
            0
            • alexsh1A Offline
              alexsh1A Offline
              alexsh1
              wrote on last edited by
              #30

              I found a similar sensor in the UK and added this to the list of my to be sensors for the weatherstation. Can I use it inside or it has to be placed outside to have a direct vision?

              http://www.embeddedadventures.com/as3935_lightning_sensor_module_mod-1016.html

              Tore André RosanderT 1 Reply Last reply
              0
              • alexsh1A alexsh1

                I found a similar sensor in the UK and added this to the list of my to be sensors for the weatherstation. Can I use it inside or it has to be placed outside to have a direct vision?

                http://www.embeddedadventures.com/as3935_lightning_sensor_module_mod-1016.html

                Tore André RosanderT Offline
                Tore André RosanderT Offline
                Tore André Rosander
                wrote on last edited by
                #31

                @alexsh1 What i read when researching this chip it can be placed inside.

                @Sparkman Nice, i see that it has a detection range about 40km so thats already a pretty good distance to get a notification when lightning is detected.

                1 Reply Last reply
                0
                • alexsh1A Offline
                  alexsh1A Offline
                  alexsh1
                  wrote on last edited by alexsh1
                  #32

                  @Sparkman I suppose your wiring diagram above is correct? I noted that the sensor is not working with 3.3V. Did you manage to find what the problem was? Looking at the datasheet http://www.embeddedadventures.com/datasheets/MOD-1016_hw_v8_doc_v4.pdf I can see what the module can operate down to 2.4V

                  I am going to receive the sensor in a few days and test it.

                  As I have a different module manufacturer, I may need to change the sketch as it uses a different library. This is unmodified example sketch:

                  */
                  
                  // AS3935 MOD-1016 Lightning Sensor Arduino test sketch
                  // Written originally by Embedded Adventures
                  
                  
                  #include <Wire.h>
                  #include <AS3935.h>
                  
                  #define IRQ_pin 2
                  
                  volatile bool detected = false;
                  
                  void setup() {
                    Serial.begin(115200);
                    while (!Serial) {}
                    Serial.println("Welcome to the MOD-1016 (AS3935) Lightning Sensor test sketch!");
                    Serial.println("Embedded Adventures (www.embeddedadventures.com)\n");
                  
                    Wire.begin();
                    mod1016.init(IRQ_pin);
                   
                    //Tune Caps, Set AFE, Set Noise Floor
                    //autoTuneCaps(IRQ_pin);
                    
                    mod1016.setTuneCaps(7);
                    mod1016.setOutdoors();
                    mod1016.setNoiseFloor(5);
                    
                    
                    Serial.println("TUNE\tIN/OUT\tNOISEFLOOR");
                    Serial.print(mod1016.getTuneCaps(), HEX);
                    Serial.print("\t");
                    Serial.print(mod1016.getAFE(), BIN);
                    Serial.print("\t");
                    Serial.println(mod1016.getNoiseFloor(), HEX);
                    Serial.print("\n");
                  
                    pinMode(IRQ_pin, INPUT);
                    attachInterrupt(digitalPinToInterrupt(IRQ_pin), alert, RISING);
                    Serial.println("after interrupt");
                  }
                  
                  void loop() {
                    if (detected) {
                      translateIRQ(mod1016.getIRQ());
                      detected = false;
                    }
                  }
                  
                  void alert() {
                    detected = true;
                  }
                  
                  void translateIRQ(uns8 irq) {
                    switch(irq) {
                        case 1:
                          Serial.println("NOISE DETECTED");
                          break;
                        case 4:
                          Serial.println("DISTURBER DETECTED");
                          break;
                        case 8: 
                          Serial.println("LIGHTNING DETECTED");
                          printDistance();
                          break;
                      }
                  }
                  
                  void printDistance() {
                    int distance = mod1016.calculateDistance();
                    if (distance == -1)
                      Serial.println("Lightning out of range");
                    else if (distance == 1)
                      Serial.println("Distance not in table");
                    else if (distance == 0)
                      Serial.println("Lightning overhead");
                    else {
                      Serial.print("Lightning ~");
                      Serial.print(distance);
                      Serial.println("km away\n");  
                    }
                  }
                  

                  This is SPI sketch, I'd like to use I2C connection. Generally, the procedure is as follows:

                  Wait a few milliseconds for the system to stabilise
                   Set the tune capacitor to the value indicated on the packaging, by setting the
                  TUNE_CAP bits of register 8
                   Wait 2 milliseconds
                   Callibrate RCO by:
                  o Sending a calibrate RCO direct command (set memory location 0x3d to the
                  value 0x96)
                  o Set Register 0x08, bit 5 to 1
                  o Wait 2 milliseconds
                  o Set Register 0x08, bit 5 to 0
                  The factory calibrating tuning cap value will be fine for general use. When you have a
                  MOD-1016 in an enclosure or close to other electronics it is worth calibrating the tuning
                  cap again.

                  1 Reply Last reply
                  0
                  • scalzS Offline
                    scalzS Offline
                    scalz
                    Hardware Contributor
                    wrote on last edited by scalz
                    #33

                    can't wait to test this one too ;) i have pcbs for a weather shield (with bme280, veml6070 etc. ) and i have this sensor on it too (https://forum.mysensors.org/uploads/files/1459631385870-stacked.jpg). But not assembled yet, was busy, i hope asap.. i plan to use it with 3v and i2c. @alexsh1 There are libs for i2c if you want :)

                    Thx @Sparkman for your work on it ;)

                    alexsh1A 1 Reply Last reply
                    0
                    • scalzS scalz

                      can't wait to test this one too ;) i have pcbs for a weather shield (with bme280, veml6070 etc. ) and i have this sensor on it too (https://forum.mysensors.org/uploads/files/1459631385870-stacked.jpg). But not assembled yet, was busy, i hope asap.. i plan to use it with 3v and i2c. @alexsh1 There are libs for i2c if you want :)

                      Thx @Sparkman for your work on it ;)

                      alexsh1A Offline
                      alexsh1A Offline
                      alexsh1
                      wrote on last edited by
                      #34

                      @scalz yes, please (for i2c lib). What is this red board you have?

                      1 Reply Last reply
                      0
                      • SparkmanS Offline
                        SparkmanS Offline
                        Sparkman
                        Hero Member
                        wrote on last edited by
                        #35

                        @alexsh1 @scalz

                        I'm running my sketch with I2C now, rather than SPI. I found the sensor would lock up occassionally, so recently converted it and am still testing it. I have mine running at 5v now as well instead of 3.3v, but it works fine with either.

                        I'll post an updated sketch (and wiring diagram) soon. I based both the spi and i2c sketches on the examples found here: http://playingwithfusion.com/productview.php?pdid=22&catid=1001.

                        Cheers
                        Al

                        alexsh1A 1 Reply Last reply
                        0
                        • SparkmanS Sparkman

                          @alexsh1 @scalz

                          I'm running my sketch with I2C now, rather than SPI. I found the sensor would lock up occassionally, so recently converted it and am still testing it. I have mine running at 5v now as well instead of 3.3v, but it works fine with either.

                          I'll post an updated sketch (and wiring diagram) soon. I based both the spi and i2c sketches on the examples found here: http://playingwithfusion.com/productview.php?pdid=22&catid=1001.

                          Cheers
                          Al

                          alexsh1A Offline
                          alexsh1A Offline
                          alexsh1
                          wrote on last edited by
                          #36

                          @Sparkman Thanks. Your sketch is very much appreciated. I'll have to adopt it anyway as I have a different manufacture and there is a certain process I have to follow to get it initiated (posted above).

                          1 Reply Last reply
                          0
                          • alexsh1A Offline
                            alexsh1A Offline
                            alexsh1
                            wrote on last edited by alexsh1
                            #37

                            Absolutely delighted with the module I have received today by post. The weather is sh@t tonight (lightning, rain etc.) which means that I can test it:

                            Welcome to the MOD-1016 (AS3935) Lightning Sensor test sketch!
                            TUNE	IN/OUT	NOISEFLOOR
                            6	10010	5
                            
                            after interrupt
                            DISTURBER DETECTED
                            DISTURBER DETECTED
                            DISTURBER DETECTED
                            DISTURBER DETECTED
                            DISTURBER DETECTED
                            LIGHTNING DETECTED
                            Lightning ~27km away
                            
                            DISTURBER DETECTED
                            DISTURBER DETECTED
                            LIGHTNING DETECTED
                            Lightning ~17km away
                            
                            DISTURBER DETECTED
                            LIGHTNING DETECTED
                            Lightning ~10km away
                            

                            I calibrated the sensor and put a reasonable "noise floor". Now I have to convert it into MySensors and hook up to the ceech board outside.

                            @Sparkman I have my sensor running at 3.3V

                            alexsh1A 1 Reply Last reply
                            0
                            • alexsh1A alexsh1

                              Absolutely delighted with the module I have received today by post. The weather is sh@t tonight (lightning, rain etc.) which means that I can test it:

                              Welcome to the MOD-1016 (AS3935) Lightning Sensor test sketch!
                              TUNE	IN/OUT	NOISEFLOOR
                              6	10010	5
                              
                              after interrupt
                              DISTURBER DETECTED
                              DISTURBER DETECTED
                              DISTURBER DETECTED
                              DISTURBER DETECTED
                              DISTURBER DETECTED
                              LIGHTNING DETECTED
                              Lightning ~27km away
                              
                              DISTURBER DETECTED
                              DISTURBER DETECTED
                              LIGHTNING DETECTED
                              Lightning ~17km away
                              
                              DISTURBER DETECTED
                              LIGHTNING DETECTED
                              Lightning ~10km away
                              

                              I calibrated the sensor and put a reasonable "noise floor". Now I have to convert it into MySensors and hook up to the ceech board outside.

                              @Sparkman I have my sensor running at 3.3V

                              alexsh1A Offline
                              alexsh1A Offline
                              alexsh1
                              wrote on last edited by
                              #38

                              BTW, I am not sure the sensor is similar to what you guys have.

                              0_1466633381738_2016-06-22 09.54.18.jpg

                              SparkmanS K 2 Replies Last reply
                              0
                              • alexsh1A alexsh1

                                BTW, I am not sure the sensor is similar to what you guys have.

                                0_1466633381738_2016-06-22 09.54.18.jpg

                                SparkmanS Offline
                                SparkmanS Offline
                                Sparkman
                                Hero Member
                                wrote on last edited by
                                #39

                                @alexsh1 It looks to be a different breakout board, but for the same chip. So I would expect them to work basically the same.

                                Cheers
                                Al

                                alexsh1A 1 Reply Last reply
                                0
                                • SparkmanS Sparkman

                                  @alexsh1 It looks to be a different breakout board, but for the same chip. So I would expect them to work basically the same.

                                  Cheers
                                  Al

                                  alexsh1A Offline
                                  alexsh1A Offline
                                  alexsh1
                                  wrote on last edited by
                                  #40

                                  @Sparkman it is a different board made (or designed) by a UK company.

                                  We are having a real British summer over here :-)))

                                  LIGHTNING DETECTED
                                  Lightning ~20km away
                                  
                                  LIGHTNING DETECTED
                                  Lightning ~20km away
                                  
                                  LIGHTNING DETECTED
                                  Lightning ~6km away
                                  
                                  LIGHTNING DETECTED
                                  Lightning ~6km away
                                  
                                  LIGHTNING DETECTED
                                  Lightning ~6km away
                                  
                                  LIGHTNING DETECTED
                                  Lightning ~6km away
                                  
                                  LIGHTNING DETECTED
                                  Lightning ~6km away
                                  
                                  LIGHTNING DETECTED
                                  Lightning ~5km away
                                  
                                  NeverDieN 1 Reply Last reply
                                  0
                                  • alexsh1A alexsh1

                                    @Sparkman it is a different board made (or designed) by a UK company.

                                    We are having a real British summer over here :-)))

                                    LIGHTNING DETECTED
                                    Lightning ~20km away
                                    
                                    LIGHTNING DETECTED
                                    Lightning ~20km away
                                    
                                    LIGHTNING DETECTED
                                    Lightning ~6km away
                                    
                                    LIGHTNING DETECTED
                                    Lightning ~6km away
                                    
                                    LIGHTNING DETECTED
                                    Lightning ~6km away
                                    
                                    LIGHTNING DETECTED
                                    Lightning ~6km away
                                    
                                    LIGHTNING DETECTED
                                    Lightning ~6km away
                                    
                                    LIGHTNING DETECTED
                                    Lightning ~5km away
                                    
                                    NeverDieN Offline
                                    NeverDieN Offline
                                    NeverDie
                                    Hero Member
                                    wrote on last edited by
                                    #41

                                    @alexsh1
                                    There doesn't appear to be audio input to this board, nor a microphone on the board. So, how does it estimate the distance to the lightening?

                                    SparkmanS 1 Reply Last reply
                                    0
                                    • NeverDieN NeverDie

                                      @alexsh1
                                      There doesn't appear to be audio input to this board, nor a microphone on the board. So, how does it estimate the distance to the lightening?

                                      SparkmanS Offline
                                      SparkmanS Offline
                                      Sparkman
                                      Hero Member
                                      wrote on last edited by
                                      #42

                                      @NeverDie All these breakout boards are based on this chip: http://ams.com/eng/Products/Wireless-Connectivity/Wireless-Sensor-Connectivity/AS3935. They use a proprietary method to figure out distance and is not based on sound.

                                      Cheers
                                      Al

                                      NeverDieN 1 Reply Last reply
                                      0
                                      • SparkmanS Sparkman

                                        @NeverDie All these breakout boards are based on this chip: http://ams.com/eng/Products/Wireless-Connectivity/Wireless-Sensor-Connectivity/AS3935. They use a proprietary method to figure out distance and is not based on sound.

                                        Cheers
                                        Al

                                        NeverDieN Offline
                                        NeverDieN Offline
                                        NeverDie
                                        Hero Member
                                        wrote on last edited by
                                        #43

                                        @Sparkman said:

                                        @NeverDie All these breakout boards are based on this chip: http://ams.com/eng/Products/Wireless-Connectivity/Wireless-Sensor-Connectivity/AS3935. They use a proprietary method to figure out distance and is not based on sound.

                                        Cheers
                                        Al

                                        Any impression yet as to how accurate its distance estimates are?

                                        SparkmanS alexsh1A 2 Replies Last reply
                                        0
                                        • NeverDieN NeverDie

                                          @Sparkman said:

                                          @NeverDie All these breakout boards are based on this chip: http://ams.com/eng/Products/Wireless-Connectivity/Wireless-Sensor-Connectivity/AS3935. They use a proprietary method to figure out distance and is not based on sound.

                                          Cheers
                                          Al

                                          Any impression yet as to how accurate its distance estimates are?

                                          SparkmanS Offline
                                          SparkmanS Offline
                                          Sparkman
                                          Hero Member
                                          wrote on last edited by
                                          #44

                                          @NeverDie No, as we've had very little lightning since I started using it.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          11

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.1k

                                          Posts


                                          Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular