I have a dual 5v relay module connected to a UNO. It is wired the standard way shown in all the introductory diagrams.
from the power connections on the Arduino Ground goes to the ground pin on the Relay module, 5v from the Arduino Power connection goes to the VCC pin on the relay module.
I have Pin 8 from the DO side of the Arduion going to IN1 on the relay module.
I have a Sketch that writes a high signal to pin 8 and at the same time a high signal to the built in Arduino LED; after a pause, the sketch then writes a LOW signal to PIN 8 and at the same time a LOW signal to the built in Arduino LED.
The relay turns on when the signal is LOW and turns off when the signal is HIGH. It works exactly opposite from the built in LED.
ANY clue what gives here???
Here's a wiring diagram.... the lines that cross are not connected, sorry not real good a
doing wiring diagrams.
Nothing gives here. That's just how your relay module's circuit works. HIGH and LOW are just arbitrary pin states. Don't make the mistake of thinking HIGH == on. You will find that many circuits, including LEDs are active LOW.
I suggest doing something like this in your code:
const byte relayOnState = LOW;
const byte relayOffState = HIGH;
Then you can do things like this:
Do you see how the code is now self documenting, even without an explanatory comment? There will be no problems with you coming back to an old sketch after a year and trying to remember what the significance of LOW was.
I did not know that. Thanks very much for the reply and suggested code.
I will modify how I use these from now on and test modules before “assuming” they work the
way I expect them to…
Great Help, much appreciated.
Relay modules like this are "active LOW".
You must set the Arduino pin LOW to activate the relay, and HIGH to release it.
If you have problems working with that, then you can use the above 'trick' from pert.
Because the Arduino pin is LOW during bootup, the relay could activate for a few milliseconds during that time.
That short activation could be unwanted in some situations.
A 'trick' is to write a HIGH to the pin in setup() BEFORE you make the pin an output with pinMode().
Thanks very much Leo. Appreciate the additional information.
When I first ran into this, it was very counter intuitive and opposite what I found in the on line posts and YouTube videos about using similar relay modules (which added to the confusion). Before I made this post, I even tested the voltage output from pin 8 on the Uno digital output: High registered 5 volts, LOW registered 0 (zero) volts. I had a hard time figuring out how zero volts could activate the relay.
but it obviously does in this case.
BTW I also appreciate the suggestion from pert about the self documenting code. Something I really appreciate being an "OLD" Fortran coder from back in the 70s and 80s. :o
I had a hard time figuring out how zero volts could activate the relay.
"Voltage" is provided by the relay module itself.
If the Arduino pin also provides a "voltage" (HIGH), there is no voltage difference, and no current will flow.
If the Arduino pin is LOW, current from the relay (opto coupler) can flow through the Arduino pin to Arduino ground.
You can find some 5v relay modules that have a jumper pin to set the relay to trigger on HI or LOW signals.