Arduino Nano 33 IoT - Buzzer

In this lesson, we’ll learn how to use the Arduino Nano 33 IoT to control a 12V active buzzer that makes a loud noise. If you need to control a 5V active or passive buzzer, please check out this Arduino Nano 33 IoT Piezo Buzzer tutorial.

There are two ways to drive the 12V buzzer. A relay is simple, but it clicks every time it switches. A MOSFET module does the same job with no sound, and it can switch very fast. This is good for alarm beeps. We will try both ways in this tutorial.

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×Relay
1×Alternatively, MOSFET Module (AOD4184, LR7843 or FR120N)
1×12V Active Buzzer
1×12V Power Adapter
1×Optionally, DC Power Jack
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of 12V Active Buzzer

The 12V active buzzer makes a loud noise, which makes it great for alarm systems.

Pinout

Arduino Nano 33 IoT 12V Active Buzzer Pinout

A 12-volt active buzzer normally comes with two pins.

  • Negative (-) pin (black): Connect this to the ground (GND) of your DC power supply.
  • Positive (+) pin (red): Connect this to the 12V output of your DC power supply.

How to Control 12V Active Buzzer

If you connect a 12V active buzzer to a 12V power supply, it will produce sound. To make the buzzer work with an Arduino Nano 33 IoT, you need to connect a relay between them. The Arduino Nano 33 IoT can control the buzzer through the relay. If you are not sure about what a relay is, how its pins work, or how to program it, check out the Arduino Nano 33 IoT - Relay tutotial.

The MOSFET module is the second choice. The pins, the inside and the code of the module are explained in the Arduino Nano 33 IoT - MOSFET Module tutorial.

Relay vs MOSFET Module for a 12V Buzzer

Relay MOSFET Module
What it can do turn the buzzer on or off turn the buzzer on or off
Noise when switching a click every time, mixed with the beep no sound, you hear only the beep
How fast it switches slow, a few milliseconds very fast
Fast beeps the relay clicks loudly and wears out fast no problem
Life the contacts wear out after many switches nothing moves, so it lasts long
Type of power AC or DC DC only
Buzzer power supply any voltage the relay is rated for about 6V or more
Isolation from the Arduino yes, between coil and contacts yes, by the PC817 optocoupler
Good for slow ON/OFF, like ON for a few seconds alarm patterns with many short beeps

If the buzzer beeps slowly, the relay is fine. If you want an alarm with many short beeps, the MOSFET module is the better pick.

Wiring Diagram

The wiring diagram between Arduino Nano and 33 IoT 12V Active Buzzer

This image is created using Fritzing. Click to enlarge image

No breadboard? The same circuit can be wired without one, as shown below:

The wiring diagram between Arduino Nano and 33 IoT 12V Active Buzzer  (No Breadboard)

This image is created using Fritzing. Click to enlarge image

Pushing jumper wires into the headers is quick, but the wires can slip out. Simply plug the Arduino Nano 33 IoT into a Screw Terminal Expansion Board for Arduino Nano. The diagram below shows the same wiring with the screw terminal board.

The wiring diagram between Arduino Nano and 33 IoT 12V Active Buzzer Screw Terminal

This image is created using Fritzing. Click to enlarge image

Note: on the Arduino Nano 33 IoT, the 5V pin is the VUSB pin. It gives 5V only after you close the VUSB solder jumper on the bottom of the board, and only when the board runs on USB power.

Arduino Nano 33 IoT Code

This code repeatedly turns the 12V active buzzer on for one second and then off for two seconds.

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-buzzer */ #define RELAY_PIN 2 // The Arduino Nano 33 IoT that connects to relay to control the 12V buzzer // The setup function runs once on reset or power-up void setup() { // initialize digital pin as an output. pinMode(RELAY_PIN, OUTPUT); } void loop() { digitalWrite(RELAY_PIN, HIGH); delay(1000); digitalWrite(RELAY_PIN, LOW); delay(2000); }

Detailed Instructions

If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:

  • Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
  • Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
  • Launch the Arduino IDE on your computer.
  • Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
  • Copy the code above and paste it into the Arduino IDE.
  • Click the Upload button to send the code to the Arduino Nano 33 IoT.
  • Check the status of the 12V active buzzer.

