Apologies if this is not a pico question, not sure where the problem lies...

I have a small hobby motor (5v) mounted with a hobby fan:


that is connected to Normally Open on a relayRelay and 5V Wall Power supply (via a barrel/terminal block adapter. I also hooked up an oled and a temp probe:

All Components

On the input side, the relay connections are:

  • VCC to Pi Pico 3.3V/pin 36
  • GND to GND
  • input pin to GPIO 15

Relay to Pico

Everything works well as I am pursing a small thermostat project following these links:



However, after triggering the relay to turn on the fan, OR after about 10 loops of just turning the relay on / off with a delay of 5 seconds, Thonny no longer prints to the screen and can no longer connect to /dev/ttyACM0.

Here's the simple test code:

import time
from machine import Pin, I2C

from oled_runner import lcd
i2c0_sda = Pin(12)
i2c0_scl = Pin(13)
i2c0 = I2C(0, sda=i2c0_sda, scl=i2c0_scl)

from dht20 import DHT20
dht20 = DHT20(0x38, i2c0)

relay = Pin(15, Pin.OUT)


def run_relay():
    global count
    print('sleep before turn on relay')
    print('sleep before turn off  led')
def thermo_stat():
    if fahrenheit > 77:
        #If on, turn off (relay.value(0) sets GPIO high)
        if relay.value() == 1:
            print("Turning on the fan via the relay")
            print("Relay value already", relay.value())
        print("Turning off the fan via the relay")
def oled_show():
    lcd.text(f"Temp: {fahrenheit} F",0,0)
def thermometer():
    global fahrenheit
    measurements = dht20.measurements
    celcius = measurements['t']
    fahrenheit = (celcius * 1.8) + 32
    fahrenheit = round(fahrenheit, 2)
    print(f"Temp: {fahrenheit} °F, humidity: {measurements['rh']} %RH")
while True:
    #run_relay() -   toggle this on/of per testing ...

The pico continues to 'be a thermostat' if the temp goes up/down and can still turn the relay on/off, it's just Thonny can't talk to the Pico at all anymore. The Linux PC powering the USB connection can see the pico via 'lsusb'. I don't see any obvious errors in the backend.log on Thonny.

I noticed this only happens when the relay is turned on, otherwise if the temp never trips the relay Thonny/Pico still communicate.

Suggestions? It seems like a Thonny problem but it more seems like the pico becomes unresponsive on the usb once the relay is triggered.


1 Answer 1


How much current does your relay draw?

You are running the relay off the Pico 3.3V (even though it is rated at 5V and is unlikely to be reliable).

You also have other devices apparently also powered by the Pico.

The 3.3V regulator is rated at 300mA so it likely this is a power problem.

The Pico is not designed to power peripherals and the high transient current when the relay operates is likely to drop voltage causing connection to drop.

  • What path should I check to see how much current the relay draws? Do you mean from it's own VCC to it's own ground? The components should be well under 300 ma per their datasheets, and I feel like lots of other people are powering components like this, and maybe they (links above) are incorrect to do so), but you have good point worthy to track down. I suppose I could get a second breadboard and power supply to see what happens...thanks for the thought..
    – james6125
    Commented Sep 19, 2023 at 3:22
  • Frankly I would power the relay from 5V, but then I would't use a relay to run a small motor - it just seems like an unnecessary complication. You could measure relay current with a multimeter - measuring transient is another matter but this is not an EE forum.
    – Milliways
    Commented Sep 19, 2023 at 3:55
  • OK thank you - perhaps this is more of an EE problem, but one never knows. Thanks for your comments.
    – james6125
    Commented Sep 19, 2023 at 12:54
  • The problem is also that the inrush current can cause a short but very high current consumption. That can cause a short voltage drop that will cause the Pico to restart. To prevent this you could use a filter, a decoupling capacitor or its own PSU. Remember that all devices/PSU MUST share the same ground if you don't do any isolation (Thats another topic). Ref. en.wikipedia.org/wiki/Inrush_current
    – MatsK
    Commented Sep 20, 2023 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.