Buzzer with Arduino Skip to main content

How to control RGB LED using Arduino Uno

RGB LED is the abbreviation of ‘’Red Green Blue Light Emitting Diode’’. RGB LED is the most amazing type of The LED which has the ability to create millions of different shades of light-colors using red, green and blue colors.

Buzzer with Arduino





A buzzer or piezo speaker is an audio signaling device commonly used to produce sound. Piezo buzzer produces sound based on the reverse principle of the piezoelectric effect. The buzzer is a less costly and light weighted electronic device that’s why it is used in computer, alarm device, refrigerator, microwave oven, security devices and so on. 

There are two conductors available inside the buzzer along with piezo crystal between them. Whenever the potential is applied across the crystal than the conductor’s position get changed due to which 2 to 4 kHz sound wave produced by the buzzer.

In this article, I will explain to you how a buzzer can be operated with the help of Arduino Uno in a different manner to generate different toned sound. This is a very basic tutorial if you want to learn more like how can buzzer used in any security device then you can check my advance level project named Locker guard based on Arduino Uno.


Required components:

  • 1 x Buzzer...........................................BUY
  • 1 x Arduino Uno.................................BUY
  • 1 x Breadboard....................................BUY
  • Few jumper wires................................BUY

Connection diagram: 



Circuit description:


A buzzer is a two terminal (one is longer and another one is shorter) device. The longer leg is used to provide the input and the shorter leg is used to provide the ground connection. According to the circuit diagram, I have connected the pin 7 of Arduino with the longer leg of the buzzer. The shorter leg of the buzzer is connected with the GND terminal of the Arduino Uno. 


Code:

Here I am sharing three codes along with their output video which will help you to understand the working of the code in an efficient manner.

Code-1: Example Code

In this first example, I used “digitalwrite(pin, value)” command to operate buzzer. In this syntax, pin indicates the pin number and the value indicates the LOW or HIGH. To turn on the buzzer HIGH value is used and on the other side to turn off the buzzer LOW value is preferred in the command. 

Code-2:

In this example, I used tone() function to operate buzzer. There are two types of the syntax used for tone() function.

Syntax of the tone() function:

     Parameters:

  • pin = pin number which is used to generate a tone.
  • Frequency = frequency of the tone in hertz (unsigned integer can take values up to 65,535 but we will use values between 2000 and 5000 to make tone hearable for human ears).
  • Duration = the time limit of tone in the millisecond.

I used different values to generate different tones. tone() function used to generate a square wave of the specified frequency. Duration of the tone can be specified with the frequency of the tone. If the duration is mentioned along with the tone() function then the tone will be generated only for the specified duration. If the duration is not mentioned in the tone() function then the noTone() function is needed to stop the tone.


Syntax of the noTone() function:

  • noTone(pin)

Parameter: 

  •  pin = pin on which tone generation should get stopped.

Limitation of Tone() function:

  • If you are using analogWrite() on pin 3 or 11 then you cannot use tone() because tone() uses the same built-in timer for pin 3 and 11 as analogWrite(). If you will use them together then you will find an unexpected tone as output.
  • If you are using two buzzers on different pins then you can’t play both of them at the same time. You need to turn off the tone on any one of the pin using noTone() before using the tone() on another pin.
  • The buzzer is not able to generate tone below 31 HZ.

Output video:


Here I am attaching the output video for all codes which will help you to understand the working of the codes.






The tone function can also be used to generate piano notes of any song with the help of additional pitches.h file. Hence buzzer is a small, efficient, less costly, less bulky device which has the capability to generate different kind of tones with very fewer efforts.


Comments

Post a Comment

Popular posts from this blog

Smart Plant Watering System Using ARDUINO UNO

As we all know, plants play an important role in our life, there are countless benefits we get from plants but the most important is fresh air and the pleasant atmosphere on the earth. Hence,   It is not only our social duty as well as the responsibility that we should plant trees as much as we can and also take care of them. But  the biggest challenge we face, is, taking care of them,

How to use LCD with Arduino Uno

Liquid crystal Display 16x2 (LCD) is the widely used electronic device to establish communication between the real world and electronics based machine world.

How to operate soil moisture sensor with Arduino

The soil moisture sensor is the most amazing sensor used to measure the quantity of water present in the soil and defines the moisture level of the soil as the output. Because of its amazing operating principle this sensor used in application such as automatic irrigation system, agriculture research applications, landscape irrigation, indoor planting system, and lawns. I have also made an advance level project  "Smart Plant Watering System" using a soil moisture sensor.

ad

ad