Chinese relay board on/off inverted

Hey gang!

I bought a Chinese 4-channel relay board as pictured below. When I coded my Arduino Nano project, I had used HIGH for on and LOW for off (what a surprise, right?).
Unfortunately because of the way this relay board was designed, it actually wants you to sink to ground to turn a relay on, thus the relays in my project were operating backwards.
I did some micro-surgery and modified the PCB to remove the common VCC and made ground common instead, so the problem is solved, but I wanted to know, what would be the correct way to handle this in the future?
Is there a way you can invert the digital output pins without literally swapping HIGH and LOW (which would surely make the code a bit confusing).

Thanks for your help!
Dax.

It's so much easier to modify the software! Just use constants with a well chosen name instead of HIGH and LOW:

const byte RELAY_ON = LOW;
const byte RELAY_OFF = HIGH;

digitalWrite(relayPin, RELAY_ON);

I suspect they use active-low signalling on relay modules because many industrial sensors have
open-collector outputs and can only sink current, and this is also the case with most comparator chips.

Active LOW is done on purpose, so you can use the relay module with 5volt and 3.3volt Arduinos.

Just accept that HIGH is not always 'on'.
No need to use extra code for that.
Leo..

You can purchase them with active high, active low, and you select it. ebay, aliexpress and others have them at a very reasonable price.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.