ESP8266 - Siren
This tutorial instructs you on how to program ESP8266 to control a siren to produce a warning sound and/or light.
Hardware Preparation
1 | × | ESP8266 NodeMCU | |
1 | × | Micro USB Cable | |
1 | × | Relay | |
1 | × | 12V Alarm Siren Horn | |
1 | × | 12V Power Adapter | |
1 | × | DC Power Jack | |
1 | × | Jumper Wires | |
1 | × | Breadboard | |
1 | × | (Optional) Screw Terminal Expansion Board for ESP8266 |
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
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
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 ESP8266 and 12V siren. ESP8266 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 ESP8266 - Relay tutorial
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.
ESP8266 Code
The below code repeatedly turns the 12V siren ON in two seconds and OFF in four seconds,
Detailed Instructions
To get started with ESP8266 on Arduino IDE, follow these steps:
- Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
- Wire the components as shown in the diagram.
- Connect the ESP8266 board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
- Connect ESP8266 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 ESP8266
- Check out the siren's state
Code Explanation
Read the line-by-line explanation in comment lines of code!