yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
Pico Robot Car📖
0.Introduction
  • 0.1 Description of Pico Robot
  • 0.2 Interface Description
1.Assembly steps
  • Assembly video
2.Development environment construction
  • 2.1 Update firmware
  • 2.2 Build environment
  • 2.3 Download code Startup automatically
  • 2.4 Import library file
3.Basic course
  • 3.1 Control LED light
  • 3.2 Onboard temperature sensor
  • 3.3 Passive buzzer
  • 3.4 Breathing light
  • 3.5 Marquee light
  • 3.6 OLED display
  • 3.7 Battery power display
  • 3.8 Servo control
4.Advanced course
  • 4.1 Light sensor
  • 4.2 Sound sensor
  • 4.3 Tracking sensor
  • 4.4 Ultrasonic sensor
  • 4.5 IR control display
5.Robot course
  • 5.1 Car forward
  • 5.2 Car movement
  • 5.3 Singing dancing
  • 5.4 Car tracking
  • 5.5 Edge detection
  • 5.6 Ultrasonic avoiding
  • 5.7 Ultrasounic following
  • 5.8 Light follow
  • 5.9 Voice control car
  • 5.10 Infrared control
  • 5.11 Bluetooth control
6.Battery and charge
  • Battery and charge
Download
  • APP(iOS/Android)
  • Code
  • Instructions Manual
  • Appendix
Download ZIP

Welcome to Pico Robot Car repository

3.3 Passive buzzer

3.3 Passive buzzer

1. Learning objectives

  1. Learn to combine the Raspberry Pi Pico 2/Pico mainboard and the car expansion board passive buzzer for experiments.
  2. Understand the use of active buzzers.

2. Hardware usage

This course uses Pico 2/Pico mainboard and the car board passive buzzer

image-20220209095936443

Passive buzzers use electromagnetic induction to attract or repel the permanent magnet formed by the voice coil after the alternating current is connected to the voice coil, and the diaphragm is pushed to make sound. When connected to direct current, it can only continuously push the diaphragm but cannot produce sound. In control, we generally use PWM to control the passive buzzer to make sound.

3. Program Analysis

Code path: Code -> 1.Basic course -> 3. Passive buzzer.py

from machine import Pin, PWM
import time
# set buzzer pin
BZ = PWM(Pin(22))
BZ.freq(1000)
# Initialize music
CM = [0, 330, 350, 393, 441, 495, 556, 624] 
song = [CM[1],CM[1],CM[5],CM[5],CM[6],CM[6],CM[5],CM[4],CM[4],CM[3],CM[3],CM[2],CM[2],CM[1],]
beat = [ 0.5,0.5,0.5,0.5,0.5,0.5,1,0.5,0.5,0.5,0.5,0.5,0.5,1,]
# music   
def music():
        print('Playing song ...')
        for i in range(len(song)):
            BZ.duty_u16(500)
            BZ.freq(song[i])
            time.sleep(beat[i]) 
            BZ.duty_u16(0)
            time.sleep(0.01) 
# play music   
music()
print("Ending")

from machine import Pin, PWM

The machine library contains all the instructions MicroPython needs to communicate with Pico and other MicroPython-compatible devices, extending the language of physical computing. Only the Pin and PWM libraries are used here.

import time

The "time" library. This library handles everything related to time, from measuring it to inserting delays into the program. The unit is seconds.

BZ = PWM(Pin(22))

Set IO22 to the PWM output pin for controlling the buzzer.

BZ.freq(1000)

Set the PWM frequency to 1000.

BZ.duty_u16(0)

Turn off the sound when the value is 0, and turn on the sound when it is 500.

music()

By calling the music() function, a for loop is used in the function to play the pre-written sounds of different frequencies one by one, so as to achieve music playback.

4. Experimental Phenomenon

After the program is downloaded, we can hear the buzzer playing the music Little Star, and after the playback, the Shell displays Ending.

Onboard temperature sensor
Breathing light

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文