ESP8266 Automatic Watering Circuit - low level trigger relay will turn on but won't turn off

Thread Starter

aaceith

Joined Dec 3, 2021
21
I think its wired wrong, wired to be on when the relay is not activated and off when it is activated, but the 3.3V you are feeding it is too low to actually pull the relay, only light up the led.
Thank you. I will try the Vin pin or add a separate 5V source for the relay control. I agree that the default condition should be off with activation of the pump.
 

Thread Starter

aaceith

Joined Dec 3, 2021
21
See above, the module is designed as active low. The input needs to be pulled down to turn the relay on. The 3.3V supply is a separate question, and it could be a problem (though the author of the article it is taken from says he is using 3V3).

The odd part is the choice active low logic. It would mean if the MCU goes dead the pump would fail on. This doesn't seem to be a good design.
I definitely do NOT want this thing to default to active pumping if the controller fails. That said, I am limiting the water supply and making sure the supplied plants have saucers big enough to handle a critical failure like you describe.
 

Thread Starter

aaceith

Joined Dec 3, 2021
21
I think the way the relay board works is that when Vin is not connected to anything, the relay is off. When Vin is shorted to grounded, the relay operates.
With no power to the MCU, the relay is off.
Its not really active low.
I dont see a voltage regulator on the relay logic board, therefore I think the base of a transitor, or a gate of a fet is being pulled to ground to operate the relay.
In that case, the digital output of the MCU needs to be set as an input(high impedance) for off, and set to digital ouput and set to low to turn relay on.
Your reply matches what I have observed when I get the relay to work using a higher voltage to supply it. When the capacitive moisture sensor is dry, the pump is on; wet the pump is off. If I pull the control pin connector but leave the ground and Vcc, the pump is off.
 

Thread Starter

aaceith

Joined Dec 3, 2021
21
Wired like that, your motor will kill your 3.3v rail and cause all sorts of odd issues. Power it from the 5v Vin pin, if you're using USB to power it all, or better a separate 5v supply.

Secondly, as already noted, the relay is a 5v component. It won't reliably pull in on 3.3v. Again power it from the 5v rail.

Confusingly those boards appear to be low-level triggered, i.e relay closes when input is low and open when input high or open-circuit. See here for similar module. So your logic would appear to be correct.
I thought the same thing about the 3.3V rail being under powered to power the pump but the designer of this circuit says he has gotten it to work without a failure of the board. In short term testing, the pump motor does run (not under load) with the 3.3V pin. The relay begins to work if I power it with the Vin pin at nearly 5V.
 

Thread Starter

aaceith

Joined Dec 3, 2021
21
The module is active low. Pulling the pin down to ground turns on the relay. In this case the choice was made to connect the pump's supply to the NC contact that means when the relay is on (pin low) the pump is off. When the relay is off, the NC contact closes and the pump runs.
I thought the same at first but if you look at the diagram, it is because a wire partially obscures the "O" in the "NO" label that it looks like it's the NC side. It is actually the NO side that is connected.
 

Thread Starter

aaceith

Joined Dec 3, 2021
21
This is the line that's confusing. Is he connecting a constant 4.6 volts to the Vin pin as power instead of the Vcc pin? Or does he means power from the Vin pin of the ESP8266?
Apologies. That was not very precise. I had no luck with the 3.3V pin recommended by the original designer of this circuit, so I tried the Vin pin, which I measured to have a voltage of 4.6V. Interestingly, without any changes in the circuit (and I have four identical ESP8266s, pumps, and relays) the relay started to work. I.E. it will trigger with the appropriate low moisture stimulus.
 

Thread Starter

aaceith

Joined Dec 3, 2021
21
One possible reason for the relay staying on is if the Vcc of the relay module is 4.6 volts but the control voltage is 3 volts from the ESP8266. The transistor on the relay board is probably not switching OFF completely and the relay stays activated due to the lower dropout voltage. The LED though would appear to operate normally.
I must say, as a beginner, much of these very kind replies are at the edge of my current (no pun intended) knowledge. I was scouring various forums and a few people mentioned something about "pulling the pin low" but I don't know what that means.
 

Thread Starter

aaceith

Joined Dec 3, 2021
21
This looks very technical but I think what I'm seeing is a proof of concept for the suggestion that 3V is not enough to deactivate the circuit. Initially, when I tried the Vin pin to power the relay, there was no difference in behaviour but, without making any changes to the coding or wiring apart from powering the the relay with the Vin pin (yes I know it implies an input but it delivers a 4.6V supply) it started working.
 

Thread Starter

aaceith

Joined Dec 3, 2021
21
And the relay module seems a very odd choice of component to turn the little pump on and off. The relay is nice if you are looking to isolate the processor from the pump and turn a high power pump on and off, but this is only a 3 to 4.5V pump drawing 280mA. I don't know the current output of the processor digital output pins but even a small signal reasonably high gain NPN transistor, with resistor from processor into base, emitter to ground and pump connected between the 4.5V supply and collector would be simpler and easy to test. If indicator diodes are important, use two other output pins - with resistors in series to make sure they are not pushed beyond their current limit.
Thank you for articulating this suggestion! I wondered the same thing and watched a couple of Youtube videos to try to figure out the logic of adding a relay to a board that, itself, is powering the pump. I don't know enough to argue for a transistor solution to the on/off issue but I did wonder why it wasn't proposed. I looked online and the maximum current you can draw from a GPIO pin is 12 mA. As for the 3.3V pin, I found a post that indicated the whole board minus what is pulled from the 3.3v pin can handle 500mA. That seems like a lot.
 

Thread Starter

aaceith

