How to control the brightness of the LED bulb using the Raspberry Pi Pico board

How to control the brightness of the LED bulb using the Raspberry Pi Pico board

Hello and welcome back. In this tutorial, we will learn how to control LED brightness using the Raspberry Pi Pico board. For that, I used a potentiometer. Through this, we can get the analog values and use that value to control the potential given to the LED bulb. It’s simply called PWM. This process can be done without a potentiometer. But using a potentiometer we can increase or decrease the LED brightness values as we want. You can also learn how to get an analog read on a Raspberry Pi board. If you want to know how to control LED brightness using Arduino, click this link. I also used the Micropython language and the Thonny IDE for this project. If you don’t have any idea about this, please use this link.

What is PWM?

PWM is simply called Pulse Width Modulation. Through this, we can get any value between the maximum and minimum value of the potential used to operate a microcontroller. For example, through a microcontroller powered by 5v, we can get any potential from 0v to 5v. Also, through the Raspberry Pi Pico board, we can get a potential between 0v to 3.3v. If you want to know more info about PWM, Please use this link. The PWM value on the Arduino board is between 0-255 and on the Raspberry Pi Pico board, it’s between 0-65535. Also, we can use any GPIO pins on the Raspberry Pi Pico board for PWM.

What is Analog Input?

From this, we can get the potential values between 0v to 3.3v in the Raspberry Pi Pico board. Also, we can do this task simply with a potentiometer or a preset. For that, we can use the GPIO 26,27,28, and 29 pins in the Raspberry Pi board. Also, we can get these analog values between 0 to 65535.

OK, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, attach the Raspberry Pi Pico board, potentiometer, LED, and 180-ohm resistor to the breadboard.

Step 3

Thirdly, connect these components to the Raspberry Pi Pico board. For that use the circuit diagram below.

Step 4

Next, connect it to the computer. Now, let’s create the program for this project. It’s as follows.

  • Full details of this project – Download
#Include the library files
from machine import ADC, Pin,PWM
from time import sleep

led = PWM(Pin(2))#Include the LED pin
potentiometer = ADC(28)#Include the potentiometer pin
led.freq(1000)#Set the frequency

while True:
    value = potentiometer.read_u16()#Get the values
    print(value)#Print value on the shell
    led.duty_u16(value)#Turn the LED ON and OFF
    sleep(0.2)#Set the delay time

We can use the PWM class for PWM and the ADC class for analog input.

Step 5

Now, save this code on the Raspberry Pi Pico board as “main.py“.

Step 6

Finally, run this code and enjoy this project.

How to control the brightness of the LED bulb using the Raspberry Pi Pico board

Similar Posts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *