Project 07: Flowing Water Light

  1. Introduction

In our daily life, we can see many billboards made up of different colors of LED. They constantly change the light to attract the attention of customers. In this project, we will use Raspberry Pi Pico to control 10 LEDs to achieve the effect of flowing water.

  1. Components Required

Raspberry Pi Pico*1

Raspberry Pi Pico Expansion Board*1

Red LED*10
220ΩResistor*10 Breadboard*1 Jumper Wires USB Cable*1
  1. Circuit Diagram and Wiring Diagram

Img

Note:

How to connect the LED.

How to identify the 220Ω 5-band resistor.

  1. Test Code

This project is to design and manufacture a flowing water light.  Here are the steps: first , turn on LED #1, then turn it off.  Second, turn on LED #2, then turn off… . Do the same for the 10 LEDs until the last one is turned off. Repeating the process to achieve the “movement” of the water.

The code used in this tutorial is saved in the file …\Python_Codes. You can move the code to anywhere,for example,we can save the Python_Codes file in the Disk(D), the route is D:\Python_Codes.

Open“Thonny”, click“This computer”→“D:”→“Python_Codes”→“Project 07:Flowing Water Light”. And double left-click the“Project_07_Flowing_Water_Light.py”.

from machine import Pin
import time
#Use an array to define 10 GPIO ports connected to LED Bar Graph for easier operation.
pins = [16, 17, 18, 19, 20, 21, 22, 26, 27, 28]
#Use two for loops to turn on LEDs separately from left to right and then back from right to left
def showLed():
for pin in pins:
print(pin)
led = Pin(pin, Pin.OUT)
led.value(1)
time.sleep_ms(100)
led.value(0)
time.sleep_ms(100)
for pin in reversed(pins):
print(pin)
led = Pin(pin, Pin.OUT)
led.value(1)
time.sleep_ms(100)
led.value(0)
time.sleep_ms(100)
while True:
showLed()
  1. Test Result

Ensure that the Raspberry Pi Pico is connected to the computer,click“Stop/Restart backend”.

Click “Run current script”, the code starts executing, we will see that the 10 LEDs will light up from left to right and then return from right to left. Press“Ctrl+C”or click“Stop/Restart backend”to exit the program.

Img