Arduino automatic plant waterer, relay works in setup() but not in loop().

djsfantasi

Joined Apr 11, 2010
9,186
Working backwards in your code, the water pump is turned on when
mval<=50​
“mval” is the result of the map() function. Your input limits are as follows:
Map(Val,200,700,100,1)​
But the input can be from 0 to 1023 unless you know something I don’t. What happens if val<200 or val>700?
 

SamR

Joined Mar 19, 2019
5,078
Gary my approach would be this. Start with the soil moisture sensor. Is it getting an input? Using serial monitor you can see this and test it by wetting and drying the sensor. Apply a setpoint to trigger a green LED when above setpoint and a red LED below the setpoint. Start there.
 

Thread Starter

Gary Clarke

Joined Sep 11, 2019
18
Thanks both.

Yes i use the serial monitor, thanks Sam, it's a handy tool indeed.

djs in practice these capacitive sensors don't go below 220 or above 650 (i bought 10 and have tested 3), even when hanging in dry air or fully immersed in tap-water.

I did start with the sensor and built the project up as i went along, and i've re-tested multiple times.

Since this Uno won't power-up via Vin/GND i may have blown the voltage regulator or something, i'll know when the nanos arrive (the nano i thought i had turned out to be a pi zero).

Thanks again chaps, i'll update after i've tested with nano.
 

djsfantasi

Joined Apr 11, 2010
9,186
djs in practice these capacitive sensors don't go below 220 or above 650 (i bought 10 and have tested 3), even when hanging in dry air or fully immersed in tap-water.

Since this Uno won't power-up via Vin/GND i may have blown the voltage regulator or something, i'll know when the nanos arrive (the nano i thought i had turned out to be a pi zero).
Have you connected the UNO with a nine volt battery (nothing else) and measured the voltage at the 5V and 3.3V pins? This would be a quick check that the regulators are still working (or not).
 

Thread Starter

Gary Clarke

Joined Sep 11, 2019
18
That's odd, the Uno now powers-up using Vin/GND, which it didn't before.

Okay, so now i have this setup :

1 x 12V SLA Battery
1 x LM2596 module from battery to 5V rail for relay.
1 x LM2596 module from battery to 5V rail #2 for pump.
1 x LM2596 module from battery to 3V rail for sensor.
Uno connected to the 12V battery.

So they all share common ground from the battery, everything works fine apart from firing the relay (it doesn't work in setup() or loop()).

I don't get it, it should be simple.
 

AlbertHall

Joined Jun 4, 2014
12,396
How are you driving the relay coil from the arduino pin?
Which arduino pin are you using for the relay?
Include the complete, presently not working, arduino code.
 

Thread Starter

Gary Clarke

Joined Sep 11, 2019
18
How are you driving the relay coil from the arduino pin?
Which arduino pin are you using for the relay?
Include the complete, presently not working, arduino code.
Solved, turns out that the sensor gives a different reading range when relay and pump are hooked up, so all i had to do was change my limits!

Thanks for all the help and suggestions :)
 

Thread Starter

Gary Clarke

Joined Sep 11, 2019
18
Still sounds like a V problem? Why would the sensor range shift?
Not sure but it definitely gives a compressed range when relay is closed, but only when powred via USB or AC adapter, not when powered via Vin/GND (which works now!?).

I don't like when a fault is intermittent or variable but it's all working as expected now so i'm happy :)
 

SamR

Joined Mar 19, 2019
5,078
only when powred via USB or AC adapter, not when powered via Vin/GND (which works now!?).
AHA... So you get full range with external power. Good. I ran into this once with a temp sensor with a large complicated Arduino circuit. Everything was working fine until I added a few more parts, then the temp became erratic. I was just playing around and I knew what the problem was but I didn't go the extra step of externally powering the circuit to correct it. Good! Glad it's working.
 

Thread Starter

Gary Clarke

Joined Sep 11, 2019
18
AHA... So you get full range with external power. Good. I ran into this once with a temp sensor with a large complicated Arduino circuit. Everything was working fine until I added a few more parts, then the temp became erratic. I was just playing around and I knew what the problem was but I didn't go the extra step of externally powering the circuit to correct it. Good! Glad it's working.
Thanks Sam :)
 

Thread Starter

Gary Clarke

Joined Sep 11, 2019
18
BTW, your cat reminds me of one of ours that died a couple of years back, he died of a liver tumour, and during the course of my reading i found that there's an epidemic of cat and dog cancer and it's likely to be linked to grain/cereal-based dry foods, so if you can find your pets grain-free dry food it'll be better for them :)

there's also something called Carageenan in wet foods that is cancer-causing so always read the label!
 

djsfantasi

Joined Apr 11, 2010
9,186
What are you powering from the Arduino GPIO pins? There is a recommended maximum of 20 mA per pin with a total of 200mA for the entire board.

What are you powering from the Arduino 5V pin? There is a 400-600 mA maximum depending on if the Arduino is powered by an external supply or USB.

So if the relay is drawing more than 20 mA, you’re going to have problems. Or if you’re drawing more than the board max you’re going to have issues.
 

SamR

Joined Mar 19, 2019
5,078
if you can find your pets grain-free dry food it'll be better for them :)
We lost his littermate to cancer a while back and another earlier. One of my many "work my way through school" jobs was as a Jim Dandy Feed Store manager and learned what they use in pet food is pretty sad for some of the companies in order to make a cheaper and more profitable product. One case in fact is the use of Feather-Meal. When poultry is processed they sell everything but the cluck including the feathers which are "protein" and are used as a feed additive to boost the protein percentage even though it is not digestible.
 
Top