I have made a simple controller for my outdoor hot tub that I have been running for a few years without problem. Now I have changed some components and starting to build a new program to get rid of some code that was not used and also need to change the functions. I have just started so there is not much in the code so far.
The arduino is connected to a relay card with 8 relays on it. Pin 2,3 4 is for activating 3 different relays. The relays is used for controlling 3 different contactors.
The problem is, with the code below, that the 3 pins (2,3 and 4) is turning HIGH when the program starts. The 3 used relays (and contactors) is activated. If i put digitalWrite(heater, LOW); in setup or loop there is no difference.
Please post a wiring diagram and a link to the relay module. Pins default to INPUT on restart, so they are not presenting a HIGH output level, unless you have pullup resistors on them.
Try adding a line in setup() to set the output low:
pinMode(heater, OUTPUT); // sets the digital pin 13 as output
digitalWrite(heater, LOW);
jremington:
Please post a wiring diagram and a link to the relay module. Pins default to INPUT on restart, so they are not presenting a HIGH output level, unless you have pullup resistors on them.
Try adding a line in setup() to set the output low:
pinMode(heater, OUTPUT); // sets the digital pin 13 as output
digitalWrite(heater, LOW);
Why the comment about pin 13?
It was just standard code from an example. Forgot to remove it.
There is no difference if I add the digitalWrite in setup. Still all 3 pins are HIGH.
If I put // before all three pinMode the pins stay as Inputs and all relays are off. As soon as I remove the comment, // on one of the pinMode the pin get HIGH and relay is activated.
I had no instructions with my board. And I googeled and found the link with this board that seems to be the same kind.
Then I wil just change the cables on the board to NO instead of NC and problem is solved without code. Then when the pins are LOW. The relays will be ON but the contactors will be OFF.
Why that.
Relays draw ~75mA all the time, and that might give overheating problems if they are on 24/7.
They should be off most of the time, and only active if the pump/heater is ON.
Coding active LOW is just as easy as active HIGH.
if(tempIsTooLow)
{
digitalWrite(relay1Pin, LOW); // heater on
}
else
{
digitalWrite(relay1Pin, HIGH); // heater off
}