sketch doing opposite of what it's supposed to do...

If I assign LOW to a pin, it energizes the optocoupler relay. If I assign HIGH to a pin, it will not energize the optocoupler.

I am using a new nano, 4 channel 5V optocoupler/relay and a 5V 2A power supply that puts out 4.77V.

VIN from the nano and VCC from the optocoupler are connected to +5V.

Ground from nano and opto are connected to -5V.

With this test sketch, pins 2, 3 and 4 make the NO relays closed. The NO relay connected to pin 5 remains open.

If you guys could help me get to the bottom of this, it would be much appreciated.

void setup() {


  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);    
  pinMode(4, OUTPUT);      
  pinMode(5, OUTPUT);
}
void loop() {
  digitalWrite(2, LOW); 
  digitalWrite(3, LOW);      
  digitalWrite(4, LOW);
  digitalWrite(5, HIGH);

}

The LED in the optocoupler is wired to +5 through a resistor to the Arduino output. Setting the output to LOW allows current to flow through the LED to ground, turning on the LED and therefore the phototransistor in the optocoupler and energizing the relay.
If the output is HIGH there is no potential across the LED and it will not light.

Wired like this
OPTO RELAY.jpg

saltyjoe:
If I assign LOW to a pin, it energizes the optocoupler relay. If I assign HIGH to a pin, it will not energize the optocoupler.

You will often come across this sort of issue. You should not assume that HIGH = on and LOW = off. Just use whatever works. The Arduino does not care.

For example if you use the recommended pinMode(pin, INPUT_PULLUP); for an interface to a switch HIGH will mean the the switch is OFF or open.

...R

I was sure I must have something hooked up backwards or something and switching the pin assignments would cause trouble later. Switch them, I will.

Thanks a ton, you guys!