0% found this document useful (0 votes)
36 views7 pages

Beginner Projects For Raspberry Pi Pico - 6 Steps - Instructables

The document outlines beginner projects for the Raspberry Pi Pico using MicroPython, including LED control, temperature measurement, a thief alarm, a weather monitor, and a distance sensor. Each project includes a list of required hardware, circuit diagrams, and code examples to help users implement the projects. The guide aims to provide a hands-on approach to learning programming and electronics with the Raspberry Pi Pico.

Uploaded by

pete555
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views7 pages

Beginner Projects For Raspberry Pi Pico - 6 Steps - Instructables

The document outlines beginner projects for the Raspberry Pi Pico using MicroPython, including LED control, temperature measurement, a thief alarm, a weather monitor, and a distance sensor. Each project includes a list of required hardware, circuit diagrams, and code examples to help users implement the projects. The guide aims to provide a hands-on approach to learning programming and electronics with the Raspberry Pi Pico.

Uploaded by

pete555
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

17/01/2025, 12:17 Beginner Projects for Raspberry Pi Pico : 6 Steps - Instructables

Beginner Projects for Raspberry Pi Pico


By robotistan in CircuitsRaspberry Pi

Introduction: Beginner Projects for Raspberry Pi Pico

Hi friends! In this content, we will try to use Raspberry Pi Pico using Micropython programming language. Let's explore together how we can code
Pico with a few simple projects.

https://www.instructables.com/Beginner-Projects-for-Raspberry-Pi-Pico/ 1/7
17/01/2025, 12:17 Beginner Projects for Raspberry Pi Pico : 6 Steps - Instructables

Supplies

There is a manual book where we describe how you can use Pico. You can find this manual in the pdf file above.

Also you can visit our Maker Blog to see detailed contents.

MicroPython and Pico - Robotistan Blog

Step 1: Getting Required Hardware

We will use Robotistan made Raspberry Pi Pico Mega Kit in the projects we will describe. Pico Mega Kit, which comes with 34 different components,
was created to implement projects quickly.

There are many important components in the kit, from smart sensors to IoT modules.

To get the kit: Raspberry Pi Pico Mega Kit

https://www.instructables.com/Beginner-Projects-for-Raspberry-Pi-Pico/ 2/7
17/01/2025, 12:17 Beginner Projects for Raspberry Pi Pico : 6 Steps - Instructables

Step 2: LED Control With Button

(1) The 38th pin on your Pico's pin diagram is "GND," the ground pin, while the 36th pin is the "3V3 (OUT)" pin. These two pins will appear frequently
in your projects. To begin, construct the circuit on the breadboard as shown in the picture above.

(2) Then open your Thonny IDE and make changes to the "blink" code you created in the previous project. Double-click the "blink.py" file on the left
side of Thonny IDE to open it. You'll be able to see the codes you wrote in the prior project. Now you'll fully remove these codes and replace them with
fresh ones.

(3) You specified the hardware of Pi-co using the code "from machine import Pin" as in the previous project and included the "time" library when you
looked at the code below.

You designated the 15 numbered pin as the pin you linked to the LED using the code "led = Pin (15, Pin.OUT)". The code "button = Pin (14, Pin.IN,
Pin.PULL DOWN)" specifies the pin number 14 as the input pin to which the button is connected.

After that, you made a "while loop." It will alter the state of the led in this cycle based on the value read from the button. If you push the button once
when the LED is off, it will turn on; if you press the button while the LED is on, it will turn off.

The LED will flash and flash at half-second intervals when you push and hold the button with the code "time.sleep (0.5)".
from machine import Pin
import time

led = Pin(15, Pin.OUT)


button = Pin(14, Pin.IN, Pin.PULL_DOWN)

while True:
if button.value():
led.toggle()
time.sleep(0.5)

After you've finished creating the codes, hit the "Run" icon at the top to save and run them on your Pico. By pressing the button, you will be able to
switch the LED on and off. Now it's time to move on to the next endeavor.

https://www.instructables.com/Beginner-Projects-for-Raspberry-Pi-Pico/ 3/7
17/01/2025, 12:17 Beginner Projects for Raspberry Pi Pico : 6 Steps - Instructables

Step 3: Temperature Measurement With Pico

The Raspberry Pi Pico includes an inbuilt temperature sensor, as I explained at the start of this post. Then let's all learn how to utilize this temperature
sensor together.

To begin, use the Thonny IDE and create a new file in which to write the following programs.
#We provided access to hardware on Raspberry Pi Pico
import machine
import utime

#We have defined the pin to which the temperature sensor is connected
sensor_temp = machine.ADC(4)

#Since we are making analog readings, we have converted the 16-bit data from the sensor into voltage data that may be meaningful to us with the "conve
conversion_factor = 3.3 / (65535)

while True:
#Temperature reading
reading = sensor_temp.read_u16() * conversion_factor
temp = 27 - (reading - 0.706)/0.001721
print(temp)
utime.sleep(2)

Now we'll save and execute these programs on our Pico. We can see the temperature data from our Pico every 2 seconds in the Shell window at the
bottom when the programs start to execute.

https://www.instructables.com/Beginner-Projects-for-Raspberry-Pi-Pico/ 4/7
17/01/2025, 12:17 Beginner Projects for Raspberry Pi Pico : 6 Steps - Instructables

Step 4: Thief Alarm With Raspberry Pi Pico

So far, we've completed a project using the Pico's LED and temperature sensor. Isn't it about time you switched to the breadboard and started making
circuits using jumpers? Then take your breadboards and join me in making a "Thief Alarm."

