Example Code for Arduino-Measure Sound Level(dBA)
Last revision 2026/01/07
The article offers a detailed guide on measuring sound level using an Arduino board with Gravity: Analog Sound Level Sensor. It covers necessary hardware and software preparations, wiring diagrams, and sample code to help users accurately capture and calculate sound levels in decibels (dBA).
Hardware Preparation
- SEN0232 Gravity: Analog Sound Level Sensor x1
- DFR0216-2 DFRduino UNO R3 with IO Expansion Shield and USB Cable A-B x1
- FIT0897 Gravity: Analog Sensor Cable for Arduino(Included with SEN0232) x1
Software Preparation
- Download Arduino IDE: Click to Download Arduino IDE
Wiring Diagram

Other Preparation Work
Caution
- In order to protect the microphone on the board, you should not touch the black membrane on the microphone. Also you should keep it clean.
- Please do not place this module on the surface of conductor or semiconductor. Otherwise, this will cause the microphone pin to be shorted.
Sample Code
/***************************************************
DFRobot Gravity: Analog Sound Level Meter
<https://www.dfrobot.com/wiki/index.php/Gravity:_Analog_Sound_Level_Meter_SKU:SEN0232>
***************************************************
This sample code is used to test the analog sound level meter.
Created 2017-06-26
By Jason <[email protected]@dfrobot.com>
GNU Lesser General Public License.
See <http://www.gnu.org/licenses/> for details.
All above must be included in any redistribution
****************************************************/
/***********Notice and Trouble shooting***************
1. This sample code is tested on Arduino Uno with Arduino IDE 1.0.5 r2.
2. In order to protect the microphone on the board, you should not touch the black membrane on the microphone. Also you should keep it clean.
3. Please do not place this module on the surface of conductor or semiconductor. Otherwise, this will cause the microphone pin to be shorted.
****************************************************/
#define SoundSensorPin A1 //this pin read the analog voltage from the sound level meter
#define VREF 5.0 //voltage on AREF pin,default:operating voltage
void setup()
{
Serial.begin(115200);
}
void loop()
{
float voltageValue,dbValue;
voltageValue = analogRead(SoundSensorPin) / 1024.0 * VREF;
dbValue = voltageValue * 50.0; //convert voltage to decibel value
Serial.print(dbValue,1);
Serial.println(" dBA");
delay(125);
}
Result

Was this article helpful?
