Sensor taking the status of a blinking led of an alarm system
-
@Tibus
being new at programmig for arduino, I'm not really sure how to put this into code :-(
could you give me an code example how you do that?@BulldogLowell
I agree! When the warranty runs out, I'll take the opening and soldering approach ;-) But even at the moment it's not that bad, because the Alarmterminal is hidden and for switching it on, I use my controller.Many thanks for your help!
Petz -
@Tibus
being new at programmig for arduino, I'm not really sure how to put this into code :-(
could you give me an code example how you do that?@BulldogLowell
I agree! When the warranty runs out, I'll take the opening and soldering approach ;-) But even at the moment it's not that bad, because the Alarmterminal is hidden and for switching it on, I use my controller.Many thanks for your help!
Petzif 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):
EDITED
#include <MySensor.h> #include <SPI.h> typedef enum{ NOT_ARMED = 0, ARMED } AlarmState; AlarmState state; AlarmState lastAlarmState; unsigned long lastFlashTime; #define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your light sensor #define CHILD_ID 1 // Id of the sensor child MySensor gw; MyMessage msg(CHILD_ID, V_TRIPPED); void setup() { pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input gw.begin(); gw.sendSketchInfo("Motion Sensor", "1.0"); delay(1000); gw.present(CHILD_ID, S_MOTION); delay(1000); } void loop() { // Read digital light sensor value if (digitalRead(DIGITAL_INPUT_SENSOR) == HIGH) { lastFlashTime = millis(); state = ARMED; if (lastAlarmState == NOT_ARMED) { gw.send(msg.set(ARMED)); // Send tripped value to gw } } if (lastFlashTime - millis() > 5000UL && state == ARMED) // you may have to adjust... this is 5 seconds { state = NOT_ARMED; if (lastAlarmState == ARMED) { gw.send(msg.set(NOT_ARMED)); // Send not tripped value to gw } } lastAlarmState = state; } -
Many Thanks for the code, I will start to play around asap ;-)
-
Many Thanks for the code, I will start to play around asap ;-)
OK, just check the edit... so it is not banging away at your gateway!!!
-
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? -
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/^/ / -
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/^/ / -
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?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:

-
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); } } -
@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?
-
Why not measure when there is voltage to the led??? Much more reliable and simple
-
@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?
@Tibus said:
why not use sleep.
you are correct, of course. I look at it as a two step approach:
- get it to work
- get it to work better than before
-
@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
-
@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
-
Nano - so VIN! Thanks!