Programming an automated fire extinguisher.

Hello there fellow electronics enthusiasts!

I am a newbie at programming the arduino just so that is said. You will most likely understand that anyways. :sweat_smile:
Still waiting for my Arduino Nano but i am trying to program it already so that i have time to jiggle the variables later-on.

I basically want to put 2 smoke detectors (already have the I/O pin and grounds cabled out already) hooked up to two relays (2-relay-board for Arduinos)
When the smoke detectors signal the Arduinos inputs to send the relays the signal to give the waterpumps starting to spray out the super destilled water so that the misters kill the fire.

You can see the setup is in the attached PNG.
Any help would be appreciated alot! :slight_smile:

Thanks for reading and good luck to your projects!

Do you have a link for your smoke detectors?

Sure, here it is. :) http://kingdun-kd.en.made-in-china.com/product/MebnQURGqmiw/China-Smoke-Alarm-KD-108-.html

Heres is the programming i just did, what am i doing wrong if anything?

 const int buttonPin = 2;     // smokedetector 1
 const int buttonPin2 = 3;    // smokedetector 2
 const int ledPin =  10;      // relay1
 const int ledPin2 =  11;     // relay2

// variables will change:
int buttonState = 0;       

void setup() {
   // initialize relay 1 pin as an output:
   pinMode(ledPin, OUTPUT);      
   // initialize relay 2 pin as an output:
   pinMode(ledPin2, OUTPUT);    
   // initialize the smokedetector 1 pin as an input:
   pinMode(buttonPin, INPUT);     
   // initialize the smokedetector 2 pin as an input:
   pinMode(buttonPin2, INPUT);     
}

void loop(){
   // read the state of the pushbutton value:
   buttonState = digitalRead(buttonPin);
   buttonState = digitalRead(buttonPin2);

   // check if the pushbutton is pressed.
   // if it is, the buttonState is HIGH:
   if (buttonState == HIGH) {     
     // turn LED on:    
     digitalWrite(ledPin, HIGH);  
     digitalWrite(ledPin2, HIGH);  
   } 
   else {
     // turn relays off:
     digitalWrite(ledPin, LOW); 
     digitalWrite(ledPin2, LOW); 
   }
}
 const int buttonPin = 2;     // smokedetector 1
 const int buttonPin2 = 3;    // smokedetector 2
 const int ledPin =  10;      // relay1
 const int ledPin2 =  11;     // relay2

// variables will change:
int buttonState = 0;       

void setup() {
   // initialize relay 1 pin as an output:
   pinMode(ledPin, OUTPUT);      
   // initialize relay 2 pin as an output:
   pinMode(ledPin2, OUTPUT);    
   // initialize the smokedetector 1 pin as an input:
   pinMode(buttonPin, INPUT);     
   // initialize the smokedetector 2 pin as an input:
   pinMode(buttonPin2, INPUT);     
}

void loop(){
   // read the state of the pushbutton value:
   buttonState = digitalRead(buttonPin);
   button2State = digitalRead(buttonPin2); // <-------------------------------this overrides what you did on the previous statement.

   // check if the pushbutton is pressed.
   // if it is, the buttonState is HIGH:
   if (buttonState == HIGH) {     // <------------THIS MAY NOT NECESSARILY BE TRUE. YOU DON'T HAVE BUTTONS IN YOUR SCHEMATIC.
     // turn LED on:    
     digitalWrite(ledPin, HIGH);  
     digitalWrite(ledPin2, HIGH);  
   } 
   else {
     // turn relays off:
     digitalWrite(ledPin, LOW); 
     digitalWrite(ledPin2, LOW); 
   }
}

Do you want to turn the pumps when both detectors are true, or when either of them are true? That condition isn’t in your program as it is now.

Oh crap. Your right. :astonished:

How do i separate them? How do i change from buttons to relays?

Thanks for telling me all of this, i didnt even see it...

Relay 1 has to be connected to detector 1. And Relay 2 has to be to detector 2. So that it does not sprinkle the wrong area.;)

Can i put in if/else detector 1 HIGH or something? Any geniuses out there? :)

Does this work?

 const int buttonPin = 2;     // smokedetector 1
 const int buttonPin2 = 3;    // smokedetector 2
 const int ledPin =  10;      // relay1
 const int ledPin2 =  11;     // relay2

// variables will change:
int buttonState = 0;       

void setup() {
   // initialize relay 1 pin as an output:
   pinMode(ledPin, OUTPUT);      
   // initialize relay 2 pin as an output:
   pinMode(ledPin2, OUTPUT);    
   // initialize the smokedetector 1 pin as an input:
   pinMode(buttonPin, INPUT);     
   // initialize the smokedetector 2 pin as an input:
   pinMode(buttonPin2, INPUT);     
}

