Arduino Sound-Activated LED Project

Arduino Sound-Activated LED Project

In  the Sound-Activated LED Project, a basic Arduino circuit will be constructed, primarily utilising a two-colour LED (light-emitting diode) module and a microphone sound sensor module. The premise of this project is simple: when the sound sensor picks up a snap/clap sound, the LED will switch from a green colour to a red colour for two seconds, and then revert to its original green colour. If a snap sound is not detected by the sound sensor at all, the LED will simply remain green in colour. The sound technically does not need to be a snap/clap sound as it is just an example of a sound that may spike the sensor’s reading above a certain threshold value, to then trigger the change in LED colour.

The sound sensor module that is featured in  Sound-Activated LED is the HW-485 Microphone Sound Sensor Module and has the capability of outputting both analogue & digital signals. However, because this project makes use of digital signalling in switching the LED colour between two states, the digital output of the sensor will be used. This means that the sound sensor can only send two states depending on the input level (sound) that it receives: 1 (on) or 0 (off). The sensor will send a 1 to the Arduino if it picks up any sound that is above its threshold value; otherwise, a 0 is sent for all sounds that do not cross the threshold.

In order to alter this threshold value, you can rotate the trimmer potentiometer that is mounted directly on the sensor module to modulate the sensitivity of the sensor. For this particular model (HW-485), rotating the potentiometer clockwise increased its sensitivity whereas rotating the potentiometer counter-counterclockwise decreased its sensitivity. It is important to note that for your sound sensor module, depending on the model, the direction may be opposite. If the LED is not changing state (colour) when there is a loud sound nearby, you will need to alter the sensitivity of the sensor. 

Upon understanding the fundamental principles of this Arduino project, it will certainly be easier to incorporate and integrate some of the concepts demonstrated in this circuit into other applications. The basis of this project essentially relies on the sound sensor picking up an input (sound) and acting as a switch to then activate a change in the LED module, the output device. With this concept in mind, the output device can easily be substituted with a piezo buzzer (to generate noise), a visual display (LCD, OLED, TFT, etc), a relay (connected in line with other external devices), a wireless transmitter etc. Additionally, in consumer electronic PCBA, a similar type of circuit is used when creating voice-activated electronic devices or even home automation systems. Many of these circuits can additionally be integrated into a PCB by both through-hole and surface-mount PCBA to reduce the overall size of the project. By transferring a project like this from a breadboard onto a PCB, it can be achieved effortlessly. To make this circuit project homebrew we need to source components:

  • Arduino Nano (подойдут и другие совместимые с Arduino платы)
  • USB-кабель (совместимый с платой Arduino)
  • Хлебная доска
  • Male-Male Jumper Wires (6)
  • HW-485 Microphone Sound Sensor Module
  • HW-480 Красный/зеленый 2-цветный светодиодный модуль (общий катод)
  • 220Ω резисторы (2)

Sound Control LED Electronic Project Wiring Diagram

В зависимости от вашей платы Arduino, вам может потребоваться или не потребоваться макетная плата для подключения платы. В данном примере используется Arduino Nano, поэтому требуется макетная плата, но если вы используете, например, Arduino Uno, провода-перемычки можно подключить от компонентов на макетной плате непосредственно к контактам платы.

The wiring for this project is fairly simple as aside from the main modules, not a lot of extra components are needed. In terms of the sound sensor module, the HW-485 module that is featured in this project has a 4-pin configuration where there is a digital output (DO) and analogue output (AO). If your module has this same 4-pin configuration, use the digital output (DO) but if your module has a 3-pin configuration, the standard output/signal pin will work. In terms of the LED module, the reason that two 220Ω resistors are connected in series with the two outputs from this module is to prevent the LEDs from burning out when applying a supply voltage of +5 volts. Here’s a circuit diagram of the wiring for this DIY project:

  • HW-485 Microphone Sound Sensor Module: Connect the digital output (DO)/signal pin to D7 on your Arduino board, the positive (+) pin to +5v and the GND (G) pin to GND.
  • HW-480 Red/Green 2-Colour LED Module: Insert one 220Ω resistor in the breadboard in series with the output pin for the red colour LED signal (R) and insert another 220Ω resistor in series with the output pin for the green colour LED signal (G). Connect the red colour output pin (R) to D5 and the green colour output pin (G) to D6. Connect the negative (-) pin to GND on your Arduino.
  • Теперь вы можете подключить плату Arduino через USB-кабель к компьютеру.

