Arduino Nano ESP32 - Siren

In this tutorial, we are going to learn how to program Arduino Nano ESP32 to control a siren to produce a warning sound and/or light.

Hardware Preparation

1×Arduino Nano ESP32
1×USB Cable Type-C
1×Relay
1×12V Alarm Siren Horn
1×12V Power Adapter
1×(Optional) 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

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
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 Siren

Depending on the manufacturer, a siren can produce either a loud sound or a warning light, making it suitable for an alarm system. It is also available in several operating voltages. This tutorial will use a 12V siren, and other voltages will be similar.

Pinout

Arduino Nano ESP32 12V siren Pinout

12V siren usually has two pins:

  • Negative (-) pin (black): needs to be connected to GND of DC power supply
  • Positive (+) pin (red): needs to be connected to 12V of DC power supply

How to Control a Siren

If 12V siren is powered by 12V power supply, it make sound and/or warning light. To control a 12V siren, we need to use a relay in between Arduino Nano ESP32 and 12V siren. Arduino Nano ESP32 can control the 12V siren via the relay. If you do not know about relay (pinout, how it works, how to program ...), learn about relay in the Arduino Nano ESP32 - Relay tutorial

Wiring Diagram

The wiring diagram between Arduino Nano ESP32 and 12V siren

This image is created using Fritzing. Click to enlarge image

Arduino Nano ESP32 Code

The below code repeatedly turns the 12V siren ON in three seconds and OFF in five seconds,

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-siren */ #define RELAY_PIN D2 // The Arduino Nano ESP32 that controls the siren via relay // 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(3000); digitalWrite(RELAY_PIN, LOW); delay(5000); }

Detailed Instructions

  • If this is the first time you use Arduino Nano ESP32, see how to setup environment for Arduino Nano ESP32 on Arduino IDE
  • Connect Arduino Nano ESP32 to PC via USB cable
  • Open Arduino IDE, select the right board and port
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to Arduino Nano ESP32
  • Check out the siren's state

Code Explanation

Read the line-by-line explanation in comment lines of code!

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!