Microphone Sound Sensor explained | HW-484 | Interfacing with ESP 8266
Microphone Sound Sensor
In this tutorial, we will learn about microphone sound sensor which is used to measure sound intensity. The sensor takes in ambient sound and provides a voltage corresponding to intensity in both digital and analog outputs. We will see both cases of outputs.
In this we will try to lit an Led if the voltage output is above a threshold.
Parts Needed
1. ESP 8266 NodeMCU
2. 330 Ohms resistor
4. HW 484 Sensor
5. Power supply 3.3v/5v
6. Led
7. Jumper wires and bread board
Connections
Power supply 3.3V - HW484 +
Power supply Gnd - HW484 G
NodeMCU D4 - HW484 D0
NodeMCU D2 - 330 Ohms Resistor - Led
CODE
boolean soundValue = 0; void setup() { pinMode(D2, OUTPUT); pinMode(D4, INPUT); Serial.begin(115200); } void loop() { soundValue = digitalRead(D4); Serial.println (soundValue); if(soundValue == HIGH) { digitalWrite(D2, HIGH); } else { digitalWrite(D2, LOW); } }
Case 1 : Using Analog Output
In this we will try to lit an Led strip based on sound intensity from alexa.Parts Needed1. ESP 8266 NodeMCU2. Led strip3. HW 484 Sensor4. Power supply 3.3v/5v5. Jumper wiresConnectionsNodeMCU D5 - Led strip Data pinNodeMCU Vcc- Power supply 5V - Led Strip VccNodeMCU Gnd - Powersupply Gnd - Led Strip GndNodeMCU D4 - HW484 A0NodeMCU 3.3V - HW484 VccNodeMCU Gnd - HW 484 GndCODE
#include <FastLED.h> #define NUM_LEDS 35 #define DATA_PIN D5 CRGB leds[NUM_LEDS]; void setup() { FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); FastLED.setBrightness(30); } void loop() { int sensorValue = analogRead(A0); if(sensorValue > 680) sensorValue = 680; if(sensorValue < 520) sensorValue = 520; int noOfLeds = min ((sensorValue - 520)/4 + 1, NUM_LEDS); CRGB colors[12] = { CRGB::Aqua,CRGB::Lime, CRGB::DeepPink, CRGB::Navy, CRGB::Coral, CRGB::Orchid, CRGB::Plum, CRGB::YellowGreen, CRGB::Green, CRGB::Red, CRGB::Yellow, CRGB::Blue}; for( int i = 0; i < noOfLeds; ++i) { leds[i] = colors[i/3]; } for( int i = noOfLeds; i < NUM_LEDS; ++i) { leds[i] = CRGB::Black; } FastLED.show(); }Troubleshooting
1. Adjust potentiometer for sensitivity. I used it to get correct digital output for led.
2. Validate the output from analog output as the threshold range is of 200 values. Adjust potentiometer to bring the initial values to desired range. In my case it was 520.
3. Although Analog output is usually of range 0 - 1023 in this case the range is less and can be controlled. According to specs HW484 will output a threshold voltage of max vcc/2.
Comments
Post a Comment