Posts: 1
Joined: Sun Jun 04, 2023 9:17 am

Pin gets activated to easily

Sun Jun 04, 2023 9:55 am

I bought a new raspberry pi pico and wanted to build my first circuit. It should only need a simple button which turns on the picos LED.

Code: Select all

from machine import Pin
import utime

led = Pin("LED", Pin.OUT)
button = Pin(15, Pin.IN)

while True:
    if button.value()==1:
This is the code, but when I run this, any metal object or even my finger is able to activate it when touching it(not only the ones that are also connected to it with 3V3 pin). This is really problematic, because when I connect the pin with a cable, the LED starts blinking.
I guess I have misunderstood something, but I thought that the Pin only gets activated when 3V flows through them and the 3V3 provides the pin with these 3V. I only have to close and open the circuit with a button to send multiple signals.
What would I have to do to make the LED toggle when a button is pressed?

User avatar
Posts: 2584
Joined: Fri Aug 10, 2012 12:38 pm
Location: Cumbria, UK

Re: Pin gets activated to easily

Sun Jun 04, 2023 2:17 pm

You should pull the input down assuming your button is connected between pin 15 and 3.3V so that it is not floating:

Code: Select all

button = Pin(15, Pin.IN, Pin.PULL_DOWN)

Posts: 13702
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Pin gets activated to easily

Sun Jun 04, 2023 2:19 pm

That's because when you input pin is not connected to 3.3V it is floating and can easily be influenced but local electrical fields.

Have a read of this it was written for the raspberry pi not the pico but the theory is still relevant and so is using external resistors to fix the problem.

https://github.com/raspberrypilearning/ ... up_down.md
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “MicroPython”