Building the foundational knowledge in order to successfully complete one (or all) of these examples takes time. This is where an inventor’s kit will come in handy. Everything, such as an instruction booklet, components, and required wires is included, so you can create experiments that will expand your knowledge and skills to automate anything your heart desires.
Preparation
The Thonny IDE (integrated development environment) is a great tool to help connect your Raspberry Pi Pico to your computer and program the Pico. To ensure that you’re all set up correctly, be sure to check out our guide on getting started with Thonny on the Raspberry Pi Pico for details.
The Kitronik Inventor’s Kit comes with everything you need to complete this light experiment. If you are an electronic enthusiast with spare parts lying around, you may have what you need already:
Raspberry Pi Pico (or Pico W) Breadboard Rotary potentiometer 2x Push switch Red 5mm LED 8x M/M jumper wires 220 ohm resistor (marked with colored bands: red, red, brown, gold)
Did your Pico come with pre-soldered GPIO pins? If not, find out how to solder header pins to your Raspberry Pi Pico the right way.
Expected Output
This experiment provides a great visual representation to help explain what happens during an interrupt routine (pushing a button), at which point a pulse-width modulation (PWM) output determines the brightness of an LED—which can be controlled by using the potentiometer as an analog input.
A software interrupt will be detected when you push the button sitting on the breadboard. This action will trigger a variable that will control when the red LED light turns on or off. When you twist the potentiometer in either direction, its analog input value is transferred to the PWM output for the LED. This is the magic (if you will) behind the LED light becoming either dimmer or brighter.
Assembling Project Code
Before you continue forward, grab a copy of the code required for this experiment from the official Kitronik support site directly. As well, this resource acts as a supportive guide if you get stuck along the way.
While you have the code on the screen, let’s break down some key points in the code:
The on/off switch is mapped to GP15 on the Raspberry Pi Pico. The LED light is set up as a PWM output on GP16 on the Pico. The potentiometer (pot) relies on GP26’s built-in analog-to-digital converter (ADC). The button state defaults to false when you first run the Python program. The IRQ handler (or interrupt signal) is linked to the switch input. The while loop detects whether the switch is pressed and then proceeds to read the pot value (depending on which way you twist the potentiometer) to set the LED brightness.
This Inventor’s Kit aims to build upon the learning that you acquire as you progress through the included booklet. With each page turn, you’ll find yourself gaining knowledge incrementally. You may also find yourself smirking with pride as the “light bulb” moments increase in frequency as your experience grows.
If you want to step back to the basics of light sensors and analog inputs, head over to our getting started with Raspberry Pi Pico electronics guide for details regarding the previous light experiment in this series.
Your Future Is Bright
These kits are great for those experimenting with electronics up to an intermediate level. Now that you’ve learned some additional fundamentals around analog inputs, interrupt signals, and controlling the brightness of an LED light, you may be ready to take your knowledge to the next level.
Using a transistor to drive a motor, building upon the recent potentiometer experiment by adding a servo, setting the tone of a buzzer, counting using displays, understanding the basics of wind power, and more.
Pick up a kit that includes a booklet and all the gizmos and wires that you need to get started. Better yet, buy one for you and for someone else you know who enjoys tinkering with electronics and technology too.
Most importantly, take time to enjoy the process of building knowledge. As well, be sure to pause for pride when you find yourself completing experiments that end with a declaration such as, “I did it!”