Detect Noise Level Audio Decibels in MXChip Azure IoT DevKit

Playing with Azure IoT DevKit MXChip is always fun, the device has many capabilities. For the past few days, I have been working with some of the capabilities of this device like Atmospheric pressure, Temperature, Humidity through its Sensors. In this Article, I will show you how you can calculate the noise level using the microphone of AZ3166 IoT Device. Now let’s start implementing the same. I hope you will like it.


Background

In our last article, we have already seen how to read the temperature, humidity, atmospheric pressure from the MXChip AZ3166 sensors and send those to our Azure IoT Hub. Here in this article let’s do the following tasks.

  1. Find the Noise level using the AudioClassV2 class

  2. Send the Values to our IoT Hub

  3. Configure the Existing Angular application with a new component to show Decibel values

Source Code

Please feel free to play around with this repository.


Using the Code

Once you have your own workspace, we can open the solution in VSCode and start coding.


main.ino

This is our solution starting point, every project must have its own sketch file, usually, this file will be contained at least the functions loop() and setup().


Before we get started, let’s include the header files we are going to use.

//Header files - Start//
#include "AZ3166WiFi.h"
#include "AzureIotHub.h"
#include "DevKitMQTTClient.h"
#include "config.h"
#include "utility.h"
#include "SystemTickCounter.h"
#include "RingBuffer.h"
#include "parson.h"
#include "EEPROMInterface.h"
#include "http_client.h"
#include <Arduino.h>
#include <stdio.h>
#include <math.h>
#include "OledDisplay.h"
#include "AudioClassV2.h"
#include "stm32412g_discovery_audio.h"
#include "RGB_LED.h"
#include <stdint.h>

#define MFCC_WRAPPER_DEFINED
#include "featurizer.h"
//Header files - End//
//**********************//

Now we can declare our constants and variables.

//Constants and variables- Start//
enum AppState{  
    APPSTATE_Init,  
    APPSTATE_Error,  
    APPSTATE_Recording
};

static AppState appstate;
// These numbers need to match the compiled ELL models.