Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Sound-Activated

Sound-Activated: Controlling Devices with Sound

Introduction: The ability to control devices using sound has become increasingly popular in various applications, such as home automation, robotics, and interactive installations. This article aims to explore the concept of sound-activated control using Arduino, providing examples of code and a list of components required for the projects.

Project: The project we will create as an example is a sound-activated LED strip. The objective is to control the LED strip based on the sound level in the environment. When the sound reaches a certain threshold, the LED strip will turn on, and when the sound level decreases, it will turn off.

Components: To complete this project, you will need the following components:

  • Arduino Uno board
  • Sound sensor module (e.g., KY-038)
  • LED strip (e.g., WS2812B)
  • Jumper wires
  • Breadboard
  • Power supply for the LED strip (if necessary)

Examples: Here is an example code that demonstrates the sound-activated LED strip:

#include <Adafruit_NeoPixel.h>

#define PIN_LED_STRIP 6
#define PIN_SOUND_SENSOR A0

Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, PIN_LED_STRIP, NEO_GRB + NEO_KHZ800);
int soundThreshold = 500;
boolean ledState = false;

void setup() {
  strip.begin();
  strip.show();
  pinMode(PIN_SOUND_SENSOR, INPUT);
}

void loop() {
  int soundLevel = analogRead(PIN_SOUND_SENSOR);
  if (soundLevel > soundThreshold && !ledState) {
    strip.fill(strip.Color(255, 0, 0));  // Turn on the LED strip with red color
    strip.show();
    ledState = true;
  }
  else if (soundLevel < soundThreshold && ledState) {
    strip.fill(strip.Color(0, 0, 0));  // Turn off the LED strip
    strip.show();
    ledState = false;
  }
}

Explanation:

  1. We include the necessary library, Adafruit_NeoPixel, to control the LED strip.
  2. We define the pin numbers for the LED strip and sound sensor.
  3. We create an instance of the Adafruit_NeoPixel class, specifying the number of LEDs and the pin number.
  4. We set the sound threshold, above which the LED strip will turn on.
  5. We initialize the LED strip and set the sound sensor pin as an input.
  6. In the loop function, we read the sound level from the sensor using analogRead.
  7. If the sound level exceeds the threshold and the LED strip is currently off, we turn on the LED strip by setting all LEDs to red color.
  8. If the sound level goes below the threshold and the LED strip is currently on, we turn off the LED strip by setting all LEDs to off.
  9. We update the LED strip by calling strip.show().

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.