Programming a pico for a live bait tank in my boat

~'hi, I’m an older bloke that loves tinkering around in my shed . I recently installed a live bait tank in my boat. I also discovered Core Electronics and all the stuff i could use, although not yet able to programme.

My project now is to switch the pump on at the helm and have it run till the tank is full and overflowing then stop the pump for , say, 10mins and then run again for say 2mins till i close the switch . this is to save battery power and because its fun to do. I also want a bezel mounted led on the helm to blink on and off when the programme is running , this will be a warning to shutdown the pump if its not running when I get back to the boat ramp. I will power project from the boats 12v battery.

Also , as the pump will be out of the water when driving the boat im going to install a 12v relay that picks up a voltage when i turn on the motor. Thats easy because there is un used cables at the control that will turn on when motor is running.

From Core i have the following;
CE05137 5V Single Channel Relay Module 10A

Raspberry Pi Pico (with Soldered Headers)

DFR0379 20W Adjustable DC-DC Buck Converter with Digital Display

So from following a guide i was able to get a programme using thonny to switch a led on a bread board on for 5 seconds then off for 20seconds and can understand how the programme is doing that.

Now my problem is , how do i make the indicator led blink and have the main programme running using the 12v relay.
I have tried googling and youtubing and hope someone can help with this , im sure its simple to do , but at the moment im not going anywhere.
Thanks ALL


Welcome back Andrew :slight_smile:

Sounds like a neat project!

It sounds like there is a couple of bits to your project:

To detect if the relay is closed you’ll want to connect one of the COM pins on the output of the relay to 3.3V on the Pico, and a pin that you arent using to the normally open (NO) pin. This will basically act as a button or switch.
Be sure that the 12V from your boats electronics dont make their way into the Pico, this will definitely let out the magic smoke!

On the software side we’ll want to set up an input with a pull-down resistor, and an output.

from machine import Pin
import time

led = Pin(15, Pin.OUT)
relay = Pin(14, Pin.IN, Pin.PULL_DOWN)

while True:
    if relay.value(): #This will only run if the relay is closed


This is using what’s called ‘blocking code’ so once it enters the if statement it cant exit until the led has finished its 2 seconds on 10 off cycle, this is good for systems that should have a set duty cycle like yours!

To get the helm LED constantly blinking you could utilise threadings to keep it blinking:

import machine
import utime
import _thread

led = machine.Pin(15, machine.Pin.OUT) # This will end up being your motor input. to drive an appropriately rated relay should work
relay = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)
blinkLED = machine.Pin(25, machine.Pin.OUT)

def blinkThread(): #This function will run as long as blink is True
    global blinkLED
    while blink:
        utime.sleep(1) # Blink once a second

while True:
    if relay.value(): #This will only run if the relay is closed
        blink=True    # Starts the blinking


Let us know how you go!


Hi Liam ,
Thanks for your help, that info was greatly appreciated.

I’m having trouble understanding a few things though ,ie

connecting output of the relay COM to 3.3v on the pico. I had planned to use the same 12v battery to power the pico with a voltage controller and the 12v pump. Do i need to power the pico differently?

also, do i use any pin on the pico im not using to connect to the normally open pin on the relay, then also connect 12v to COM and normally closed relay outlet ? I don’t understand how i can just connect to any pin.

I’m thinking this is a bit out of my league , but would feel great to get to work , as i already have some more projects in mind … But i think i will do some projects already posted under projects , and learn along the way.

anyway i think its great that i can get support from other makers , good way of helping novices along the way.
kind regards

1 Like