manuel serene control

I try to make a controller to activate a fire sirene.
On different places fire alarm buttons are placed. These buttons have an on/off switch,This means that I have to convert them to a momentery switch.
There is also a test-button ( momentary) and a reset button to stop the sirene.
The sirene has to be active for 2 minutes after a fire button or the test button is pushed.

I have 2 problems. -

  • The timer is not working when I use a subroutine.
  • when the reset button is pushed the sirene has to stop, so I have to reset the timer.

my sketch :

int kelder=1;
int lastkelder = 1;
int gelijkvl=1;
int lastgelijkvl = 1;
int N1=1;
int lastN1 = 1;
int N2=1;
int lastN2 = 1;
int testknop = 1;
int lasttestknop = 1;
int resetknop = 1;
int sirene = 5;

unsigned long DUUR = 10000; // 10 seconds during test
unsigned long previousMillis = 0;

void setup(){

Serial.begin(9600);
pinMode (6,INPUT_PULLUP);
pinMode (7,INPUT_PULLUP);
pinMode (8,INPUT_PULLUP);
pinMode (9,INPUT_PULLUP);
pinMode (11,INPUT_PULLUP);
pinMode (12,INPUT_PULLUP);
pinMode (A6,INPUT_PULLUP);
pinMode (A5,INPUT_PULLUP);

pinMode (sirene, OUTPUT);

digitalWrite (sirene,LOW);

delay(5);
}

void loop(){

//detectie drukknop kelder
kelder = digitalRead(6);

if (kelder !=lastkelder && kelder == LOW )
{
previousMillis = millis();
Serial.println ("knop gedetecteerd");
digitalWrite( sirene, HIGH);
kelder = lastkelder ;
tijd();
}

//detectie drukknop gelijkvloers
gelijkvl = digitalRead(7);

if (gelijkvl != lastgelijkvl && gelijkvl ==LOW)
{
previousMillis = millis();
tijd();
lastgelijkvl = gelijkvl;
}

// ........................other fire buttons

//detectie test knop
testknop = digitalRead(A5);

if (testknop == LOW)
{
Serial.println ("testknop");
previousMillis = millis();
tijd();
}

//detectie reset knop - make previousMillis bigger than the actual millis() to reset the timer
resetknop = digitalRead(A6);
if (resetknop == LOW)
{
Serial.println ("resetknop");
previousMillis =( millis()+ DUUR +100000);
tijd();

}

}

// timer
void tijd() {

if (millis() - previousMillis> DUUR)
{
digitalWrite( sirene, LOW);
Serial.println ("timer afgelopen");

}
}

To make it easy for people to help you please modify your post and use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to my text editor. The text editor shows line numbers, identifies matching brackets and allows me to search for things like all instances of a particular variable or function.

Also please use the AutoFormat tool to indent your code consistently for easier reading.

...R

PS ... The spelling is "siren" not "sirene" or "serene". Indeed siren is almost the opposite of serene :slight_smile:

The variable names are in your native language so I can't immediately see what you are doing, but in principle you should have a state variable, for example:

bool siren_on = false ; // state variable if siren_on is true, the siren is sounding, otherwise the siren is off.

You already have a timer:

unsigned long previousMillis = 0 ;

When you detect the press of the test button, you set siren_on to true and set the timer to millis() .

When either the timer expires (after DUUR milliseconds) or the reset button is pressed, set siren_on to false.

You always make the state of the pin, to which the siren is connected, dependent on the value of siren_on.

Robin2,

I don't have this button not on my screen in the Quick reply window.

guyc1:
Robin2,

I don't have this button not on my screen in the Quick reply window.

I don't know why that is. It is certainly in my quick reply window. Maybe there is something that needs to change in your Profile settings

I suggest you use the Reply button for the full editor.

...R

Robin2:
I don't know why that is. It is certainly in my quick reply window. Maybe there is something that needs to change in your Profile settings

I suggest you use the Reply button for the full editor.

...R

It's an option in the profile settings:-

Mouse over the Profile icon (top right of page) and choose Profile.

Look for Forum settings and click on edit.

Then click on settings and choose Look and Layout.

Scroll down to the entry "Use full editor in quick reply" and check the box.

Hope this helps

Ian