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?