Pages: [1]   Go Down
Author Topic: problem with my if statment  (Read 918 times)
0 Members and 1 Guest are viewing this topic.
uk
Offline Offline
Sr. Member
****
Karma: 0
Posts: 314
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
/*
 *  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
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How have you determined that esval is your problem?
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

0
Offline Offline
Full Member
***
Karma: 2
Posts: 156
It was all digital
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

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

-Fletcher
Logged

uk
Offline Offline
Sr. Member
****
Karma: 0
Posts: 314
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes im using external pull ups
Logged

uk
Offline Offline
Sr. Member
****
Karma: 0
Posts: 314
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

uk
Offline Offline
Sr. Member
****
Karma: 0
Posts: 314
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

uk
Offline Offline
Sr. Member
****
Karma: 0
Posts: 314
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34725
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pennsylvania, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

uk
Offline Offline
Sr. Member
****
Karma: 0
Posts: 314
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

uk
Offline Offline
Sr. Member
****
Karma: 0
Posts: 314
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

thanks very much for the help, really appreciate it
Logged

Pages: [1]   Go Up
Jump to: