problem with relay

dear sirs

i had a problem with relay.

since i had a project about pH controller.
i define relay ln1 as CH1 dan ln2 as CH2. and pHValue as analogRead.
here is the code
the problem is when pHValue > 6. CH1 is On. it's work
but when the pHValue < 6 CH1 is off and CH2 doesn't switch on.

if(pHValue > 6)
{
digitalWrite(CH1, HIGH);
} else {
digitalWrite(CH1, LOW);
}

if(pHValue < 6 )
{
digitalWrite(CH2, HIGH);
} else {
digitalWrite(CH2, LOW);
}

the problem is when pHValue > 6. CH1 is On. it's work
but when the pHValue < 6 CH1 is off and CH2 doesn't switch on.

if(pHValue > 6)
{
digitalWrite(CH1, HIGH);
digitalWrite(CH2, LOW);
}
else // replace else with  if(phValue < 6)  if nothing should happen when value is 6
{
digitalWrite(CH1, LOW);
digitalWrite(CH2, HIGH);
}

Note that "else" is also on a different line.
Leo..

What happens if
pHValue == 6

Good point. Nothing happened in OP's code.
Don't know if OP wanted nothing to happen.
Added a comment to the code.
Leo..

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
So we can see how you have your relays connected.

What model Arduino are you using?

Thanks.. Tom.. :slight_smile: