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 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 computers, alarm devices, refrigerators, microwave oven, security devices and so on. 

There are two conductors available inside the buzzer along with a piezo crystal between them. Whenever the potential is applied across the crystal then the conductor’s position gets 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 sounds. This is a very basic tutorial if you want to learn more about how the can buzzer be used in any security device then you can check my advanced 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 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. 


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 the buzzer. In this syntax, the 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. 


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

Syntax of the tone() function:


  • 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. The 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)


  •  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 pins using noTone() before using the tone() on another pin.
  • The buzzer is not able to generate a 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 that has the capability to generate different kinds of tones with very fewer efforts.


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 temperature sensor with Arduino Uno

The temperature sensor is the most popular measuring device which is capable to sense the intensity of heat generated by the object to which it is connected. These sensors are most frequently used by us through our household devices such as microwaves, refrigerators, air conditioners, and so on. In this tutorial, we will learn about LM35 (LM means linear monolithic) temperature sensor which is an integrated circuit analog temperature sensor.