void loop(){
   // read the state of the pushbutton value:
   buttonState = digitalRead(buttonPin);
   button2State = digitalRead(buttonPin2);

   // check if the pushbutton is pressed.
   // if it is, the buttonState is HIGH:
   if (buttonState == HIGH) {     
     // turn relays on:    
     digitalWrite(ledPin, LOW);  
   } 
   else {
     // turn relays off:
     digitalWrite(ledPin, HIGH); 
   }
   
   // check if the pushbutton is pressed.
   // if it is, the buttonState is HIGH:
   if (button2State == HIGH) {     
     // turn relays on:    
     digitalWrite(ledPin2, LOW);  
   } 
   else {
     // turn relays off:
     digitalWrite(ledPin2, HIGH); 
   }
}

I know that wasn't what you asked about, and you sound like somebody who knows what you're doing, but are you aware of the dangers of spraying water around when there is any live electrical equipment?

You are missing this:

int button2State = 0;

You should try to compile the code before posting... ;)

Hi there Peter, yeah. I have researched 0 pollutant (100% destilled water) and it is not dangerous against any high or low Amp circuits as long as it is misted in low quantities. Thanks for the interest and read.

bubulindo: You are missing this:

int button2State = 0;

You should try to compile the code before posting... ;)

Silly me ;) I will add it now. Thanks for the help dude. As you said, i dont have any buttons in my setup. And you are right. But will the programming f things up if i do have what i have programmed?

There is only 2 relays (2-relay module) and 2 smoke detectors hooked up to the I/O ports in their ICs. I dont see the problems yet, but as we all know. Problems happen.

Here is the new recompiled coding:

 const int buttonPin = 2;     // smokedetector 1
 const int buttonPin2 = 3;    // smokedetector 2
 const int ledPin =  10;      // relay1
 const int ledPin2 =  11;     // relay2

// variables will change:
int buttonState = 0;
int button2State = 0;

void setup() {
   // initialize relay 1 pin as an output:
   pinMode(ledPin, OUTPUT);      
   // initialize relay 2 pin as an output:
   pinMode(ledPin2, OUTPUT);    
   // initialize the smokedetector 1 pin as an input:
   pinMode(buttonPin, INPUT);     
   // initialize the smokedetector 2 pin as an input:
   pinMode(buttonPin2, INPUT);     
}

void loop(){
   // read the state of the pushbutton value:
   buttonState = digitalRead(buttonPin);
   button2State = digitalRead(buttonPin2);

   if (buttonState == HIGH) {     
     // turn relays on:    
     digitalWrite(ledPin, LOW);  
   } 
   else {
     // turn relays off:
     digitalWrite(ledPin, HIGH); 
   }
   
   if (button2State == HIGH) {     
     // turn relays on:    
     digitalWrite(ledPin2, LOW);  
   } 
   else {
     // turn relays off:
     digitalWrite(ledPin2, HIGH); 
   }
}

I have a problem, i found out the Smoke detectors bounce on the I/O pins. This is bad, which means the waterpumps/relays would turn off and on all the time (1000ms bounce). How can i debounce that factor? So when the detectors are HIGH they stay HIGH and do not stop all of a sudden. :( Help would REALLY be appreciated!

I cannot (most likely) use the Delay fuction. Am I right? Any other easy functions that can fix the job? Or do I need an advanced algorithm? lol Maybe I could use a pullup resistor and capacitor combo? I have no idea, im lost here.

use millis and read the inputs every half a second or so. that should be enough. :)

