How to make an LED chaser using Raspberry Pi Pico board

Hello and welcome back. In this tutorial, we will learn how to make an LED chaser using a Raspberry Pi Pico board. For that, I used eight LEDs and six patterns. You can change them as you like. Also, we created an LED chaser using Arduino in a previous project, but today we will use the Raspberry Pi Pico board. For that, I used python language and Thonny IDE. If you don’t have any knowledge of this IDE and python language, use this link for more info. OK, let’s go ahead.

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

Step 1

Firstly, identify these components.

Step 2

Secondly, connect the Raspberry Pi Pico board to the breadboard.

Step 3

Thirdly, attach the LEDs and resistors to the breadboard. You can arrange it as you like.

Step 4

Now, connect the LEDs to the Raspberry Pi Pico board using the jumper wires. For that, use the circuit diagram below. If you want, you can create a PCB for this project. But I used a breadboard.

Step 5

After that, connect it to the computer or Raspberry Pi board. Then, upload the program. It is as follows.

  • Full details of this project – Download
#Import the library files
from  machine import Pin
import time

#Pattern one
def patternOne(times):
    for a in range (0,times):
        for i in range(0,8):
            Pin(i,Pin.OUT).value(1)
            time.sleep(0.1)
            Pin(i,Pin.OUT).value(0)          

#Pattern two
def patternTwo(times):
    for a in range(0,times):
        for i in range(0,7):
            Pin(i,Pin.OUT).value(1)
            time.sleep(0.1)
            Pin(i,Pin.OUT).value(0)
            
        for x in range(7,0,-1):
            Pin(x,Pin.OUT).value(1)
            time.sleep(0.1)
            Pin(x,Pin.OUT).value(0)

#Pattern three
def patternThree(times):
    for a in range(0,times):
        for i in range(0,7):
            Pin(i,Pin.OUT).value(0)
            time.sleep(0.1)
            Pin(i,Pin.OUT).value(1)
            
        for x in range(7,0,-1):
            Pin(x,Pin.OUT).value(0)
            time.sleep(0.1)
            Pin(x,Pin.OUT).value(1)

#Pattern four
def patternFour(times):
    for a in range(0,times):
        for i in range(0,8):
            Pin(i,Pin.OUT).value(1)
            time.sleep(0.1)       
            
        for x in range(7,0,-1):
            Pin(x,Pin.OUT).value(0)
            time.sleep(0.1)       

#Pattern five
def patternFive(times):
    for a in range(0,times):
        for i in range(0,7):
            Pin(i,Pin.OUT).value(0)
            time.sleep(0.1)       
            
        for x in range(8,-1,-1):
            Pin(x,Pin.OUT).value(1)
            time.sleep(0.1)

#Pattern six
def patternSix(times):
    for a in range(0,times):
        for i in range(0,7):
            Pin(i,Pin.OUT).value(1)
            Pin(i+1,Pin.OUT).value(1)
            time.sleep(0.1)
            Pin(i,Pin.OUT).value(0)
            Pin(i+1,Pin.OUT).value(0)
            
        for x in range(7,0,-1):
            Pin(x,Pin.OUT).value(1)
            Pin(x-1,Pin.OUT).value(1)
            time.sleep(0.1)
            Pin(x,Pin.OUT).value(0)
            Pin(x-1,Pin.OUT).value(0)

#Call the functions
while True:           
    patternOne(3)
    patternTwo(3)
    patternThree(3)
    patternFour(3)
    patternFive(3)
    patternSix(3)

This program includes six functions and these functions are called in the “while loop” below. Also, all these functions are created using “for loop”.

Step 6

Next, save it on your computer or Raspberry Pi Pico board. I saved it on the Raspberry Pi Pico board. Therefore, we can use it without a computer. But you must remember to save it as “main.py”.

Step 7

Finally, run this code using the Run button. Now, you can use this project without a computer.

Ok, enjoy this project. The full video guide is below. So, see you in the next project.

How to make an LED chaser using Raspberry Pi Pico board

Similar Posts

Leave a Reply

Your email address will not be published.