Relay module behaviour

I bought this cheap and suspicious automatic irrigation set consisting a 5V miniature pump, a relay module (JGC-3F it says on top, seems to be a quite common relay shield) and a soil moisture sensor consisting of a fork probe and a transmitter module. The way the moisture sensor worked didn't really convince me, so I started to experiment with connecting the relay to an Arduino Uno board and playing around with timing.

Now I have a simple code where turning a pin HIGH on the Arduino closes the relay and the pump pumps for a while. Then the Arduino turns the pin LOW, the relay opens, pump disconnects and the Arduino waits for a longer period. Works fine.

What I don't get is that if I disconnect the jumper wire going from the Arduino pin to the relay IN, the relay closes and the pump starts pumping. If I connect the jumper wire from the relay to 5V, it keeps still pumping. If I ground it, the relay opens. It works as if it would close when the signal is low, but when connected to the Arduino pin, it definitely closes when the pin is high. There is probably a very simple answer to this, but I just can't get it right now.

For additional information: the relay module has three pins on the control side: VCC, GND, IN and the VCC and GND are appropriately connected. The red led is always on and green led turns off when the relay closes.

Puzzling.

So clearly we need a photo (which is to say, taken in good light, generally outside daylight but not full sun, not in a dark room, actually focused and with a resolution at least 1024 x 768) of your arrangement and the Web link showing the relay module. :grinning:

Here are the photos. For clarity I removed the moisture sensor and it’s wiring.

Note: As you see here the whole thing is powered from the Arduino board 5V pin. I know it’s maybe not the most recommendable choice but I can’t see how that would be the problem here as the thing works as it should when run from the Arduino: when the pin connected to relay IN is HIGH, the relay connects and the current seems to be enough for everything: the board, the relay and the pump itself.

The only answer to my question that I personally can come up with is that the problem would in fact be in the code: that the control pin would actually be low when I have thought it should be high and that causes the confusion. But the code couldn’t be clearer:

// this is where the pump goes ON for 10 secs
digitalWrite(pumpPin, HIGH);
delay(10000);
digitalWrite(pumpPin, LOW);
// then the code waits for a longer period

Probable solution: The relay is active low (instead of active high as I thought) and the pump was connected to the NC of the relay instead of NO. Some practice in basic logic for me...

But what I didn't get before is that connecting something (the relay signal wire in this case) to a low pin is actually the same as grounding it. I thought it would be the same as just disconnecting it. I tried be reversing both the code (the pin goes now LOW for a short period and HIGH for a longer period) and the relay-pump wiring (it's now NO/normally open for sure) and it works fine for the purpose, but for curiosity's sake I still wonder why disconnecting the signal wire in this schematic doesn't turn the pump on but grounding the wire does. (Well, actually I'm driving a test arrangement with a led right now, with the pump it's not so obvious when it's on and when it isn't, but nevertheless...)

I still wonder why disconnecting the signal wire in this schematic doesn't turn the pump on but grounding the wire does.

In most of the active LOW relay modules grounding the input completes a circuit which lights up an led in an optocoupler.

A floating input of disconnected input does not do that.

Looking at a schematic of your relay module will help you.

Yep, the ol' noobie brainlock, HIGH is ON, LOW is OFF. Shake that off ASAP, either can be either. :slight_smile:
EDIT: In fact LOW is ON is more common in digital logic.

cattledog:
In most of the active LOW relay modules grounding the input completes a circuit which lights up an led in an optocoupler.
A floating input of disconnected input does not do that.

I'm blushing for my ignorance here but I never before realised that the low state of an Arduino pin would mean it to be the same as ground. I thought that the 0V there would mean that it's just disconnected from everything inside the board, just a disconnected output, no voltage being another thing than ground. (I'm not a native speaker of English so sometimes the terminology can cause confusion, but I think here this is not the case). Does this mean that I could light a led or do whatever by connecting it between the Arduino 5V and a low pin OR AS WELL Arduino GRD and a high pin? (If it's a led the of course minding it's polarity and a current limiting resistor etc.)

Does this mean that I could light a led or do whatever by connecting it between the Arduino 5V and a low pin OR AS WELL Arduino GRD and a high pin? (If it's a led the of course minding it's polarity and a current limiting resistor etc.)

Yes, if the pin set LOW with digitalWrite() is an OUTPUT.

https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/

If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V (ground) for LOW.