SCP v30 13 Noise Level Sensor V2

This is the basic code to manage and read the Noise Level Sensor V2.

Required Materials

1 x Waspmote 1 x Battery 1 x Smart Cities PRO board 1 x NLS V2

Notes

- Remember to connect the battery to Waspmote for proper operation. - The connection of the sensor is described in the Smart Cities PRO technical guide. - Cycle time: 2 minutes

Code

 /*  
 *  ------------  [SCP_v30_13] - Noise Level Sensor V2  -------------- 
 *  
 *  Explanation: This is the basic code to manage and read the noise 
 *  level sensor. The sensor can be configured at: 
 *  SLOW (1 second of measuring) and 
 *  FAST (125 milliseconds of measuring).
 *  CONTINOUS (average of custom time)
 *  
 *  Copyright (C) 2022 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify  
 *  it under the terms of the GNU General Public License as published by  
 *  the Free Software Foundation, either version 3 of the License, or  
 *  (at your option) any later version.  
 *   
 *  This program is distributed in the hope that it will be useful,  
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of  
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
 *  GNU General Public License for more details.  
 *   
 *  You should have received a copy of the GNU General Public License  
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  
 * 
 *  Version:    1.0 
 *  Design:     Heimdal laHoz, Cristian Montoya.
 */


#include <WaspSensorCities_PRO.h>

/*
   P&S! Possibilities for this sensor:
    - SOCKET_A
*/

uint8_t status;

void setup()
{
  USB.ON(); 
  USB.println(F("Reading Noise Level Sensor"));
}


void loop()
{
  
  /////////////////////////////////////////////////////////////////
  // 1. Configure the sensor for UART communication
  /////////////////////////////////////////////////////////////////
  noiseV2.configure();
  delay(200);

  ///////////////////////////////////////////
  // 2. Read sensor
  ///////////////////////////////////////////
  
  //SLOW MODE
  // Get a new measure of the SPLA from the noise sensor
  status = noiseV2.get(LAS_MODE);

  if (status == 0) 
  {
    USB.print(F("Sound Pressure Level with A-Weighting (SLOW): "));
    USB.printFloat(noiseV2.SPLA,2);
    USB.println(F(" dBA"));
  }
  else
  {
    USB.println(F("Communication error. No response from the audio sensor "));
  }
  delay(100);


//FAST MODE
// Get a new measure of the SPLA from the noise sensor
  status = noiseV2.get(LAF_MODE);

  if (status == 0) 
  {
    USB.print(F("Sound Pressure Level with A-Weighting (FAST): "));
    USB.printFloat(noiseV2.SPLA,2);
    USB.println(F(" dBA"));
  }
  else
  {
    USB.println(F("Communication error. No response from the audio sensor"));
  }
  delay(100);


  //CONTINUOUS MODE
  // Get a equivalent coninuous measure of the SPLA from the noise sensor during 60 seconds
  status = noiseV2.getAverage(60000);

  if (status == 0) 
  {
    USB.print(F("Sound Pressure Level with Equivalent continuous is the average (LAEq): "));
    USB.printFloat(noiseV2.SPLA,2);
    USB.println(F(" dBA"));
  }
  else
  {
    USB.println(F("Communication error. No response from the audio sensor"));
  }
  delay(100);  

  ///////////////////////////////////////////
  // 3. Sleep
  ///////////////////////////////////////////

  // Go to deepsleep
  // After 30 seconds, Waspmote wakes up thanks to the RTC Alarm
  USB.println(F("Enter deep sleep mode"));
  PWR.deepSleep("00:00:00:30", RTC_OFFSET, RTC_ALM1_MODE1, ALL_ON);
  USB.ON();
  USB.println(F("wake up!!"));
}

Output

J#
Reading Noise Level Sensor
Sound Pressure Level with A-Weighting (SLOW): 43.30 dBA
Sound Pressure Level with A-Weighting (FAST): 38.80 dBA
Sound Pressure Level with Equivalent continuous is the average (LAEq): 52.90 dBA
Enter deep sleep mode
wake up!!

Last updated