# SPL Meter using Wemos D1 mini

**URL:** <https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864>\
**Category:** General Guidance\
**Created:** [May 30, 2023, 11:48pm UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864 "2023-05-30T23:48:32Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![fedefranke97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/fedefranke97/32/920931_2.png) [@fedefranke97](https://forum.arduino.cc/u/fedefranke97)\
**Post date:** [May 30, 2023, 11:48pm UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/1 "2023-05-30T23:48:32Z")

</div>

Hello everyone!

I'm a biomedical engineering student working on a project, where I need to develop a sound pressure meter for an intensive care environment. My goal is to measure noise levels in decibels (dB) using a prototype with a Wemos D1 Mini board and a MAX4466 sensor.

In addition to the doubts about sampling and data processing that I mentioned earlier, I would like to know if my current hardware is suitable for achieving these goals or if there are any limitations I should consider. Are the Wemos D1 Mini and MAX4466 sensor suitable for accurately and reliably sampling sound at 44.1 kHz? Are there any hardware limitations or special considerations I should be aware of when working with these devices?

I have an initial code for sound sampling, but I suspect that I am not achieving the proper sampling time to reach the required 44.1 kHz. Currently, I am using a "delay" in my code, but I know that this is not the best option to achieve accurate sampling frequency.

```arduino
/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/8768649e-d5da-4a65-ab9d-f11ea0b5e85c 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  float aDC;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

//float aDC;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 

  // read the input on analog pin 0:
  aDC = analogRead(A0);
  // print out the value you read:
  Serial.println(aDC);

  delay(125);
  
}

```

I would like to know what modifications I can make in my code to meet the desired sampling time according to the 44.1 kHz requirement. Are there any specific functions or techniques I should consider to achieve precise sampling?

I would greatly appreciate any guidance or advice you can provide. Thank you very much!

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [May 31, 2023, 12:08am UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/2 "2023-05-31T00:08:53Z")

</div>

> [@fedefranke97](#):
>
> I would like to know if my current hardware is suitable for achieving these goals

Practical testing is needed. Nobody can tell for sure based on Your post.

> [@fedefranke97](#):
>
> Are the Wemos D1 Mini and MAX4466 sensor suitable for accurately and reliably sampling sound at 44.1 kHz?

Set it up and test. Theoretical investigations would likely be too time consuming.

---

<div class="post-metadata">

**Author:** ![aldr3i](https://avatars.discourse-cdn.com/v4/letter/a/77aa72/32.png) [@aldr3i](https://forum.arduino.cc/u/aldr3i)\
**Post date:** [May 31, 2023, 1:13am UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/3 "2023-05-31T01:13:56Z")

</div>

have a look at commercially available sensors that are already used in intensive care environments then compare specs with your sensor.

---

<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:** [May 31, 2023, 2:07am UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/4 "2023-05-31T02:07:37Z")

</div>

The sample rate isn't that critical. High frequencies are normally weak (with natural sounds) and with a real SPL meter they are attenuated in the measurement ([A-weighting](https://en.wikipedia.org/wiki/A-weighting#:~:text=A-weighted%20SPL%20measurements%20of%20noise%20level%20are%20increasingly,also%20used%20for%20noise%20dose%20measurements%20at%20work.)) to account for the fact that our ears are most sensitive at mid-frequencies.

If your measurements are not weighted you can just find the peaks over a short period of time without worrying about about the sample rate.

> [@fedefranke97](#):
>
> In addition to the doubts about sampling and data processing that I mentioned earlier, I would like to know if my current hardware is suitable for achieving these goals or if there are any limitations I should consider.

**There are lots of "complications"** that make it impractical, if not impossible, to make an SPL meter for regulatory, health & safety, or legal purposes.

That said, I made an [SPL Meter](https://forum.arduino.cc/t/sound-sensor-which-one/962327/6) with different hardware. There are lots of comments and notes regarding the complications. (It's very simple and I don't do any weighting.)

---

<div class="post-metadata">

**Author:** ![fedefranke97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/fedefranke97/32/920931_2.png) [@fedefranke97](https://forum.arduino.cc/u/fedefranke97)\
**Post date:** [May 31, 2023, 11:34pm UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/5 "2023-05-31T23:34:10Z")

</div>

What I learned from the test was that I had very few samples using the delay (125). I tried using a sample time of 1/44100 and that allowed me to get more samples. My doubt is in the level of accuracy.

---

<div class="post-metadata">

**Author:** ![fedefranke97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/fedefranke97/32/920931_2.png) [@fedefranke97](https://forum.arduino.cc/u/fedefranke97)\
**Post date:** [May 31, 2023, 11:50pm UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/6 "2023-05-31T23:50:03Z")

</div>

Well they are not weighted in Arduino, I figured that I could obtain an Excel with all the data and export it to Matlab, where I can do the signal processing. The main issue is that it prevents me from having real time measurements, which I want.  
I guess my main doubt is if I can sample the sound and do the signal processing with any library in Arduino so I can have the real time dB levels.

---

<div class="post-metadata">

**Author:** ![Railroader](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/railroader/32/274550_2.png) [@Railroader](https://forum.arduino.cc/u/Railroader)\
**Post date:** [June 1, 2023, 6:51pm UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/7 "2023-06-01T18:51:50Z")

</div>

> [@fedefranke97](#):
>
> My doubt is in the level of accuracy.

That's impossible for us to tell anything about. You need to compare Your values with the values from a reference device.

---

<div class="post-metadata">

**Author:** ![Wawa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wawa/32/1211303_2.png) [@Wawa](https://forum.arduino.cc/u/Wawa)\
**Post date:** [June 1, 2023, 9:04pm UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/8 "2023-06-01T21:04:40Z")

</div>

Taking a snapshot of a sound wave won't do it.  
Forget about an analogue microphone and the crappy A/D of an ESP.

I think you should use some sort of **[MEMS microphone with digital I2S output](https://www.adafruit.com/product/3421)** (!= I2C).  
And an ESP32, with hardware I2S, and FFT code.  
Can't help you with that, but **[this page](https://dronebotworkshop.com/esp32-i2s/#I2S_Microphone_with_ESP32)** could be a start.  
Leo..

---

<div class="post-metadata">

**Author:** ![fedefranke97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/fedefranke97/32/920931_2.png) [@fedefranke97](https://forum.arduino.cc/u/fedefranke97)\
**Post date:** [June 6, 2023, 12:12am UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/9 "2023-06-06T00:12:12Z")

</div>

I've consider using a MEMS mic, but it's very hard to find it in my country and the import laws are a mess, that's why I have chosen this technology.

---

<div class="post-metadata">

**Author:** ![fedefranke97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/fedefranke97/32/920931_2.png) [@fedefranke97](https://forum.arduino.cc/u/fedefranke97)\
**Post date:** [June 6, 2023, 11:22pm UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/10 "2023-06-06T23:22:37Z")

</div>

Do you know how to test if the ADC of the board can sample at 44100KHz?

---

<div class="post-metadata">

**Author:** ![Wawa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wawa/32/1211303_2.png) [@Wawa](https://forum.arduino.cc/u/Wawa)\
**Post date:** [June 7, 2023, 1:08am UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/11 "2023-06-07T01:08:14Z")

</div>

Maybe. I have seen sample times of 10us on the net.  
But not at a constant rate with a single core CPU, and not at 16-bit depth.  
I think you're on your own if you follow the path you're on.  
Leo..

---

<div class="post-metadata">

**Author:** ![fedefranke97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/fedefranke97/32/920931_2.png) [@fedefranke97](https://forum.arduino.cc/u/fedefranke97)\
**Post date:** [June 9, 2023, 10:51pm UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/12 "2023-06-09T22:51:15Z")

</div>

Hi Wawa, fortunately I was loaned a MEMS microphone. In this case i will be using a STEVAL MKI155V2. On the page you attached i saw that the code uses the library \<driver/i2s.h\>, do you know if this library works with a esp8266?

---

<div class="post-metadata">

**Author:** ![Wawa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wawa/32/1211303_2.png) [@Wawa](https://forum.arduino.cc/u/Wawa)\
**Post date:** [June 11, 2023, 1:28am UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/13 "2023-06-11T01:28:49Z")

</div>

ESP8266 does not have I2S I/O, only the ESP32 does.  
Never used I2S on an ESP32, but it should work.  
Leo..

---

<div class="post-metadata">

**Author:** ![fedefranke97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/fedefranke97/32/920931_2.png) [@fedefranke97](https://forum.arduino.cc/u/fedefranke97)\
**Post date:** [June 13, 2023, 12:21am UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/15 "2023-06-13T00:21:54Z")

</div>

From what i gather esp8266 is able to work with the I2S protocol because of the GPIO pins

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/0/1/4/01481613b4409f15e0656ed54f8a91c26bfa0242.jpeg)  
I know that ESP 32 is able to work with I2S, but why you think it wouldt work with esp8266

---

<div class="post-metadata">

**Author:** ![Wawa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wawa/32/1211303_2.png) [@Wawa](https://forum.arduino.cc/u/Wawa)\
**Post date:** [June 13, 2023, 1:20am UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/16 "2023-06-13T01:20:28Z")

</div>

Seems you're right. I saw examples on the net where I2C is used with the ESP8266.  
Leo..

---

<div class="post-metadata">

**Author:** ![fedefranke97](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/fedefranke97/32/920931_2.png) [@fedefranke97](https://forum.arduino.cc/u/fedefranke97)\
**Post date:** [June 13, 2023, 1:34am UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/17 "2023-06-13T01:34:24Z")

</div>

Could you attach the links to the examples?

---

<div class="post-metadata">

**Author:** ![Wawa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wawa/32/1211303_2.png) [@Wawa](https://forum.arduino.cc/u/Wawa)\
**Post date:** [June 13, 2023, 1:58am UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/18 "2023-06-13T01:58:18Z")

</div>

Not a lot out there for the ESP8266.  
Most projects go straight for the 2-core ESP32.  
**[Here you go.](https://letmegooglethat.com/?q=ESP8266+I2S)**  
Leo..

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 10, 2023, 1:58am UTC](https://forum.arduino.cc/t/spl-meter-using-wemos-d1-mini/1132864/19 "2023-12-10T01:58:58Z")

</div>

Closed on December 10, 2023, 1:58am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
