ChangeLog

15 of June 2024

  • initial release

DFRobot / Gravity Analog Sound Meter 1.0

This template is for the Gravity Analog Sound Meter released by DFRobot. The code has some boilerplate functionality where the template is able to connect to a designated Wifi network, as well as listen to over the wire OTP updates, whilst continuously polling the Gravity Analog Sound Meter and publishing the measured value to an MQTT bus.

Usage

At the time of writing, there is no runtime functionality and the template should just be modified in order to set the Wifi and/or OTP credentials after which it can be wired up and left to run on its own.

Theory

The theory behind the template revolves around the linear design of the Analog Sound Meter in that the output voltage is calibrated out of production to correspond to some amount of decibels. As per the specifications, the noise level that the Analog Sound Meter is capable of registering ranges from $30dBA$ to $130dBA$ with those two values corresponding to $0.6V$, respectively the maximum voltage that the analog pin is capable of reading (for most micro-arduinos, such as the WeMoS, that would be $3.3V$). Given the linear progression, the only thing left to do is just measure the voltage of the analog pin connected to the meter's signal pin and then linearly map the voltage range $0.6..3.3V$ into the decibels range $30...130dB$.

Here is the code responsible for measuring noise levels using DFRobot's Gravity Analog Sound Level Meter 1.0 within the template provided in the code section:

// https://grimore.org/fuss/mathematics/algebra#linearly_map_a_value_in_a_range_into_another_range
float mapValueToRange(float value, float xMin, float xMax, float yMin, float yMax) {
  return yMin + ((yMax - yMin) * (value - xMin)/(xMax - xMin));
}
 
  // measure noise level (dbA)
  float ai, vc, noise;
  ai = analogRead(DECIBELMETER_PIN_ANALOG);
  vc = mapValueToRange(ai, 0, 4095, 0, MAX_ANALOG_VOLTAGE);
  noise = vc * 50.0;

where:

  • DECIBELMETER_PIN_ANALOG is the analog pin that the Analog Sound Level Meter connects to on the ESP,
  • MAX_ANALOG_VOLTAGE is the maximum in voltage on the ESP (sometimes ranges from $0V$ to $3.3V$ but can also range from $0V$ to $5V$)

As can be observed, after the value from the analog pin is measured, the value is mapped to the voltage range of the pin. The resulting scaled voltage is then multiplied by $50.0$, which is a cheap operation compared to mapValueToRange that is meant to scale the measured voltage to the decibel range, based on the observation that the lowest voltage $0.6V$ corresponding to the lowest amount of decibels that the board can measure, when multiplied by $50.0$ yield a nice lowest decibel value of $30dbA$.

Aside the boilerplate Arduino code, the former short snippet is the whole nucleus that is responsible of measuring the noise level that is characteristic to the provided template in the code section.

Code

Unable to display file "http://svn.grimore.org/arduino-sketches/arduinoAnalogSoundMeter/arduinoAnalogSoundMeter.ino": It may not exist, or permission may be denied.


arduino/analog-sound-meter.txt ยท Last modified: 2024/06/15 07:26 by office

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.