Код проекта

int redPin = 5;

int greenPin = 6;

int sensorPin = 7;

boolean val = 0;

 

void настройка(){

 pinMode(redPin, OUTPUT);

 pinMode(greenPin, OUTPUT);

 pinMode(sensorPin, INPUT);

 Серийный.начать(9600);

}

 

 void петля (){

 val = digitalRead(sensorPin);

 Серийный.println(val);

 

 если (val == HIGH) {

   digitalWrite(greenPin, LOW);

   digitalWrite(redPin, HIGH);

   задержка(2000);

 }

 else {

   digitalWrite(redPin, LOW);

   digitalWrite(greenPin, HIGH);

 }

}

О коде

  • This simple code is an excellent display of many of the functions that you may come across again while Программирование ИС in the Arduino IDE, which uses a variant of the C++ programming languages. This code features fundamental integers, booleans, useful functions and if statements.
  • The first block of code defines the three digital pins on the Arduino that are being used by the microphone sensor module and the LED module. The variable redPin designates pin D5 to be used for the red colour LED signal, greenPin designates D6 and sensorPin designates D7 for use with the sound sensor module. In addition, a boolean named val is assigned to 0 (low/false/off). A boolean is a specific data type that can either hold a true or false value (1 or 0).
  • Moving on to the void setup part, each of the pins that were defined earlier is now either defined here as an input or output. Since the sound sensor is picking up sound data and then sending it to the Arduino for processing, it is set as an input whereas the LED module is receiving data from the Arduino so the two LED pins are set as outputs. The serial communication baud rate is set to 9600 bauds so that the data picked up by the sensor can be read within the serial monitor later on.
  • Regarding the void loop part, the boolean val is first set to whatever state the sound sensor is currently in. Since the Arduino is receiving digital output from the sensor, the information it sends to the Arduino can only either be true (1) or false (0). This data is then printed to the serial monitor and this information can be very useful when calibrating the sensitivity of the sound sensor (setting the threshold for sounds that the sensor can detect). 
  • Next, an if statement is introduced that essentially states that if the sound sensor detects a snap (when the sound sensor sends back a 1), the green colour LED will be switched off and the red colour LED will be switched on for two seconds before switching back to its default state (red colour LED off and green colour LED on). This demonstrates the use of the pinMode() function that specifically can switch a digital output (e.g. LED module) either on (HIGH) or off (LOW) depending on certain parameters within the if statement, in this case.

Следующие шаги

This sound-activated LED project from Технология FS is an excellent introductory project into the use of various input and output devices, in addition to various fundamental functions that are used in the Arduino code to control information being received and sent from/to those devices. Resultantly, this principle can then be applied to much larger projects where the digital input from a sensor can be used to trigger a circuit or switch on/off an output device. For example, motion-detection systems typically incorporate PIR (passive infrared) sensors that when activated, will trigger a bright light or an alarm. This is simply one of the many examples of this simple digital input-output system that is incorporated in many electrical appliances and electronic circuits today. In terms of the code functions/statements that were featured in the Arduino code, one of the most important functions to remember are if statements. These statements are extremely fundamental and popular functions that can be seen in almost all codes, especially when working with several devices that are communicating with one another to form part of a larger network/system. With all of these concepts in mind, it is now up to you to be able to apply and expand upon your newly-founded knowledge to create your DIY PCBA плата!

Блог о проектах DIY электроники

Рекомендации по печатной плате клавиатуры для горячей замены

Рекомендации по печатной плате с горячей заменой клавиатуры Традиционные платы PCBA полагаются на процесс пайки для надежного крепления компонентов к поверхности печатной платы. В то время как

Читать далее "
Как разогнать Ваш Raspberry Pi?

Как разогнать Ваш Raspberry Pi? Хотели ли Вы когда-нибудь увеличить возможности Вашей Raspberry Pi без необходимости использования дополнительного оборудования или

Читать далее "
Проект Arduino Photoresistor Night Light

Проект Arduino Photoresistor Night Light Принцип проекта Введение В сегодняшнем проекте будет построена схема ночного освещения с использованием модуля фоторезисторов HW-486 и

Читать далее "