Introduction: Arduino Sound Sensor Alarm
This tutorial aims to build an alarm based on the sound sensor by using Arduino.
Step 1: Required Component
1. A sound sensor
2. A LED
3. A 330-ohm resistor
4. An Arduino board
5. Bunch of wires
6. A computer
In addition, it requires a basic understanding of Arduino code and python
Step 2: Build the Circuit
Same as the first graph, a sound sensor have four pins. VCC and GND will connect to 5V and GND on Arduino. D0 need to wire with any digital pin which is 7 in my circuit on Arduino board. That is how a sound sensor should wire.
Later, the Led need to be wired either. The short side should connect to ground on Mini breadboard. The most important is 330-ohm resistor should be wired between them. The long side will connect to another digital pin which is 13 in my circuit.
Step 3: Arduino Code
After the circuit set up, we can use Arduino code to make it work.
Step 4: Flask
In order to control the sensor by flask, we will first write a flask by python. We first need to know what we want to detect in order to store in forms.py file. In this case, the only thing we need to know whether the sensor is on or off.
Routes.py should transfer data if we make any change of switch state of the sound sensor. In addition, we need to use the pyserial package in order to communicate with the Arduino since the Arduino code is compiled in C code. It will write the value into the Arduino to switch on and off the sensor.
We also need two HTML file in order to run the webpage. The login file is the file you will see the state of the sensor. If you want to change the state, it will redirect to the index page and this is the page you can turn on and off the sensor.
All the file should be saved in as the pictures to run them. Also, you need to use pip install to install flask, pyserial, flask-wtf if you don't have them. These are necessary modules to run the following files.
Step 5: Test
After every above step is finished, you should be able to run your new small alarm. In order to do that, you need to run "python iotapp.py".