Code Explanation

You can find the explanation in the comments of the Arduino code above.

How to Make Alarm Beeps with MOSFET Module

Now let's replace the relay with a MOSFET module. The buzzer works the same, but there is no click, so it can beep fast like a real alarm.

Wiring Diagram

The wiring diagram between Arduino Nano and 33 IoT 12V active buzzer MOSFET module

This image is created using Fritzing. Click to enlarge image

Here is the same wiring without a breadboard:

The wiring diagram between Arduino Nano and 33 IoT 12V active buzzer MOSFET module  (No Breadboard)

This image is created using Fritzing. Click to enlarge image

From To
Arduino Nano 33 IoT pin D9 MOSFET module PWM
Arduino Nano 33 IoT GND MOSFET module GND
12V adapter + MOSFET module +
Buzzer red wire (+) MOSFET module + (same terminal as the adapter +)
Buzzer black wire (−) MOSFET module LOAD
12V adapter − MOSFET module −

Pushing jumper wires into the headers is quick, but the wires can slip out. To do that, mount the Arduino Nano 33 IoT on a Screw Terminal Expansion Board for Arduino Nano. The diagram below shows the same wiring with the screw terminal board.

The wiring diagram between Arduino Nano and 33 IoT 12V active buzzer MOSFET module Screw Terminal

This image is created using Fritzing. Click to enlarge image

Most 12V active buzzers have a small circuit inside and do not need a flyback diode. If your buzzer is a magnetic type (it has a coil inside), add a 1N4007 or 1N5819 diode across it. The side with the stripe (cathode) goes to the buzzer +, the other side goes to the buzzer −.

The Arduino Nano 33 IoT pin gives only 3.3V, but this is enough for the MOSFET module. No level shifter is needed. Never connect the 12V to any pin of the Arduino Nano 33 IoT.

Arduino Nano 33 IoT Code

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-buzzer */ #define MOSFET_PIN 9 // The Arduino Nano 33 IoT pin connected to the PWM pin of the MOSFET module void setup() { Serial.begin(9600); pinMode(MOSFET_PIN, OUTPUT); digitalWrite(MOSFET_PIN, LOW); // start with the buzzer OFF } void loop() { // fast alarm beeps: 10 short beeps Serial.println("Alarm: fast beeps"); for (int i = 0; i < 10; i++) { digitalWrite(MOSFET_PIN, HIGH); // turn on buzzer delay(100); digitalWrite(MOSFET_PIN, LOW); // turn off buzzer delay(100); } // one long beep Serial.println("Alarm: long beep"); digitalWrite(MOSFET_PIN, HIGH); delay(1000); digitalWrite(MOSFET_PIN, LOW); // quiet time Serial.println("Quiet"); delay(3000); }

What the buzzer does: it beeps 10 times fast, then makes one long beep, then stays quiet for 3 seconds. Then it starts again.

An active buzzer makes its own sound. Only turn it fully ON or fully OFF with digitalWrite(). Do not use analogWrite() (PWM) to change the volume, because the sound will be weak or strange.

Detailed Instructions

  • Do the same setup as in the Quick Steps of the relay part above.
  • Wire the buzzer and the MOSFET module as shown in the diagram. Keep the 12V adapter unplugged.
  • Upload the code above to the Arduino Nano 33 IoT.
  • Plug in the 12V adapter.
  • Open the Serial Monitor at 9600 baud.
  • Listen to the buzzer: you hear the fast beeps with no relay click.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano 33 IoT
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano 33 IoT' on 'COM15')
New Line
9600 baud
Alarm: fast beeps Alarm: long beep Quiet Alarm: fast beeps Alarm: long beep Quiet
Ln 11, Col 1
Arduino Nano 33 IoT on COM15
2

※ NOTE THAT:

The MOSFET module works with DC only, and the buzzer power supply must be about 6V or more. For a 5V buzzer, see the Arduino Nano 33 IoT Piezo Buzzer tutorial. For an AC buzzer or siren, use the relay.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!