In this project, you’ll learn how to programme a Raspberry Pi Pico using MicroPython by connecting it to another computer.

A Raspberry Pi Pico is a microcontroller with a low price tag. Microcontrollers are little computers, but they lack huge amounts of storage and auxiliary devices to which they can be connected (for example, keyboards or monitors).

Control an LED with an analogue input

Your Raspberry Pi Pico has input pins that can receive analogue signals. This means that instead of only reading the values of 1 and 0 (on and off), it can read values in between.

A potentiometer is the perfect analogue device for this activity

Schematic Diagram

A potentiometer can be used in place of the button in your circuit. Connect it to an analogue pin using the wiring schematic below.


from machine import ADC, Pin
import time
adc = ADC(Pin(26))
while True:
from machine import Pin, PWM, ADC
pwm = PWM(Pin(15))
adc = ADC(Pin(26))
while True:
	duty = adc.read_u16()
  • To observe your maximum and minimum values, turn the potentiometer.
  • They should be in the range of 0 to 65025.
  • This parameter can now be used to modify the duty cycle of the LED’s PWM.
  • Make the following changes to the code. After you’ve ran it, adjust the brightness of the LED using the potentiometer’s dial.