ESP32 Industrial Noise Monitor with Touch Screen

Here is a quick demonstration of the capabilities of our advanced I2C flex sound meter module. In this article, we show how you can implement a simple ESP32 industrial noise monitor with GUI using an off-the-shelf development board and our sensor module.

esp32 industrial noise monitor display and sensor
Industrial noise monitor with ESP32 and PCB Artists decibel sensor

Hardware Required

To keep things as minimal as possible with this demo, we picked a highly integrated ESP32 development board with a high resolution LCD display and touch screen.

The Waveshare development board is very popular and easily available in several countries.
Connecting the PCBA-DBM-FLEX module to the Waveshare board is very easy – you just need to connect the 3.3V, SCL, SDA, and GND lines.

Development Environment Setup

To keep the development process as simple and quick as possible, we used the exact setup and guidelines provided by Waveshare. Note that the development environment is ESP-IDF.
  • GUI design was done in SquareLine Studio, a great tool for quick design with LVGL
  • Display driver and LVGL driver code as provided by Waveshare (for ESP-IDF)
  • VS Code for code editing, command line and building. You can use anything you like.

GUI Design with SquareLine Studio

The GUI for the ESP32 noise monitor is designed in SquareLine Studio, which provides a very useful drag-and-drop interface. Instead of figuring out widget dimensions and positioning yourself, SquareLine is a huge time saver and lets you see what you will get when you run your GUI on the ESP32.

The basic parameters that we need to display on the screen are listed below.
These parameters are directly read from the PCB Artists sound sensor, the ESP32 does no calculations.

  • A-weighted, time-weighted sound level (slow mode)
    This is what regular sound level meters show when you set the meter to slow mode and A-weighting.
    This value is shown on a bar to make it easy to interpret. Range is 30 dB to 130 dB.
  • LCpeak
    The peak sound level, or LCpeak, is the maximum pressure of the C-weighted physical sound wave in dB SPL
  • LAmin and LAmax
    The minimum and maximum value as seen by the monitor are marked on the sound level display bar
  • Time over threshold
    The number of seconds where the LAeq level of sound was higher than the set threshold, 85 dBA in this case
  • Statistical data
    An LAeq plot over the most recent minute, hour, and 12 hours.
esp32 industrial noise monitor gui squareline studio
GUI Layout for the Noise Monitor in SquareLine Studio

You can download the SquareLine Studio project here to get started quickly.
Note that you do not need to download this project file and generate the GUI source code files. There is a full ESP-IDF project made available for download later in the article that you can simply build and run.

Application Source Code (ESP-IDF)

The ESP32 industrial noise monitor application code simply reads the parameters available on the I2C sound meter module and plots the results out on the LCD display. No calculations are performed by the ESP32 itself.

On tapping the “Clear Markers” button, the ESP32 sends a command to the sound meter module to clear the peak and min/max values.

On tapping the “Clear History” button, the ESP32 sends a command that clears history buffers of all data.

To build the project, make sure that you have ESP-IDF v.5.3.0 installed on your PC. Assuming a Windows PC, you can build the project by launching the IDF command prompt, opening the project directory and building it.

$ cd dbm_flex_espidf_project
$ idf.py build

To flash the firmware to your Waveshare board via COM port x, use
$ idf.py build flash -b 921600 monitor -p COMx

If the sensor is connected correctly to your Waveshare dev board, the GUI should come up immediately after flashing is complete. The sensor revision and unique ID will be displayed.

C Files and Brief Descriptions

The application source code is contained in the main folder. The components folder contains components used by the application. You will not need to edit anything in the components folder.
Within the main folder are the following files.

  • decibel_meter_main.c
    Main code and app_main() routine for the ESP32 sound monitor application. Code in this file initializes the LCD, touch interface, etc. It also contains a task that reads the sound sensor at 10 Hz and updates the display elements.
  • dbm_flex.c / dbm_flex.h
    Driver file for the PCB Artists advanced I2C sound level meter module. They contain functions for performing basic functions such as reading latest sensor values and configuring the sensor.
  • lvgl_demo_ui.c, ui_comp_hook.c, ui_events.h, ui_helpers.c/.h, ui_Screen1.c, ui.c/.h
    Files generated by SquareLine Studio that contain routines for handling and rendering the GUI elements. These do not need to be edited. If you make a change to the GUI within SquareLine, you will need to export the GUI to source code and update these files in the project.

