Sound Sensor Constantly reading high

Hey, I'm having a problem with my sound sensor . I'm trying to just run a basic code so that when I snap my fingers or clap, the LED light will turn on for a small duration of time. However, when I open the serial reader and make any sort of loud noise, the module will sense it but then stay at that value instead of going back down. For example it will change the LED light color to red when sensorval is >50 and it will read 53 when there is a significant noise but then continually read 53 even though the noise is not present. I am using a rgb led hooked up to a BBQ knob light so for some reason the values are switched (255 is low and 0 is high). There is no pattern to this so I am not sure how to fix it. I also wanted to know if there was a way to increase sensitivity of the mic. sound sensor:


int D = 0; int DA = 14;

int redPin = 3; int greenPin = 5; int bluePin = 6;

int green; int blue;

int sensorval = 0; int oldsensorval; int diff;

void setup() { Serial.begin(9600); pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); // put your setup code here, to run once: Setcolor(0,0,0);


void loop() { sensorval = analogRead(DA);//READS VAL FROM SOUND SENSOR Serial.println(sensorval); delay(1); if (sensorval > 50) {///IF VAL IS OVER THRESHOLD, THEN TURN RED Setcolor(0,255,255); } else {//IF NOT, STAY WHITE Setcolor(0,0,0); } } void Setcolor(int R, int G, int B) { analogWrite(redPin, R); analogWrite(greenPin, G); analogWrite(bluePin, B); delay (15 ); }

"pin: the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the Mini and Nano, 0 to 15 on the Mega)".

Do you have a Mega?


int DA = 14; sensorval = analogRead(DA);

analogRead(14); // is A0 on an Uno.

DA suggests you use the digital output of the sound module (sound/nosound). Then you should use a digital input. And set trigger level with the 10-turn pot.

An analogRead of the analogue ouptut of the module (trimpot now doesn't matter) is more complicated. The audio wave has to be sampled constantly, min/max peak values have to be extracted, and difference between the two has to be calculated and compared to a set threshold. Leo..

@Briskgotmethrough, do no cross-post. Do not hijack. Other thread removed.

@ Coding Badly, sorry about that!! :cold_sweat: :cold_sweat: :astonished: :astonished: @Wawa Thanks for the advice! I'll probably use digital for this project but for future reference how would I use analog to do the same thing? because digital only has on or off (High or low ) and I wanted to do stuff with with changing colors based on volume levels. if there is a better module to do this, which would that be?

The MSGEQ7 can be used to make a colour organ (Google it).