# Sound sensor results high reading

**URL:** <https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863>\
**Category:** General Guidance\
**Created:** [November 28, 2022, 7:10am UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863 "2022-11-28T07:10:37Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![aidid](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@aidid](https://forum.arduino.cc/u/aidid)\
**Post date:** [November 28, 2022, 7:10am UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/1 "2022-11-28T07:10:37Z")

</div>

Hi , I tried my sound sensor and found one weird value.

```cpp
min=427	max=1023	p2p=596.00	Loudness: 62Db(A)	Level3: HIGH
min=1024	max=0	p2p=4294966272.00	Loudness: 2099226Db(A)	Level4: Ultimately HIGH
min=0	max=33	p2p=33.00	Loudness: 27Db(A)	Levell: Quiet
min=521	max=854	p2p=333.00	Loudness: 46Db(A)	Level2: Moderate
min=43	max=1021	p2p=978.00	Loudness: 87Db(A)	Level4: Ultimately HIGH
min=926	max=1020	p2p=94.00	Loudness: 30Db(A)	Levell: Quiet
min=1024	max=0	p2p=4294966272.00	Loudness: 2099226Db(A)	Level4: Ultimately HIGH

```

this is the code

```cpp

BlynkTimer timer;
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
const byte soundpin = 35;
const byte led1 = 2;
const byte led2 = 4;
const byte led3 = 17;
const byte led4 = 19;

void setup() {

  pinMode (soundpin, INPUT);
  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT);
  pinMode (led3, OUTPUT);
  pinMode (led4, OUTPUT);
  Serial.begin (115200);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(1000L, sensorDataSend);

}

void sensorDataSend() {
  int sample;
  unsigned long startMillis = millis();
  float peakTopeak = 0;
  int db;

  unsigned int signalMax = 0; // minvalue
  unsigned int signalMin = 1024; //maxvalue previously 1024

  while (millis() - startMillis < sampleWindow)
  {
    sample = analogRead(soundpin);
    if (sample < 1024) //previously i use 1024
    {
      if (sample > signalMax)
      {
        signalMax = sample; //save just max level
      }
      else if (sample < signalMin)
      {
        signalMin = sample; //save just min level
      }
    }
  }
  Serial.print("\nmin=");
  Serial.print(signalMin);
  Serial.print("\tmax=");
  Serial.print(signalMax);
  peakTopeak = signalMax - signalMin;
  Serial.print("\tp2p=");
  Serial.print(peakTopeak);
  int store = map(peakTopeak, 0, 1023, 25, 90 ); //calibrate the db 20,900,49,90
  db = store;
  Serial.print("\tLoudness: ");
  Serial.print (db);
  Serial.print ("Db(A)\t");
  Blynk.virtualWrite(V0, db);
  digitalWrite (led1, LOW);
  digitalWrite (led2, LOW);
  digitalWrite (led3, LOW);
  digitalWrite (led4, LOW);
  Blynk.virtualWrite(V1, 0);
  Blynk.virtualWrite(V2, 0);
  Blynk.virtualWrite(V3, 0);
  Blynk.virtualWrite(V4, 0);
  if (db <= 40)
  {
    Serial.print("Levell: Quiet");
    digitalWrite(led1, HIGH);
    Blynk.virtualWrite(V1, 1);
  }
  else if (db > 40 && db < 55)
  {
    Serial.print("Level2: Moderate");
    digitalWrite(led2, HIGH);
    Blynk.virtualWrite(V2, 1);
  }
  else if (db > 55 && db < 70)
  {
    Serial.print("Level3: HIGH");
    digitalWrite(led3, HIGH);
    Blynk.virtualWrite(V3, 1);
  }
    else if (db >= 70)
  {
    Serial.print("Level4: Ultimately HIGH");
    digitalWrite(led4, HIGH);
    Blynk.virtualWrite(V4, 1);
  }
}

void loop() {
  Blynk.run();
  timer.run();

}

```

could you help me solve this because the peak to peak= min -max. but min = 1024. and max = 0. also anyone have other idea to do a project on decibel meter?

---

<div class="post-metadata">

**Author:** ![johnerrington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnerrington/32/340106_2.png) [@johnerrington](https://forum.arduino.cc/u/johnerrington)\
**Post date:** [November 28, 2022, 7:17am UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/2 "2022-11-28T07:17:20Z")

</div>

What hardware are you using?

> [@How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966):
>
> See also [FAQ - Arduino Forum](https://forum.arduino.cc/faq) for general rules on forum behaviour and etiquette. Hello, Welcome to the Arduino Forum. This guide explains how to get the best out of this forum. Please read and follow the instructions below. Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…

Wher is your schematic?

> [@How to make a schematic you can post.](https://forum.arduino.cc/t/how-to-make-a-schematic-you-can-post/675103):
>
> When you submit a question on the forum you will usually need to add a schematic (circuit diagram). The tutorial that follows will explain some ways to create a useful image; however lets start by explaining how to add the image to your post. Its easy. Having created the image all you need to do is : Save the image somewhere convenient - maybe your desktop Start your post, and place the cursor (insertion point) where you want the image to be shown; [upload image to forum] 3: click th…

---

<div class="post-metadata">

**Author:** ![aidid](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@aidid](https://forum.arduino.cc/u/aidid)\
**Post date:** [November 28, 2022, 7:45am UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/3 "2022-11-28T07:45:15Z")

</div>

below is the 4 leds connects to esp32 through breadboard to notify the user for certain limit of decibel level. and 3 out of 4 pin of grove sound sensor connect to measure analog signal before get the reading in db.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/7/f/8/7f8aa6168340b2da94436045372a54a36aa71695.jpeg)

---

<div class="post-metadata">

**Author:** ![johnerrington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnerrington/32/340106_2.png) [@johnerrington](https://forum.arduino.cc/u/johnerrington)\
**Post date:** [November 28, 2022, 11:29am UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/4 "2022-11-28T11:29:25Z")

</div>

> [@aidid](#):
>
> grove sound sensor

link?

maybe this one?

> **[101020023 | Digi-Key Electronics](https://www.digikey.co.uk/en/products/detail/seeed-technology-co.,-ltd/101020023/5482608)**
>
> Order today, ships today. 101020023 – LM386 Sound Sensor Grove Platform Evaluation Expansion Board from Seeed Technology Co., Ltd. Pricing and Availability on millions of electronic components from Digi-Key Electronics.

---

<div class="post-metadata">

**Author:** ![aidid](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@aidid](https://forum.arduino.cc/u/aidid)\
**Post date:** [November 28, 2022, 12:13pm UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/5 "2022-11-28T12:13:07Z")

</div>

[https://shopee.com.my/Grove-Loudness-Sensor-PROMO-PRICE--i.6641351.1038780762](https://shopee.com.my/Grove-Loudness-Sensor-PROMO-PRICE--i.6641351.1038780762)  
this link

---

<div class="post-metadata">

**Author:** ![aidid](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@aidid](https://forum.arduino.cc/u/aidid)\
**Post date:** [November 28, 2022, 2:59pm UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/6 "2022-11-28T14:59:47Z")

</div>

is it because of I connect to 5v on the esp32 ? it turn okay but not too fluctuate to follow the sound changes when supply by 3v3 pin

---

<div class="post-metadata">

**Author:** ![Paul\_KD7HB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_kd7hb/32/1127958_2.png) [@Paul\_KD7HB](https://forum.arduino.cc/u/Paul_KD7HB)\
**Post date:** [November 28, 2022, 3:12pm UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/7 "2022-11-28T15:12:51Z")

</div>

> [@aidid](#):
>
> ` if (sample < 1024) //previously i use 1024`

Since the maximum you can ever get from an analog read is 1023, this will ALWAYS be true. Why is it there?

---

<div class="post-metadata">

**Author:** ![aidid](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@aidid](https://forum.arduino.cc/u/aidid)\
**Post date:** [November 29, 2022, 9:49am UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/8 "2022-11-29T09:49:29Z")

</div>

i see. so i should put condition like sample\<1023

---

<div class="post-metadata">

**Author:** ![johnerrington](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnerrington/32/340106_2.png) [@johnerrington](https://forum.arduino.cc/u/johnerrington)\
**Post date:** [November 29, 2022, 11:04am UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/9 "2022-11-29T11:04:32Z")

</div>

what is the purpose of that if statement?

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [November 29, 2022, 11:11am UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/10 "2022-11-29T11:11:25Z")

</div>

> [@Paul\_KD7HB](#):
>
> Since the maximum you can ever get from an analog read is 1023, this will ALWAYS be true. Why is it there?

An ESP32 has a 12 bit A:D converter the max is a bit higher than 1023.

Putting 5V into the 3V3 pins of a ESP32 will destroy the ESP32, as a note.

Here is a task I use to calculate V's.

```arduino

void fReadBattery( void * parameter )
{
  const float r1 = 50500.0f; // R1 in ohm, 50K
  const float r2 = 10000.0f; // R2 in ohm, 10k potentiometer
  const TickType_t xFrequency = 1000; //delay for mS
  float adcValue = 0.0f;
  float Vbatt = 0.0f;
  int printCount = 0;
  float vRefScale = (3.3f / 4096.0f) * ((r1 + r2) / r2);
  uint64_t TimePastKalman = esp_timer_get_time(); // used by the Kalman filter UpdateProcessNoise, time since last kalman calculation
  SimpleKalmanFilter KF_ADC_b( 1.0f, 1.0f, .01f );
  TickType_t xLastWakeTime = xTaskGetTickCount();
  for (;;)
  {
    adc1_get_raw(ADC1_CHANNEL_0); //read and discard
    adcValue = float( adc1_get_raw(ADC1_CHANNEL_0) ); //take a raw ADC reading
    KF_ADC_b.setProcessNoise( (esp_timer_get_time() - TimePastKalman) / 1000000.0f ); //get time, in microsecods, since last readings
    adcValue = KF_ADC_b.updateEstimate( adcValue ); // apply simple Kalman filter
    Vbatt = adcValue * vRefScale;
    xSemaphoreTake( sema_CalculatedVoltage, portMAX_DELAY );
    CalculatedVoltage = Vbatt;
    xSemaphoreGive( sema_CalculatedVoltage );
    
      printCount++;
      if ( printCount == 3 )
      {
      //log_i( "Vbatt %f", Vbatt );
      printCount = 0;
      }
    
    TimePastKalman = esp_timer_get_time(); // time of update complete
    xLastWakeTime = xTaskGetTickCount();
    vTaskDelayUntil( &xLastWakeTime, xFrequency );
    //log_i( "fReadBattery %d", uxTaskGetStackHighWaterMark( NULL ) );
  }
  vTaskDelete( NULL );
}

```

Note the use of 4096, `float vRefScale = (3.3f / 4096.0f) * ((r1 + r2) / r2);` instead of 1024 to calculate V's.

---

<div class="post-metadata">

**Author:** ![DVDdoug](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dvddoug/32/671533_2.png) [@DVDdoug](https://forum.arduino.cc/u/DVDdoug)\
**Post date:** [November 29, 2022, 3:02pm UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/11 "2022-11-29T15:02:19Z")

</div>

> [@](#):
>
> also anyone have other idea to do a project on decibel meter?

I once made an [SPL Meter](https://forum.arduino.cc/t/sound-sensor-which-one/962327/6) with an Arduino Uno and an analog SparkFun sound sensor.

You'd have to adapt it to the ESP32, calibrate for particular sound sensor, and possibly make other changes for your sensor. And, you'd need to add the code for the LEDs. (I send the dB values to the Serial Monitor.)

---

<div class="post-metadata">

**Author:** ![aidid](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@aidid](https://forum.arduino.cc/u/aidid)\
**Post date:** [November 29, 2022, 4:29pm UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/12 "2022-11-29T16:29:14Z")

</div>

this is the latest one.

```cpp
void sensorDataSend() {
  int sample;
  unsigned long startMillis = millis();
  float peakTopeak = 0;
  int db;
 
  unsigned int signalMax = 0; // minvalue
  unsigned int signalMin = 1024; //maxvalue previously 1024

  while (millis() - startMillis < sampleWindow)
  {
    analogSetWidth(10);
    sample = analogRead(soundpin);
    if (sample > signalMax)
    {
      signalMax = sample; //save just max level
    }
    else if (sample < signalMin)
    {
      signalMin = sample; //save just min level
    }

  }
  Serial.print("\nmin=");
  Serial.print(signalMin);
  Serial.print("\tmax=");
  Serial.print(signalMax);
  peakTopeak = signalMax - signalMin;
  Serial.print("\tp2p=");
  Serial.print(peakTopeak);
  int store = map(peakTopeak, 0, 1023, 30, 90 ); //calibrate the db 20,900,49,90
  db = store;

```

however I still get analog value more than 1023, may I know how it can happened even I reduce to 10 bit. below is the serial monitor

```cpp
min=0	max=1328	p2p=1328.00	Loudness: 94Db(A)	Level4: Ultimately HIGH
min=472	max=660	p2p=188.00	Loudness: 39Db(A)	Levell: Quiet

```

---

<div class="post-metadata">

**Author:** ![Paul\_KD7HB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_kd7hb/32/1127958_2.png) [@Paul\_KD7HB](https://forum.arduino.cc/u/Paul_KD7HB)\
**Post date:** [November 29, 2022, 4:37pm UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/13 "2022-11-29T16:37:07Z")

</div>

> [@aidid](#):
>
> however I still get analog value more than 1023,

I did not realize you were using an ESP32 device. What is the largest value you can get with 12 bits? The 1023 is the largest value for 10 bits.

---

<div class="post-metadata">

**Author:** ![aidid](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@aidid](https://forum.arduino.cc/u/aidid)\
**Post date:** [November 29, 2022, 4:49pm UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/14 "2022-11-29T16:49:40Z")

</div>

I have an issue with the sensitivity since I compare the reading with decibelX(software from phone). The above coding I shared with you is less sensitivity, when I clap, theres no big changes in db value. So i taught because of the bit is 12, is there reason I should reduce to 10bit to increase the sens of sensor? or any idea on this thing?

---

<div class="post-metadata">

**Author:** ![Paul\_KD7HB](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/paul_kd7hb/32/1127958_2.png) [@Paul\_KD7HB](https://forum.arduino.cc/u/Paul_KD7HB)\
**Post date:** [November 29, 2022, 4:53pm UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/15 "2022-11-29T16:53:40Z")

</div>

You should forget about the dB calculation until you get the raw values working properly. Use serial.Print() of the raw values and see how they change with the sound level. When they are satisfactory, then begin the dB calculations.

---

<div class="post-metadata">

**Author:** ![anon57585045](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@anon57585045](https://forum.arduino.cc/u/anon57585045)\
**Post date:** [November 29, 2022, 4:57pm UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/16 "2022-11-29T16:57:06Z")

</div>

You have no current limiting resistors on the LEDs. There is a good chance that can destroy the ESP output pins.

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [November 29, 2022, 6:02pm UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/18 "2022-11-29T18:02:05Z")

</div>

> [@aidid](#):
>
> still get analog value more than 1023, may I know how it can happened even I reduce to 10 bit. below is the serial monitor

The Arduino IDE may not have properly set the ESP32's ADC API.

You can use the ESP32's AD API to access the ESP32's ADC.

---

<div class="post-metadata">

**Author:** ![aidid](https://avatars.discourse-cdn.com/v4/letter/a/a3d4f5/32.png) [@aidid](https://forum.arduino.cc/u/aidid)\
**Post date:** [November 30, 2022, 11:37am UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/19 "2022-11-30T11:37:05Z")

</div>

![image](https://europe1.discourse-cdn.com/arduino/original/4X/c/9/0/c901356d3074a9bb95da9acaa3f1d0ef59e94fa0.png)  
this picture show the raw data I obtained by using the code as shown below.

```cpp
const byte sensorpin = 35;
void setup() {
 pinMode (sensorpin, INPUT);
 Serial.begin (115200);
}

void loop() {
 int sample;
 sample=analogRead(sensorpin);
 Serial.println(sample);
delay(100);
}

```

Throughout the test i increase my speaker volume from 0 to 80% and I saw a big difference happened on 80% but the signal value is not up to 4096 (12 bit is default in esp32 right). so why the value is not close to 4000 after increasing the sound. I use vcc 5v.

---

<div class="post-metadata">

**Author:** ![JohnLincoln](https://avatars.discourse-cdn.com/v4/letter/j/7ba0ec/32.png) [@JohnLincoln](https://forum.arduino.cc/u/JohnLincoln)\
**Post date:** [November 30, 2022, 12:33pm UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/20 "2022-11-30T12:33:23Z")

</div>

> [@aidid](#):
>
> Throughout the test i increase my speaker volume from 0 to 80% and I saw a big difference happened on 80% but the signal value is not up to 4096 (12 bit is default in esp32 right). so why the value is not close to 4000 after increasing the sound. I use vcc 5v.

The opamp ([LM2904](https://www.ti.com/lit/ds/symlink/lm2904b.pdf?ts=1669811064786&ref_url=https%253A%252F%252Fwww.ti.com%252Fproduct%252FLM2904B)) used in the sensor board does not have a rail to rail output. So the output will not go as high or as low as you expect.

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [November 30, 2022, 12:51pm UTC](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863/21 "2022-11-30T12:51:12Z")

</div>

The sound sensor may not have rail-to-rail capabilities.

Put 3V3 onto the AD pin and see what reading you get.

[Next page](https://forum.arduino.cc/t/sound-sensor-results-high-reading/1058863.md?page=2)
