Problem using ultrasonic sensor with relay and solenoid valve

Here's the catch, what I want on the output for the autodrinker which is like elkay bottle filler. The autodrinker has a filter status that has a green, yellow, and red led, which is connected to the water flow sensor, I already fixed that, but when the led turned to red and I put the bottle on the ultrasonic sensor (HC-SR04), the 5v relay module activates the solenoid valve (yf-s201) which activates the water flow.

So, what I want is when the led turned to red, relay and solenoid valve is still off even when you put the bottle on the sensor, so the water flow will not activate, but it will activate again if the person press the reset button on the arduino mega 2560, the green led will turn on and so the relay & solenoid valve.

see the attached code

drinkinhg_fount.ino (2.55 KB)

drinkinhg_fount.ino (2.55 KB)

your code is not simple as to understand looks more undefined and no logical view ..
make function for red yellow and green and make the code simple....
send the whole code ...may we got to help

okay

And please do go and read the sticky. It helps you get the most out of this forum.

I think should do it. but which part are you referring to.