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. Sensor taking the status of a blinking led of an alarm system

Sensor taking the status of a blinking led of an alarm system

Scheduled Pinned Locked Moved Development
19 Posts 6 Posters 6.4k Views 3 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.
  • M Offline
    M Offline
    Meister_Petz
    wrote on last edited by Meister_Petz
    #9

    btw, thats was my working apporach before:
    is there a nice way to add code? Do I really have to add 4 spaces before every line?

    BulldogLowellB 1 Reply Last reply
    0
    • daulagariD Offline
      daulagariD Offline
      daulagari
      Hero Member
      wrote on last edited by
      #10

      is there a nice way to add code? Do I really have to add 4 spaces before every line?

      Yes, that is the way to format code.

      But ... knowing some tools there is no need to do it by hand. In vi/vim:

      :%s/^/    /
      
      hekH 1 Reply Last reply
      0
      • daulagariD daulagari

        is there a nice way to add code? Do I really have to add 4 spaces before every line?

        Yes, that is the way to format code.

        But ... knowing some tools there is no need to do it by hand. In vi/vim:

        :%s/^/    /
        
        hekH Offline
        hekH Offline
        hek
        Admin
        wrote on last edited by hek
        #11

        @daulagari

        or just surround code-block with 3 backtick-characters. This character ----> `

        #include <hehe.h>
        
        printf();
        
        
        1 Reply Last reply
        1
        • M Meister_Petz

          btw, thats was my working apporach before:
          is there a nice way to add code? Do I really have to add 4 spaces before every line?

          BulldogLowellB Offline
          BulldogLowellB Offline
          BulldogLowell
          Contest Winner
          wrote on last edited by
          #12

          @Meister_Petz

          or in your arduino editor, just grab all the code (CTRL+A) and then increase indent twice... on my mack it is (COMMAND+ ]) That moves all the code right four spaces... see below:

          Screen Shot 2015-01-22 at 9.36.15 PM.png

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Meister_Petz
            wrote on last edited by Meister_Petz
            #13

            MANY THANKS!

            That is what I did until now without Millis and interupts,...

            In this code I determine blinks by the difference between 2 following readings. Is there a better way?

            And I simplified the message sent to the gateway quite a bit. Do I produce any errors with this?

              /* Small sketch to determine the State of a Olympia Protect Alarmsystem
              0. When UNARMED   : LED off - DISPLAY off
              1. When ARMED     : LED blinks
              2. When ACTIVATING: LED blinks - DISPLAY blinks (check if before State was ARMED)
              3. When TRIGGERED : LED blinks - DISPLAY blinks (check if before State was ARMED)
              */
              
              #include <MySensor.h>
              #include <SPI.h>
              #define CHILD_ID 3
              MySensor gw;
              MyMessage msg(CHILD_ID,V_TRIPPED);
              
              const int phCell1Pin = 0; // Photocell 1 on PIN 0 - Display
              const int phCell2Pin = 1; // Photocell 2 on PIN 1 - LED
              const int phCell1Sensitivity = 100; // sets the minimum difference between two readings to determine blinking of Display
              const int phCell2Sensitivity = 100; // sets the minimum difference between two readings to determine blinking of LED
              const int sleepTime = 7000; // 7 Sec. between Reading Cycles
              int armingTime = 30; // Seconds set until arming is done
              
              
              int DisplayState = 0;
              int LEDState = 0;
              int AlarmSystemState = 4; // (0 = Off, 1 = On, 2 = Activating, 3 = Triggered)
              int AlarmSystemStateOld = 0;
              int myRound1[10] = {0,0,0,0,0,0,0,0,0,0}; // Array to store Readings
              int myRound2[10] = {0,0,0,0,0,0,0,0,0,0}; // Array to store Readings
              int goSleep = 0;
              int i = 0;
              int i1 = 0;
              int i2 = 0;
              
              void setup(void) {
                gw.begin();
                gw.present(CHILD_ID, S_DOOR);
              }
               
              void loop(void) {
                   if (i < 10){ // 10 Readings
                     myRound1[i] = analogRead(phCell1Pin); // read Photosensor Display 
                     //Serial.print("Display PhCell:"); Serial.println(myRound1[i]);
                     myRound2[i] = analogRead(phCell2Pin); // read Photosensor LED 
                     //Serial.print("LED     PhCell:"); Serial.println(myRound2[i]);
                     
                     if (i > 0){ // compare 2 following readings
                       // Display
                       if ((myRound1[i] - myRound1[i-1]) > phCell1Sensitivity){i1++;}
                       if ((myRound1[i-1] - myRound1[i]) > phCell1Sensitivity){i1++;}
                       // LED
                       if ((myRound2[i] - myRound2[i-1]) > phCell2Sensitivity){i2++;}
                       if ((myRound2[i-1] - myRound2[i]) > phCell2Sensitivity){i2++;}
                     }
                     i++;
                     
                   } else {
                     
                     // Display
                     if (i1 > 2){ // if there are more than 3 Readings which are assumed blinks - set DisplayState to blink
                       DisplayState = 1; //Serial.println("Display blinkt - State 1");
                     } else {
                       DisplayState = 0; // Serial.println("Display dunkel - State 0");
                     }
                     
                     //LED
                     if (i2 > 2){ // if there are more than 3 Readings which are assumed blinks - set LEDState to blink
                       LEDState = 1; //Serial.println("LED blinkt - State 1");
                     } else {
                       LEDState = 0; // Serial.println("LED dunkel - State 0");
                     }
              
                     goSleep = 1; // now transmit if necessary and wait before starting again
                     // Reset
                     i = 0;
                     i1 = 0;
                     i2 = 0;
                     int myRound1[10] = {0,0,0,0,0,0,0,0,0,0};
                     int myRound2[10] = {0,0,0,0,0,0,0,0,0,0};
                   }
              
                   // send to Sleep
                   if (goSleep == 1){
                     if (DisplayState == 0 && LEDState == 0){
                       AlarmSystemState = 0; // OFF
                     } else if (DisplayState == 0 && LEDState == 1){
                       AlarmSystemState = 1; // ON
                     } else if (DisplayState == 1 && LEDState == 1 && AlarmSystemStateOld == 0){
                       AlarmSystemState = 2; // Actviating
                       //delay(70000); // wait 70 Seconds until Activating is done 
                     } else if (DisplayState == 1 && LEDState == 1 && AlarmSystemStateOld == 1){
                       AlarmSystemState = 3; // TRIGGERED
                     } else {
                      AlarmSystemState = AlarmSystemStateOld;
                     }
                     
              
                     // Send State change to Gateway
                     //Serial.print("AlarmSystemState Änderung:");Serial.println(AlarmSystemState);
                     gw.send(msg.set(AlarmSystemState));
                     
                     if (AlarmSystemState == 2){ // Delay until Arming is done before next read
                       armingTime = (armingTime * 1000)+1000;
                       delay(armingTime);
                     }
                     
                     AlarmSystemStateOld = AlarmSystemState;
                     delay(sleepTime);
                     goSleep = 0;
                   } else {
                     delay(575);
                   }
              }
            
            1 Reply Last reply
            0
            • T Offline
              T Offline
              Tibus
              wrote on last edited by
              #14

              @BulldogLowell said:

              if you need it to run on battery, then you may not want to bother with sleep, since you are looking for the non-occurrence of something.

              the interrupt method will wake the MCU every time the led flashes...

              you could start with code like this (untested):

              why not use sleep. Yes it will wake the MCU every time the led flashes but it 'll consume less power when it sleep. you can go from 7ma to 10ua when it sleep. Even for one seconds it's a benefit no?

              BulldogLowellB 1 Reply Last reply
              0
              • brettzky84B Offline
                brettzky84B Offline
                brettzky84
                wrote on last edited by
                #15

                Why not measure when there is voltage to the led??? Much more reliable and simple

                1 Reply Last reply
                0
                • T Tibus

                  @BulldogLowell said:

                  if you need it to run on battery, then you may not want to bother with sleep, since you are looking for the non-occurrence of something.

                  the interrupt method will wake the MCU every time the led flashes...

                  you could start with code like this (untested):

                  why not use sleep. Yes it will wake the MCU every time the led flashes but it 'll consume less power when it sleep. you can go from 7ma to 10ua when it sleep. Even for one seconds it's a benefit no?

                  BulldogLowellB Offline
                  BulldogLowellB Offline
                  BulldogLowell
                  Contest Winner
                  wrote on last edited by
                  #16

                  @Tibus said:

                  why not use sleep.

                  you are correct, of course. I look at it as a two step approach:

                  1. get it to work
                  2. get it to work better than before
                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    Meister_Petz
                    wrote on last edited by Meister_Petz
                    #17

                    @Tibus
                    I agree about sleeping. But for one thing I don't have the slightest clue how working with interupts works (yet) and the Arduino is hook on the power of the Alarmsystem ;-)

                    BTW my Alarmsystem Powersupply produces 6V. Would it make more sense to use a 5V Step Down Regulator and give power to pin 27 (5V) than 6V to PIN 30 (VIN)?

                    Many Thanks

                    Petz

                    BulldogLowellB 1 Reply Last reply
                    0
                    • M Meister_Petz

                      @Tibus
                      I agree about sleeping. But for one thing I don't have the slightest clue how working with interupts works (yet) and the Arduino is hook on the power of the Alarmsystem ;-)

                      BTW my Alarmsystem Powersupply produces 6V. Would it make more sense to use a 5V Step Down Regulator and give power to pin 27 (5V) than 6V to PIN 30 (VIN)?

                      Many Thanks

                      Petz

                      BulldogLowellB Offline
                      BulldogLowellB Offline
                      BulldogLowell
                      Contest Winner
                      wrote on last edited by
                      #18

                      @Meister_Petz

                      Pro-Mini? I'd just take the 6V to the RAW pin.

                      6V to Vin on a nano.

                      1 Reply Last reply
                      0
                      • M Offline
                        M Offline
                        Meister_Petz
                        wrote on last edited by
                        #19

                        Nano - so VIN! Thanks!

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


                        19

                        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