Exsoldier: I have a problem, i found out the Smoke detectors bounce on the I/O pins. This is bad, which means the waterpumps/relays would turn off and on all the time (1000ms bounce). How can i debounce that factor? So when the detectors are HIGH they stay HIGH and do not stop all of a sudden. :( Help would REALLY be appreciated!

I cannot (most likely) use the Delay fuction. Am I right? Any other easy functions that can fix the job? Or do I need an advanced algorithm? lol Maybe I could use a pullup resistor and capacitor combo? I have no idea, im lost here.

That's easily handled in software, but you need to know how the signal behaves to deal with it. Is it accurate to say that the output stays low when the alarm is 'off', and pulses high and low at about 1Hz when the alarm is 'on'?

bubulindo:
use millis and read the inputs every half a second or so. that should be enough. :slight_smile:

Cool. How do you put that in the coding?
Thanks for the help!

PeterH:

Exsoldier:
I have a problem, i found out the Smoke detectors bounce on the I/O pins. This is bad, which means the waterpumps/relays would turn off and on all the time (1000ms bounce). How can i debounce that factor? So when the detectors are HIGH they stay HIGH and do not stop all of a sudden. :frowning:
Help would REALLY be appreciated!

I cannot (most likely) use the Delay fuction. Am I right? Any other easy functions that can fix the job? Or do I need an advanced algorithm? lol
Maybe I could use a pullup resistor and capacitor combo? I have no idea, im lost here.

That‚Äôs easily handled in software, but you need to know how the signal behaves to deal with it. Is it accurate to say that the output stays low when the alarm is ‚Äėoff‚Äô, and pulses high and low at about 1Hz when the alarm is ‚Äėon‚Äô?

You sir, are correct on both parts. Its the buzzer that makes the electricity do a big sine wave. I havent tried it 100% with the arduino yet tho. So im not 100% sure its gonna be a big problem.

const int buttonPin = 2;     // smokedetector 1
 const int buttonPin2 = 3;    // smokedetector 2
 const int ledPin =  10;      // relay1
 const int ledPin2 =  11;     // relay2

You should really fix your variable to match what they actually are; the pins aren't connected to LEDs and buttons, they are connected to smoke detectors and water pumps. That's bound to cause some confusion down the road, especially if ask for further help and people start perusing your code, wondering what these LEDs are supposed to do.

Exsoldier: You sir, are correct on both parts. Its the buzzer that makes the electricity do a big sine wave. I havent tried it 100% with the arduino yet tho. So im not 100% sure its gonna be a big problem.

So you want to tell whether the signal is flapping between high/low at some frequency, or a steady low.

The way I'd do this is to poll the signal value fairly frequently, for example once each time through loop(). Define a variable that holds the value of millis() when the input was seen to be high. Each time you poll the input, if the input is high then update this variable to the current value of millis(); if it's low, leave the variable alone.

Periodically, for example once each time through loop(), subtract the value of this variable from current value of millis(). In effect this tells you how much time has elapsed since the last high was seen. If this is substantially longer than the longest pulse you expect to get, it indicates that the input has stopped pulsing and is now a steady low so the alarm is now 'off'.

Arrch: const int buttonPin = 2;    // smokedetector 1 const int buttonPin2 = 3;    // smokedetector 2 const int ledPin =  10;      // relay1 const int ledPin2 =  11;    // relay2

You should really fix your variable to match what they actually are; the pins aren't connected to LEDs and buttons, they are connected to smoke detectors and water pumps. That's bound to cause some confusion down the road, especially if ask for further help and people start perusing your code, wondering what these LEDs are supposed to do.

You're right. I was a bit lazy. Here is the new and improved. Thanks for telling me to get rid of useless text.

 const int DetectorPin1 = 2;    // Smokedetector 1, input
 const int DetectorPin2 = 3;    // Smokedetector 2, input
 const int RelayPin1 =  10;     // relay 1, connected to waterpump 1
 const int RelayPin2 =  11;     // relay 2, connected to waterpump 2

// variables will change:
int Detector1State = 0;
int Detector2State = 0;

void setup() {
   // initialize relay 1 pin as an output:
   pinMode(RelayPin1, OUTPUT);      
   // initialize relay 2 pin as an output:
   pinMode(RelayPin2, OUTPUT);    
   // initialize the smokedetector 1 pin as an input:
   pinMode(DetectorPin1, INPUT);     
   // initialize the smokedetector 2 pin as an input:
   pinMode(DetectorPin2, INPUT);     
}

void loop(){
   // read the state of the Detectors value:
   Detector1State = digitalRead(DetectorPin1);
   Detector2State = digitalRead(DetectorPin2);

   if (Detector1State == HIGH) {     
     // turns relay 1 on:    
     digitalWrite(RelayPin1, LOW);  
     
   } 
   else {
     // turns relay 1 off:
     digitalWrite(RelayPin1, HIGH); 
   }
   
   if (Detector2State == HIGH) {     
     // turns relay 2 on:    
     digitalWrite(RelayPin2, LOW);  
   } 
   else {
     // turns relay 2 off:
     digitalWrite(RelayPin2, HIGH); 
   }
}

PeterH:

Exsoldier: You sir, are correct on both parts. Its the buzzer that makes the electricity do a big sine wave. I havent tried it 100% with the arduino yet tho. So im not 100% sure its gonna be a big problem.

So you want to tell whether the signal is flapping between high/low at some frequency, or a steady low.

The way I'd do this is to poll the signal value fairly frequently, for example once each time through loop(). Define a variable that holds the value of millis() when the input was seen to be high. Each time you poll the input, if the input is high then update this variable to the current value of millis(); if it's low, leave the variable alone.

Periodically, for example once each time through loop(), subtract the value of this variable from current value of millis(). In effect this tells you how much time has elapsed since the last high was seen. If this is substantially longer than the longest pulse you expect to get, it indicates that the input has stopped pulsing and is now a steady low so the alarm is now 'off'.

I have NO idea how to program this into the coding of mine. LOL. Sorry, but this is like reading greek/chinese for me.

Also, how do i add in code for an LM335Z temp sensor?