Go Down

Topic: problem with my if statment (Read 1 time) 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)

James C4S


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


Measure the pin with a multimeter and add a Serial.print(esval) to determine what is actually happening.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

jonisonvespaa

yes ive measured it several times 3 lows all the time, ill add a Serial.print(esval) and see

jonisonvespaa

im getting a 0 low all the time monitoring it through serial monitor even though im using a pull up resistor, ive checked the circuit many times

Grumpy_Mike

Quote
im getting a 0 low all the time monitoring it through serial monitor even though im using a pull up resistor

So are you reading a low all the time with your multimeter on the actual arduino pin (that is the pin on the chip in the socket).

If this is so then unless you pull up is stupidly high then you have your wiring wrong.

tgm1175

It's possible the pin burnt out on the chip.  Try using a different pin and see if the results change

jonisonvespaa

yes ove got 0v, then plus 5, then ov, using a meter, going to try another pin maby its a faulty pin, but its a new board

jonisonvespaa

tryed another pin and its ok, must be a faulty pin/board

thanks very much for the help, really appreciate it

Go Up