Joined Dec 3, 2021
21
Note that these two lines are a problem if soilmoisturepercent is 50 because they are both true and the code will toggle the relay control on and off at the speed of the code loop.
if (soilmoisturepercent <= DrySoilMoisturePercentage)
if (soilmoisturepercent >= DrySoilMoisturePercentage)

I would probably change this line to not be equal like this;
if (soilmoisturepercent > DrySoilMoisturePercentage)
Thank you for catching this! I changed the code.
 
I looked online and the maximum current you can draw from a GPIO pin is 12 mA.
Which is why you should use an output connected to a resistor connected to the base of an NPN transistor where the emitter is connected to ground. If you let that resistor have a value of 1K ohm for example the current from the output pin will be about 2.7mA - because the voltage drop across the resistor will be 3.3V less the base emitter voltage of 0.6V. Now connect the pump between the 5V supply and the collector of the transistor. If the transistor has a gain of 100 or more you will be turning the transistor hard on and you'll be able to pull 270mA or more through the pump. A 470 Ohm resistor would be okay if you are not sure of the transistor gain. If the pump runs too fast put a lowish value resistor in series with it - or PWM the output pin, a nice way to control the pump motor speed.

At a stretch you could put a red LED in series with the resistor if you reduce its value to maybe 180 Ohm. The drop across a red LED is typically around 1.8V so the drop across the LED plus the base/emitter is around 2.4V leaving 0.9V across the resistor, giving 5mA - enough to make most LEDs reasonably bright. Other LED colours have a higher voltage drop so could be used with a smaller resistor value.

Thanks for the compliment by the way :)
 

Irving

Joined Jan 30, 2016
3,845
If the transistor has a gain of 100 or more you will be turning the transistor hard on
Except that a saturated power transistor eg TIP41 has a gain of about 10. For 300mA Ic you need an Ib of 30mA. Also the Vce(sat) is about 1v so the motor only gets 4v, and the transistor dissipates about 300mW.

A solution to the gain issue is to use a Darlington Transistor, eg TIP141. Saturated, this has a gain of 500 so Ib would be in the order of 1 - 2mA. However the downside is the saturation voltage is even higher at 1.5 - 2v, and dissipates around 600mW.

That's why the MOSFET is a better solution. The on-resistance is around 0.1ohm, dropping only 30mV at 300mA and dissipating around 10mW.
 
Except that a saturated power transistor eg TIP41 has a gain of about 10.
But I don't think you need a power transistor or a darlington pair - there are quite a number of inexpensive small transistors which can handle up to 500mA with DC current gain quoted as minimum 100 and they are usually actually higher gain than specified. If you turn them hard on they dissipate hardly any power, and Vce(sat) will be a lot less than 1.0V. The pump is rated at 180mA and voltage 3.0 to 4.5V.

I'd agree, the IRLZ44N is a nice solution, great if you need to switch one hundred times 180mA or more - it has a Rds(on) of 22 mOhm.
 
If I immerse the pump in water, which is its intended design, the total circuit uses 300mA. I'm a little worried how much that number will jump when I add tubing. I have a feeling it will fry the board. Thoughts?
Just seen your update. Where is your Vin power supply coming from? If you are continuing to switch the pump on and off with a relay surely it's not affecting the board at all? - the current for the pump is coming from your power supply that feeds Vin, going to ground via the relay as a switch. Even if you are running it from a USB connection that should be happy up to a total of around 500mA.
 

Irving

Joined Jan 30, 2016
3,845
But I don't think you need a power transistor or a darlington pair - there are quite a number of inexpensive small transistors which can handle up to 500mA with DC current gain quoted as minimum 100 and they are usually actually higher gain than specified. If you turn them hard on they dissipate hardly any power, and Vce(sat) will be a lot less than 1.0V. The pump is rated at 180mA and voltage 3.0 to 4.5V.

I'd agree, the IRLZ44N is a nice solution, great if you need to switch one hundred times 180mA or more - it has a Rds(on) of 22 mOhm.
Not sure I agree with you. OK, lets agree a spec. Max Ic = 1A, Vce(sat) ~ 0.5v, TO92 case, 1W max A typical and commonly spec'd transistor of that type would be the ZTX-series as per table below - the ZTX450 appears in many magazine projects over the years for this purpose. To guarantee saturation the base current Ib needs to be ~0.1 x Ic, as highlighted, therefore Ic = 180mA is outside the spec for the gpio - and remember the 180mA, I understood from post #38, is run current off-load, not start current under load.. You can't use the columns to the right, they only apply for small signal amplification when the transistor is suitably linearly biassed. Now, I agree for hobby use you could probably get away with a single transistor and it'll work fine, most of the time. I spent several happy years as a teenager working in an electronics store evenings and Saturdays fixing magazine projects for customers to know that's not always the case. I certainly woudn't spec a single transistor for commercial use.

For me the MOSFET is the most sensible, no worries, approach.

1666113636980.png

An alternative to the darlington which solves this, at the expense of another transistor is this arrangement, which produces near identical results as the MOSFET

1666117093080.png
 

daveymg-nz

Joined Apr 26, 2023
1
I think the way the relay board works is that when Vin is not connected to anything, the relay is off. When Vin is shorted to grounded, the relay operates.
With no power to the MCU, the relay is off.
Its not really active low.
I dont see a voltage regulator on the relay logic board, therefore I think the base of a transitor, or a gate of a fet is being pulled to ground to operate the relay.
In that case, the digital output of the MCU needs to be set as an input(high impedance) for off, and set to digital ouput and set to low to turn relay on.
Thanks for this tip, I had a similar issue getting the 5v module to operate and this solution worked perfectly.
 
Top