/*
* 2 switches monitoring two fans, healthly if both fan1 and fan2 switches are low output switches a relay, if any input high an alarm sounds no output to relay.
*/
int emstopled = 10; // emergency stop switch led
int greenled = 9; // green led lights if fan1 and fan2 are low connected to pin 9. healthey fan1 and fan2
int redled = 8; // red led lights if fan 1 or fan2 are high connected to pin 8. (sounds an alarm)
int relay = 7; // gas relay
int buz = 6; //buzzer sounds if fault
int emstop = 5; // emergency stop switch input.
int mute = 4; // mute buzzer
int fan2 = 3; // fan switch is connected to pin 3
int fan1 = 2; // fan switch is connected to pin 2
int fan1val; // var for reading the pin status
int fan2val; // var for reading the pin status
int muteval; // var for reading the pin status
int emstopval; // var for reading pin status.
void setup(){
pinMode(greenled, OUTPUT); // Set the Greenlled as op.
pinMode(redled, OUTPUT); // Set the LED pin as op.
pinMode(fan1, INPUT); // Set the switch pin as ip.
pinMode(fan2, INPUT); // Set the switch pin as ip.
pinMode(relay, OUTPUT); // Set the switch pin as op.
pinMode(buz, OUTPUT); // Set the switch pin as op.
pinMode(mute, INPUT); // Set the switch pin as 1p.
pinMode(emstop, INPUT); // Set the switch pin as 1p.
pinMode(emstopled, OUTPUT); // Set the switch pin as 1p
}
void loop(){
fan1val = digitalRead(fan1); // read input value and store it in fan1
fan2val = digitalRead(fan2); // read input value and store it in fan2
if ((fan1val == LOW) && (fan2val == LOW))
{ // check if both inputs show fan OK (Switch is pressed)
digitalWrite(greenled, HIGH); // turn green on
digitalWrite(relay, HIGH); // turn on gas relay.
digitalWrite(buz,LOW); // buzzer off, no error
digitalWrite(redled,LOW); // red led off no fault
} else{ // we do not need to test the opposite do the following.
digitalWrite(greenled, LOW); // turn green OFF
digitalWrite(redled, HIGH); // red led on
digitalWrite(relay, LOW); // gas valve off
digitalWrite(buz, HIGH); // buzzer on
}
emstopval == digitalRead(emstop);
if (emstop == LOW)
{
digitalWrite(emstopled, HIGH); //emergency stop made, gas valve off buzzer sounds. **** wont change to a high****
hi this is my first program after a couple of days im really stuck, i would like to start another if command with instructions to follow but wont work
can anybody help please
thank you
emstopval == digitalRead(emstop);
if (emstop == LOW)
{
digitalWrite(emstopled, HIGH); //emergency stop made, gas valve off buzzer sounds. **** wont change to a high****
} }
hi dxwood thanks for the help, not a million miles from you im from andover, i noticed that first error and fixed it but still no joy? i shortened the (emergencystop to emstop a bit confusing)
thanks
emstopval == digitalRead(emstop);
if (emstop == LOW)
{
digitalWrite(emstopled, HIGH); //emergency stop made, gas valve off buzzer sounds. **** wont change to a high****
hi, works both ways but, it was this part i was having trouble with?
Once the line AWOL is talking about is fixed, you are still checking the pin number rather than it's value in your if statement.
if (emstop == LOW)
should be
if (emstopval == LOW)
Which is what I was trying to say in my last post.
@SystemTech - look up operator precedence, the equivalence operator has higher precedence than the logical and operator, so will be evaluated first. Having said that, I would always write it with the additional parentheses.
@SystemTech - look up operator precedence, the equivalence operator has higher precedence than the logical and operator, so will be evaluated first. Having said that, I would always write it with the additional parentheses.
just when i think im getting somewhere another problem,
in the last statement, emstop (emergency stop) this should turn off gas valve, but obviously as it loops the gas valve is turned back on,
is there a way round this?
thank you
emstopval = digitalRead(emstop);
if (emstopval == LOW){
digitalWrite(emstopled, HIGH);
//emergency stop made, gas valve off buzzer sounds.
}else{
digitalWrite(relay, LOW); // gas valve off but turns on again as program loops
}
}
/*
* 2 switches monitoring two fans, healthly if both fan1 and fan2 switches are low output switches a relay, if any input high an alarm sounds no output to relay.
*/
int emstopled = 10; // emergency stop switch led
int greenled = 9; // green led lights if fan1 and fan2 are low connected to pin 9. healthey fan1 and fan2
int redled = 8; // red led lights if fan 1 or fan2 are high connected to pin 8. (sounds an alarm)
int relay = 7; // gas relay
int buz = 6; // buzzer sounds if fault
int emstop = 5; // emergency stop switch input.
int mute = 4; // mute buzzer
int fan2 = 3; // fan switch is connected to pin 3
int fan1 = 2; // fan switch is connected to pin 2
int fan1val; // var for reading the pin status
int fan2val; // var for reading the pin status
int muteval; // var for reading the pin status
int emstopval; // var for reading pin status.
void setup(){
pinMode(greenled, OUTPUT); // Set the Greenlled as op.
pinMode(redled, OUTPUT); // Set the LED pin as op.
pinMode(fan1, INPUT); // Set the switch pin as ip.
pinMode(fan2, INPUT); // Set the switch pin as ip.
pinMode(relay, OUTPUT); // Set the switch pin as op.
pinMode(buz, OUTPUT); // Set the switch pin as op.
pinMode(mute, INPUT); // Set the switch pin as 1p.
pinMode(emstop, INPUT); // Set the switch pin as 1p.
pinMode(emstopled, OUTPUT); // Set the switch pin as 1p
}
void loop(){
fan1val = digitalRead(fan1); // read input value and store it in fan1
fan2val = digitalRead(fan2); // read input value and store it in fan2
if ((fan1val == LOW) && (fan2val == LOW))
{ // check if both inputs show fan OK (Switch is pressed)
digitalWrite(greenled, HIGH); // turn green on
digitalWrite(relay, HIGH); // turn on gas relay.
digitalWrite(buz,LOW); // buzzer off, no error
digitalWrite(redled,LOW); // red led off no fault
} else{ // we do not need to test the opposite do the following.
digitalWrite(greenled, LOW); // turn green OFF
digitalWrite(redled, HIGH); // red led on
digitalWrite(relay, LOW); // gas valve off
digitalWrite(buz, HIGH); // buzzer on
}
emstopval = digitalRead(emstop);
if (emstopval == LOW)
{digitalWrite(emstopled, HIGH); //emergency stop made, lights led, and gas valve off.
digitalWrite(relay, LOW); // gas valve off ******(probable does turn off, but when program loops gas is turned on again in the top statement)*******
}else{
digitalWrite(emstopled, LOW); // emergency stop led
}}
sorry ive cleaned it up more clear, what im trying to do is when the stop is made the gas valve turns off (stop out gas on again), but when the program loops again the relay is turned on again
Are you trying to have the emergency stop switch act as a toggle switch (press once to stop; press again to resume)? If not, then, the FIRST thing you should do in loop is test if the emergency stop switch is pressed. If it is, do nothing else.
You need a boolean variable, gasStopped, that is set to true or false each time the switch is pressed. You need to shut off the gas if the variable is true, and not do any of the rest of the stuff in loop().