Projects

Fountain Filler

My family has a fountain outside our house that always runs out of water quickly. Whether it be to evaporation, birds coming and drinking, by the end of 2 days, we will have to refill the fountain with a yard hose. And usually the task would always fall upon me to do it.

Recently, I have received an AdaBox 015 to tinker around with. This time, they sent an Adafruit CLUE, which is a really cool microcontroller with the same form factor as a BBC micro:bit, but is packed full with sensors ranging from temperature all the way to magnetic field sensors and gesture sensors! Along with the CLUE, Adafruit also shipped their Bonsai Buckaroo and a water pump with PVC piping. They also sent a makeshift water moisture sensor, which is essentially alligator clips and stainless steel nails.

This box is perfect for creating a plant watering system! With its sensors and the given pump, you can automatically water a plant in its pot without having to even be there! But we don’t have to only stay loyal to the plant. We can water whatever we feel like. Such as perhaps… a fountain?

I got to work setting the entire gizmo up and configuring the code. I used some of the tutorial code but naturally I modified it to my needs. Since this board runs on CircuitPython, I whipped up my code in a breeze and it came out like this:

import time 
import board
import digitalio
import analogio
from adafruit_clue import clue

clue.pixel.fill(0)

motor = digitalio.DigitalInOut(board.P2)
motor.direction = digitalio.Direction.OUTPUT

analog = analogio.AnalogIn(board.P1)

def read_and_average(analog_in, times, wait):
    analog_sum = 0
    for _ in range(times):
        analog_sum += analog_in.value
        time.sleep(wait)
    return analog_sum/times
    
clue_display = clue.simple_text_display(title="  FOUNTAIN SENSOR", title_scale=2)
clue_display.show()


while True:
        analog_value = read_and_average(analog, 100, 0.01)
        percentage = analog_value / 65535 * 100
        clue_display[0].text = "Moisture Sensor: {}%".format(int(percentage))
        clue_display[1].text = "Pressure: {:.1f} hPa".format(clue.pressure)
        clue_display[2].text = "Temperature: {:.1f}ÂșC".format(clue.temperature)
        clue_display[3].text = "Humidity: {:.1f}%".format(clue.humidity)
        
        if percentage < 50:
            motor.value = True
            clue_display[6].text = "Motor ON"
            clue_display[6].color = (0, 255, 0)
            clue.play_tone(880, 10)
        
        motor.value = False
        clue_display[6].text = "Motor OFF"
        clue_display[6].color = (255, 0, 0)

Most of the code explanation is found at their provided site, but in a quick rundown:

Lines 1-5: Import the libraries that will be used by the CLUE (these aren’t done with a simple pip install)

Lines 7-12: Setup all the relevant variables and pinouts

Lines 14-19: Create a function that quickly provides me with an average moisture level so I can use it later

Lines 21-22: Initialize the display of the CLUE so I can print any readings I want on the board itself. I also turn on the screen so that I won’t just have a black screen showing all the time.

Line 25: We start an infinite loop that keeps on turning the motor on and off depending on the water moisture percentage

Lines 26-27: We get the water moisture percentage like stated above.

Lines 28-31: Add some information to the screen on the CLUE because I want to get more use out of the board other than it being a glorified motor controller.

Lines 33-37: This controls the motor, as if the water moisture percentage is less than 50%, then turn on the motor for 10 seconds while playing a note at 880 Hz. We also display that the motor is on so that we won’t only have to rely on an auditory cue.

Lines 37-41: Turn off the motor (and display accordingly)

With these simple lines of code, I have essentially created an automatic water pump that pumps water from a reservoir to my fountain. I found a couple of large boxes that is large enough to house both the pump and my electronics and a lot of water, and I cut holes in them so that I can route the wires and pipes through it all. I used the included battery pack and achieved this:

I have noticed that the CLUE board is actually running on a nRF52840 BLE processor, which is a Bluetooth LE processor, which means that I can connect to it via bluetooth and control or read its sensors from there. But I have yet to figure it out how to reliably do it with CircuitPython. CircuitPython doesn’t support asynchronous functionality, so if I was to enable this bluetooth connectivity, it would halt all other processes (like pumping water or reading sensor input) until I connect to a device via bluetooth first.

In the future I plan to create a better water moisture monitor and maybe upgrade my pump so that it will be able to fill my fountain more efficiently than at its current stage. I also plan to transmit sensor info over bluetooth so that I can sit in my living room and check what the humidity is near my fountain. Why? Because I can, that’s why.

That’s all I have to show for you all today, if you have any questions about my steps, then I will be happy to answer them. Otherwise, I hope to see you next time!