Go Down

Topic: problem with my if statment (Read 941 times) previous topic - next topic

jonisonvespaa

Code: [Select]

/*
*  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 supfanled = 4;            // supply fan led
int extfanled = 5;            // ext fan led.
int esled = 8;                // emergency stop switch led                                       
int gason = 3;               // green led lights if fan1 and fan2 are low connected to pin 9. healthey fan1 and fan2
int fanfault = 6;            // red led lights if fan 1 or fan2 are high connected to pin 8.  (sounds an alarm)
int relay = 12;              // gas relay
int buz = 10;                // buzzer sounds if fault
int muteoutput = 2;          // mute buzzer (removes the low in the buz circuit to mute)
int muteswitch = A7;         // mut switch low input INPUT
int es = A6;                 // emergency stop switch input.   1111                           
int fan2 = A5;               // fan switch is connected to pin 3 
int fan1 = A4;               // fan switch is connected to pin 2 
int fan1val;                 // var for reading the pin status
int fan2val;                 // var for reading the pin status
int esval;                   // val for reading emergency stop status


boolean running = false;     // *****


void setup(){
  pinMode(supfanled, OUTPUT);           // supply fan led o/p
  pinMode(extfanled, OUTPUT);           // extfan led o/p
  pinMode(gason, OUTPUT);               // Greenlled as op.
  pinMode(fanfault, OUTPUT);            // redled 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(muteoutput, OUTPUT);          // Set the switch pin as 1p.
  pinMode(es, INPUT);                   // Set the switch pin as 1p. *****
  pinMode(esled, OUTPUT);               // Set the switch pin as 1p 
  pinMode(muteswitch, INPUT);           // set the switch pin as ip
  digitalWrite(muteswitch, HIGH);       // turn on pullup resistor
}
void loop(){
  fan1val = digitalRead(fan1);            // read input value and store it in fan1
  fan2val = digitalRead(fan2);            // read input value and store it in fan2
  esval = digitalRead(es);                // read estop value and store value
 
  if ((fan1val == LOW) && (fan2val == LOW) && (esval == LOW)) *****NOT READING A LOW ON ES PIN *******

  {         
    delay (1000);                             // check if both inputs show fan OK (Switch is pressed)
    digitalWrite(gason, HIGH);                // turn green led on.
    digitalWrite(relay, HIGH);                // turn on gas relay.
    digitalWrite(buz,LOW);                    // buzzer off, no error
    digitalWrite(fanfault,LOW);               // red led off no fault
                                           
  } else{   
    delay (1000);                               
    digitalWrite(gason, LOW);                 // turn green OFF 
    digitalWrite(fanfault, HIGH);             // red led on
    digitalWrite(buz, HIGH);                  //                             
    digitalWrite(relay, LOW);                 // gas valve off
  }
  {
  if (digitalRead(muteswitch) == LOW)         // switch is pressed - pullup keeps pin high normally
    {delay(100);                              // delay to debounce switch
    running = !running;                       // toggle running variable
   digitalWrite(muteoutput, running);         // indicate via LED
    }
   digitalWrite(supfanled, fan1val);          //fan1 status led
   digitalWrite(extfanled, fan2val);          //fan2 status led
   digitalWrite(esled, esval);                //estop status
                                       
  }}




hi ive got a problem with my if statement i just cant see whats wrong with it,  its not reading esval in the last part, it has a low to that pin but its just not working, any help greatly appreciated

James C4S

How have you determined that esval is your problem?
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Fletcher Chr

Hi

I don't see any internal pull-up's on the input - are you using external pull-ups?

-Fletcher

jonisonvespaa

yes im using external pull ups

jonisonvespaa


How have you determined that esval is your problem?


well im sot sure, im sure its not even reading esval, because the statment works but without the (esval == LOW)

Go Up