• Support
  • Cart
Phinalabs Phinalabs
  • Shop
    • STEM Education
    • Makers
    • Components
    • Tools
  • Lab
    • Fabrication
    • Projects
    • Open Source
  • Education
    • Create.Innovate.Invent
    • Resources & Kits
  • Learn
    • STEM
      • Basics
      • Coding
      • Kits
      • DIY
    • Explore
      • Basic Electronics
      • Microcontrollers
      • Displays
      • Modules
      • Actuators
      • Sensors
    • Industrial & IoT
    • Embedded Systems
      • Embedded C
      • Embedded OS
      • Micropython
      • PCB Making
  • Blog
  • Register
  • Login|
LoginRegister
­
Learn/Explore/Piezo Buzzer

Close

Piezo Buzzer

By Dennis

Share this project

Introduction

This tutorial shows how to hook up a piezo buzzer and an Arduino Uno board to make a simple sound alarm whose volume can be adjusted . The buzzer is operating at low current therefore it can be interfaced directly to the Arduino board.

Parts used

  1. arduino uno rev3
  2. buzzer module
  3. breadboard
  4. jumper wires

Breadboard layout

Arduino piezzo connections

the negative lead (black wire) is connected to the arduino’s gnd pin while the positive lead (red wire)is connected to the arduino’s digital pin 9.

Wiring

Code

Arduino:Piezo Buzzer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//setup
void setup()
{
  //set pin 9 as an output
  pinMode(9, OUTPUT);
  //beep 3 times each with a duration of 50 milliseconds
  beep(50);
  beep(50);
  beep(50);
  //wait for a second
  delay(1000);
}
 
//loop
void loop()
{
  //beep for a duration of 200 milliseconds
  beep (200);
  //call the beep function and pass a parameter to it
}
//the beep function
void beep(unsigned char delayms)
{
  analogWrite(9, 20);//he two values are pin number and value to write to it(0-255)
  delay(delayms);//this value was passed from the main loop
  analogWrite(9, 0);
  delay(delayms);
}

To test if the buzzer is working you can use the simple blink sketch on pin 9. With a delay of one second the buzzer  will beep for every one second in an infinite loop.You can use the analog write function  to change the intensity of the beep too.

How the code works

sets digital pin 9 an output

1
pinMode(9, OUTPUT);

beep for 50 milliseconds

1
beep(50);

beep for 50 milliseconds

1
beep(50);

beep for 50 milliseconds

1
beep(50);

delay for 1 second before going into the main loop

1
delay(1000);

 

this code snippet  beeps 3 times at startup and then beeps continuously at a slower rate

1
2
3
4
5
void beep(unsigned char delayms)
{
    analogWrite(9,20);
    delay(delayms);
    ....

we have created the function beep() which will send the pwm signal to the buzzer waits for a small delay and then turns it off for another small delay

1
beep (200);

the delay is passed as a parameter when calling the beep() function

Running the Code

Applications

this tutorial can be integrated into other projects to provide audio feedback .

Share this post

Like this project

Tags

accelerometer Arduino breadboard buzzer color sensor digital input jumper jumpers jumper wires kit learn led LED blinking PIR programming prototyping resistors scratch-n-sketch Scratch_n_Sketch sensors tcs3200 touch

Feedback

You must be logged in to leave feedback.


Related Projects

  • thumbnail_unda_project_1

    UNDA Project 1: Flashing Light


    By Mercy Ngoiri

    [fullwidth background_color="" background_image="" background_parallax="none" enable_mobile="no" parallax_speed="0.3" background_repeat="no-repeat"...

  • 3D_rotate

    MMA7361LC 3-Axis Accelerometer


    By Muchiri John

    This Module is a 3-axis Xyz accelerometer using Freescale MMA7361L micromachined ±1.5g or ±6g sensitivity. It's great for a motion sensing or stab...

  • tcs3200_cl_02

    Color Sensor TCS3200


    By Muchiri John

    This module is based on TCS3200 programmable color light-to-frequency converters that combine configurable silicon photodiodes and a current-to-fre...

  • pir_motion_02

    PIR Motion Sensor


    By Muchiri John

    A PIR motion sensor, is a small, low power and inexpensive sensor that is used to sense objects emitting low level radiation e.g humans, cats, dogs...

  • touch_sensor

    Touch Sensor


    By Dennis

    If you are interested in adding the ‘magic’ of touch to control your electronics project, a capacitive touch sensor module might be the way to go. ...

  • Arduino_Logo

    Arduino : Getting Started


    By Mercy Ngoiri

    In this lesson we will learn how to set up the computer to get started with Arduino, that is, downloading and installing the software and then open...

  • Arduino_Logo

    Arduino : Introduction


    By Muchiri John

    Arduino is an open-source prototyping platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sens...

Sections

  • Introduction
  • Parts used
  • Breadboard layout
  • Code
  • How the code works
  • Running the Code
  • Applications
Paginate View
Feedback

Make Yours

  • PHA007_a

    3.75mm 8×8 LED Dot Matrix Display

    Ksh. 150
    This is a single colour very bright (ultra red) 8x8…
    Add to cartLearn More
  • PHA002_a

    3mm 8×8 Dot Matrix Display

    Ksh. 100
    This is a single colour very bright (ultra red) 8x8…
    Add to cartLearn More
Get Updates

Customer Service

  • Contact Page
  • Support
  • Distributors
  • FAQ Page

Terms of Use

  • Shipping & Returns
  • Terms of Service

About Us

:: Phinalabs designs and manufactures electronics and provides a platform - tools, resources, and content for our partners and community of makers, DIYers, engineers, students, innovators, and inventors to build, learn, connect, inspire, and turn ideas into reality.

"Nothing in life is to be feared, it is only to be understood."
Marie Curie