Main C Code Snippet

Within decibel_meter_main.c, the task responsible for reading the sensor and updating the GUI is the following.

// Main task to update values on the display at 10 fps
static void dbm_task(void *arg)
{
    dbm_flex dbm;

    // Chart buffers and series
    lv_chart_series_t *ser_sec, *ser_min, *ser_hrs;
    uint8_t chart_sec_data[60], chart_min_data[60], chart_hrs_data[12];
    lv_coord_t lvchart_sec_data[60], lvchart_min_data[60], lvchart_hrs_data[12];

    // Get dbm module details
    esp_err_t err = dbmeter_get_version_id (I2C_MASTER_NUM, &dbm);
    if (err != ESP_OK)
    {
        ESP_LOGW (TAG, "dbm_flex not connected, connect module and restart");
        while (1)
            vTaskDelay (10);
    }
    else
    {
        ESP_LOGW (TAG, "dbm_flex version is 0x%02X", dbm.version);
    }

    example_lvgl_lock(-1);
    ser_sec = lv_chart_get_series_next (ui_ChartSec, NULL);
    ser_min = lv_chart_get_series_next (ui_ChartMin, NULL);
    ser_hrs = lv_chart_get_series_next (ui_ChartHour, NULL);
    
    // Set ID and version text
    char id_str[64];
    sprintf (id_str, "Rev: %02X, UID: %08X", dbm.version, (unsigned int)dbm.id);
    lv_label_set_text(ui_LabelUID, id_str);

    // Add button callbacks
    lv_obj_add_event_cb (ui_ButtonClrPeak, ui_ButtonClrPeak_click_cb, LV_EVENT_CLICKED, NULL);
    lv_obj_add_event_cb (ui_ButtonClrHistory, ui_ButtonClrHistory_click_cb, LV_EVENT_CLICKED, NULL);
    example_lvgl_unlock();

    // Clear the sensor min/max/peak to remove "pop" effects of power-up
    dbmeter_clear_data (I2C_MASTER_NUM, DBM_CLR_MAXMIN|DBM_CLR_HISTORY|DBM_CLR_OVERUNDER|DBM_CLR_LPK);

    // Run this loop every 100 ms (display readings are refreshed 10 times/sec)
    while (1)
    {
        // Update decibel data structure with parameters needed for this demo
        dbmeter_update_params (I2C_MASTER_NUM, &dbm,
            DBM_PARAM_DB | DBM_PARAM_LPK | DBM_PARAM_LMAXMIN | DBM_PARAM_TSTATS);

        // Fetch seconds history
        dbmeter_read_history_sec (I2C_MASTER_NUM, chart_sec_data);
        for (uint8_t i=0; i<60; i++)
            lvchart_sec_data[i] = chart_sec_data[i];

        // Fetch minutes history
        dbmeter_read_history_min (I2C_MASTER_NUM, chart_min_data);
        for (uint8_t i=0; i<60; i++)
            lvchart_min_data[i] = chart_min_data[i];

        // Fetch hours history
        dbmeter_read_history_hrs (I2C_MASTER_NUM, chart_hrs_data);
        for (uint8_t i=0; i<12; i++)
            lvchart_hrs_data[i] = chart_hrs_data[i];

        // Update T over value
        char tover_str[64];
        sprintf(tover_str, "%d", (unsigned int)dbm.seconds_over);

        // Refresh parameters with new values for the screen
        example_lvgl_lock(-1);

        // Update dBA,slow value
        lv_bar_set_value(ui_BardBA, dbm.dBA, LV_ANIM_ON);
        char dbval_str[16];
        sprintf(dbval_str, "%2.1f dB SPL", dbm.dBA);
        lv_label_set_text(ui_LabeldBA, dbval_str);

        // Update min, max and peak markers under the dBA bar
        // X axis for markers is -147 + 5* val
        // LAmax is ^ in red
        lv_obj_set_x(ui_LabelLAmax, -147 + 5*(dbm.LAmax-30));
        // LAmin is ^ in green
        lv_obj_set_x(ui_LabelLAmin, -147 + 5*(dbm.LAmin-30));
        // LCpeak is | in white
        lv_obj_set_x(ui_LabelLCpeak, -147 + 5*(dbm.LCpk-30));

        // Update time-over seconds count
        lv_label_set_text(ui_LabelTover, tover_str);

        // Update seconds chart
        lv_chart_set_ext_y_array(ui_ChartSec, ser_sec, lvchart_sec_data);
        lv_chart_refresh (ui_ChartSec);

        // Update minutes chart
        lv_chart_set_ext_y_array(ui_ChartMin, ser_min, lvchart_min_data);
        lv_chart_refresh (ui_ChartMin);

        // Update hour chart
        lv_chart_set_ext_y_array(ui_ChartHour, ser_hrs, lvchart_hrs_data);
        lv_chart_refresh (ui_ChartHour);
        example_lvgl_unlock();

        // Wait for 100 ms before looping again
        vTaskDelay (100/portTICK_PERIOD_MS);
    }
}