Let's begin by constructing our circuit according to the schematic above. Then, in Thonny IDE, create a new file and write the following code.
import machine
import utime

#We have defined the pin to which the PIR sensor is connected.
sensor_pir = machine.Pin(28, machine.Pin.IN, machine.Pin.PULL_DOWN)

#We have defined the pin where the LED is defined


led = machine.Pin(15, machine.Pin.OUT)

#We have defined the pin where the buzzer is defined


buzzer = machine.Pin(14, machine.Pin.OUT)

def pir_handler(pin):
utime.sleep_ms(100)
if pin.value():
print("ATTENTION! Motion Detected!")
for i in range(50):
led.toggle()
buzzer.toggle()
utime.sleep_ms(100)
sensor_pir.irq(trigger=machine.Pin.IRQ_RISING, handler=pir_handler)

while True:
led.toggle()
utime.sleep(5)

Now we'll save and execute these programs on our Pico. The buzzer will now play and our LED will light up whenever a condition activates our motion
sensor. When motion is detected, the word "ATTENTION! Motion Detected!" appears at the bottom of the Shell window.

https://www.instructables.com/Beginner-Projects-for-Raspberry-Pi-Pico/ 5/7
17/01/2025, 12:17 Beginner Projects for Raspberry Pi Pico : 6 Steps - Instructables

Step 5: Weather Monitor

(1) You will create a weather monitor with a 2X16 LCD screen in this project. In this project, you'll learn how to install a library and record the
temperature data you collect in a text file automatically.

(2) To begin, construct your own circuit on the breadboard based on the design above. Now go to this library and get the appropriate library to use our
LCD screen. To get the library, open the URL and click the green "Code" button. Then click the "Download ZIP" button.

Open the downloaded “* .zip” file and extract the “lcd_api.py“, “pico_i2c_lcd.py“, “pico_i2c_lcd_test.py” files to the desktop.

Open them in Thonny IDE by double clicking on these files that you extract to the desktop. Now save these files to the “lib” folder in your Pico in order,
click on the “Files” tab on the top and then click on “Save as …“.

(3) It asks where you want to save the library file. You will choose the Raspberry Pi Pico. In this part, you have to choose the location where you want
to save the file, then type the file name first. After that double click on the “lib” folder. Then click the “OK” button to save it to the folder.

(4) Now that you have added libraries, you can open a new file by clicking the “Plus” icon on the top of a new Thonny IDE and write the following
codes. When you examine the codes, first add the libraries as in other projects, then make the settings of our 2X16 LCD screen and create a new text
document named “save” with the code “file = open (” record.txt “,” w “)“.
import utime
import machine
from machine import I2C
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd

I2C_ADDR = 0x27
I2C_NUM_ROWS = 2
I2C_NUM_COLS = 16

i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)


lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)

dosya = open("kayit.txt", "w")

sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / (65535)

while True:
lcd.clear()
reading = sensor_temp.read_u16() * conversion_factor
temp = 27 - (reading - 0.706)/0.001721
lcd.putstr("Temp: ")
lcd.move_to(0,1)
lcd.putstr(str(temp))
dosya.write(str(temp) + "\n")
dosya.flush()
utime.sleep(2)

(5) Now save these codes to your Pico and run them, then press the “Run” icon at the top.

(6) It asks where you want to save the code. For the code to always run, you need to click on the “Raspberry Pi Pico” option and save it to our Pico.
Type “havadurumu.py” as the file name and click the “OK” button. Now, you will be able to see the temperature data on your LCD screen and at the
same time this data will be recorded in a text document.

(7) Now wait for some data to collect, then click the “Stop” icon at the top to stop the code from running. Write the following codes in the Shell section
at the bottom so that you can see the data have been saved.
file = open("kayit.txt")
print(file.read())
file.close()

(8) After typing the “print (file.read ())” code, you can see the saved data as in the photo below.

https://www.instructables.com/Beginner-Projects-for-Raspberry-Pi-Pico/ 6/7
17/01/2025, 12:17 Beginner Projects for Raspberry Pi Pico : 6 Steps - Instructables

Step 6: Using of Distance Sensor

To begin, draw your circuit on the breadboard as shown in the picture.

Now, in Thonny IDE, create a new file and write your code. When looking at the codes, you'll see that the first two lines describe the libraries, as well
as the pins to which the distance sensor is linked. The function "def echoTime ():" was also used to write the distance measuring function. You've set
the distance measuring function to run every 5 seconds, as stated by the while loop.
from machine import Pin
import utime

trigger = Pin(18, Pin.OUT)


echo = Pin(21, Pin.IN)

def echoTime():
trigger.value(0)
utime.sleep_us(5)
trigger.value(1)
utime.sleep_us(10)
trigger.value(0)
try:
echoTime = machine.time_pulse_us(echo, 1, 1000000)
cm = (echoTime * 0.034321) * 0.5

print(str(cm)+" cm")
except OSError as e:
print(e)

while True:
echoTime()
utime.sleep(5)

Save and execute these scripts on your Pico by pressing the "Run" icon at the top.

It asks where you want to save the code. For the code to always run, you need to click on the “Raspberry Pi Pico” option and save it to our Pico.

Write “distance.py” as the file name and click the “OK” button.

You can now see the distance in the Shell section of the Thonny IDE.

https://www.instructables.com/Beginner-Projects-for-Raspberry-Pi-Pico/ 7/7

You might also like