8 Channel Watering System

Yes, I checked out your Wokwi example, thank you. The solenoids and pump both run off of 12v from the 5V relays. If I have the solenoids activated from a 12v source do I still need resistors for flyback?

Diodes for flyback.

I believe that this logic should be okay. The moistureLevel is derived from the capacitive sensor reading with the previous statement of "moistureLevel = analogRead(moistureSensor[i]);" . The sensor array should be read in sequential order. The statement "if(moistureLevel > moistureThreshold)" I believe looks erroneous or backwards because it appears to be telling the pump/solenoid to energize when the moistureLevel has already surpassed its threshold. Equally, the "ON = LOW" & "OFF=HIGH" are backwards from the norm ON being high.
Does that make sense or does it only make sense in my head?

Got it. Thanks

That statement will turn ON BEFORE it reaches moistureThreshold

Yes, I think that is what I need, and once it surpasses the threshold it should turn off. Do you agree?

Hi Guix,
I was hoping to inquire about the code that you sent me for the watering system. Can the code be used on a mega2560 or only on an esp32? What is the uint8_t. I'm not going to pretend that I understand all of the logic but I think I can learn a little if I write the code to fit my system.

I did get all of my solenoid to operate independently, but cannot find a way to code in the pump as energized when any of the sensors are calling for it, or I code something and the pump stays on constantly. Thanks for the help!

Hello

This is an Arduino Nano not an ESP32 :slight_smile: And the code should work on every board using the Arduino framework.

uint8_t is a data type of an unsigned integer that can store 8 bits (one byte). I used this data type because the value of this variable (or constant) will never be less than 0 or greater than 255.

In my example, the pump (the green led) turns on if at least one of the sensors (the potentiometers) is above its threshold, isn't that what you want ? Did you try the simulation (press the "Play" button) ?

Maybe you want to change the comparison to
if ( analogRead( sprinklers[i].sensor_pin ) < sprinklers[i].threshold )
as discussed earlier

I've updated my example with this change

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