Meeting Practical Industrial Noise Monitoring Standards

Using the advanced flex decibel sensor unlocks a whole bunch of features that will let you build a “real” industrial noise monitoring solution. Rather than being a simple system that measures basic parameters like A-weighted, time-weighted decibel values, the simultaneous parameters that the PCBA-DBM-FLEX module acquires can help with meeting several standards listed below.

Although the module does not have the ability to measure extremely high levels like LCpeak of 140 dB expected by OSHA, this setup can still be used in moderate noise environments to ensure compliance. This makes this ESP32 industrial noise monitor usable in several noise at work applications.

OSHA Standards in the USA

OSHA defines some noise exposure limits to protect workers from risks associated with high noise exposure. This ESP32 industrial noise monitor can be used to measure parameters required for OSHA compliance.

  • Time-weighted average (TWA) noise level measurement is possible with this setup
  • LCpeak can be acquired from the module, as required by OSHA guidelines
  • Threshold tracking enables you to record exposure to loud sounds and calculate adjusted noise exposure

NIOSH Recommendations in the USA

NIOSH recommends that an 8-hours shift should have an exposure limit of 85 dBA. It also recommends a 3dB exchange rate, which means that the exposure is considered as doubled every 3 dB.

  • NIOSH noise exposure and exchange rate can be calculated using this setup as it reads LAeq value with a time interval of 1 hour over 12 hours. The module uses accurate continuous integration as required by NIOSH guidelines.
  • Dosimeter capabilities and data logging with a precision of 1 second allows accurate tracking of noise levels.
  • LAmax and LAmin can provide useful insights into the maximum and minimum sound level experienced.

ISO 1999 and ISO 9612

  • The ability to read LAeq, LAmax, and LCpeak support meeting ISO 1999 guidelines.
    ISO 1999 (Acoustic Measurement of Noise Exposure in the Workplace) outlines estimation of noise-induced loss of hearing using exposure data.
  • Ability to record 12 hour history of integrated sound levels with adjustable precision and threshold-crossing statistics align with ISO 9612 requirements.

European Union Directive 2003/10/EC

The EU 2003/10/EC directive mandates hearing protection and worker training based on workplace noise levels.

  • LAeq and LCpeak measurements allow compliance monitoring
  • Threshold tracking can be useful to produce useful data to implement compliance

AS/NZS 1269.1:2005 in Australia and New Zealand

  • This setup makes it possible to read LAeq and LCpeak in addition to hourly noise levels, making it easy to implement workplace noise management.

Change Log

  • 22 November 2024
    – Initial release

You may also like

Leave a Comment

six + 17 =