Sound level sensor

I work from home and I'm on the phone all day. My kids cannot seem to understand that they cannot yell or scream, I have to tell them no less than 5 times per day. Usually it's when they are playing the PS4.

So, I want to plug the PS4 into a smart plug, and use a sound level sensor in a Rule that will shut off the smart plug if they yell or scream. Other than kicking them out of the house for the whole day, this seems like it's going to be the only way to change their behavior.

Is there anything out there I can use? Preferably something that has decibels as an attribute?

2 Likes

There is some sensors like this one.

They are pretty dumb. It will tell you there is a sound or no sound.

There is also something smarter by measuring the sound like this one.

If you are looking something smarter than that (like recognizing whose making the sound, Is it human conversation), you may have to DIY yourself. It is do-able. But not easy.

Once you choose your sensor, you can use Arduino to send the information to your hub. Look at HubDuino. @ogiewon can hook you up with a DTH.

Or, If you are looking to use a Zigbee, you can use one of my module to send information from the above sensors too.

I hope it help. I am not sure that there is an out of the box sound sensor.

1 Like

I don't have ready to run sound level measurement solution/idea... You could use HubDuino to add such a device, especially one that simply outputs an analog signal. You could just use the PS_Voltage device within HubDuino to read the value. If you pick a sensor, I can help you integrate it into HubDuino.

As for shutting down the Playstation 4...perhaps you could simply use a Logitech Harmony Hub to turn off the TV/Sound System instead of killing power to the PS4? Electronics/Computers do not like having their power cycled. I worry that doing so may eventually damage the PS4.


A completely different solution might be to use something like this device... Highly effective at reducing loud outbursts! :wink:

https://www.amazon.com/Rechargeable-Adjustable-Sensitivity-Intensity-Harmless/dp/B07RJV7SW6/ref=sr_1_8?keywords=bark+collar&qid=1562090634&s=gateway&sr=8-8

:wink: Obviously, this is just a JOKE! Please do not electrically shock your children!!! :wink:

12 Likes

Do you have a Harmony hub for the system the PS4 is on? If so, you have a phone app remote. You can simply open the remote and turn it down.

I use my HH to run a power up/down sequence for my home theater and entertainment stack. I have it integrated with Google. I wish I had it integrated directly with HE, but no joy there. Maybe someday.

The harmony hub won't turn down his KIDS... Which are the things he wants to turn down (in this case by turning off their PS4 that is getting them too riled up).

Have you considered that just turning the PS4 off without letting them save their game might get them more riled up in the short term? You might even cause a riot. :stuck_out_tongue:

I'm sure that will happen the first couple of times. I'm actually going to start with turning off the TV only for 15 mins. Cutting power to the ps4 risks disk corruption.

3 Likes

I ended up ordering a bark collar. J/K. :slight_smile: I got that dfrobot SPL board. It should be here next week. I have some esp8266-like devices with an oled screen on them. I'll add code that displays the current SPL, the alarm SPL, and a couple of buttons to adjust the setpoint up and down.

1 Like

No, but if it is connected to a home theater amp/receiver, it will.

Ok, so I got the board, and I'm hooking it up to a LoLin32 arduino board with an integrated OLED display. I compiled one of the sample ESP32 sketches from the Hubduino package and successfully loaded it on the LoLin32 board. I can ping it, and all seems to be fine.

However, I noticed the the Hubduino supports only specific sensor types, and of course none of those are a sound pressure level sensor. :slight_smile: So, the way I look at it, I have a couple of options:

  1. Just put in some arduino code to monitor the sensor, and then set it up so it looks like a contact sensor to the HE. When the contact trips, this means it has exceeded the sound threshold. I'll still display the current SPL on the OLED display, and the setpoint for alarm (adjustable with 2 buttons to move the setpoint up and down)
  2. Create a new device type for Hubduino which can pull back the SPL data. Frankly, I really have no need to display this data in the HE. However, it would be nice to be able to change the alarm threshold via the HE. I'm guessing that this will require changes in the HE driver and a ton of other stuff.

Thoughts?

I'm thinking also that I'm not just going to turn off the TV, but also use Ansible to block internet access for the kids' phones and laptops as well.

Automated 15 min timeout for being too loud. This is going to be awesome.

I can whip up a Sound Pressure Level device within HubDuino for you. Which physical sensor did you buy? I am hoping it just outputs an analog signal, which woul actually mean no changes to the Arduino code whatsoever (I have a trick up my sleeve!)

Give me some more details, and I'll add a new groovy Child Sound Pressure Level driver to HubDuino for you. If desired, we can also implement a contact sensor capability in it with a user setting for max SPL threshold. This way it would be simpler to integrate with Rule Machine.

1 Like

Awesome! I bought the DFRobot sensor linked above.

1 Like

I should have a few updated Hubitat groovy drivers and an example sketch for you to try out this evening.

I am looking forward to hearing what the children think of your new use for home automation! :wink:

1 Like

Question though. Frequently their outbursts are a quick yell or scream. Does the HE poll the Hubduino device, or does the device send data on a regular interval to the HE?

Either way, since it will probably be on an interval, I would need the peak level during the last interval, not the current SPL value.

The HubDuino microcontroller is configured to poll at a certain frequency. Each time it polls, it sends data to Hubitat. So, yea, it is possible we'd miss a short, but loud, outburst...

We'll be starting by simply using the PS_Voltage HubDuino device. If it needs to be modified, or a new device created specifically for SPL measurements, we can cross that bridge when we get to it.

Here is the PS_Voltage device source code that you may want to take a look at.

We've got lots of options available! :wink:

Here's an example of how to use this thing:

https://wiki.dfrobot.com/Gravity__Analog_Sound_Level_Meter_SKU_SEN0232

Pretty simple, just multiply the voltage by 50 to get the dBa. What is the minimum polling frequency on the Hubduino, and how does short polling intervals affect performance of the HE?

I'm thinking I may have to track the max dBa with a variable that gets reset on each poll so I don't miss quick outbursts or when a kid hits the coffee table when he's frustrated playing a game.

OK, so I have the basic functionality up and running successfully on my test hub. I have update the "HubDuino Parent Ethernet" driver and I have added the "Child Sound Pressure Level" driver. Please update/add these new drivers your Hubitat system.

The Child Sound Pressure Level driver supports the Contact Sensor capability in addition to the SPL capability. You can set a max SPL threshold, above which the contact attribute will read CLOSED, otherwise it will read OPEN.

I have written the following simple sketch that will allow you to at least start your testing. I agree that it is unlikely to catch short-loud outbursts. But this will at least provide a proof of concept. I'll work on a SPL specific device that samples at a high rate, stores the MAX SPL, and then transmits it at a lower frequency.

The sketch is configured to read & average 3 samples every 30 seconds, and then transmit the SPL level to Hubitat. I scaled the SPL board's .6v to 2.6v to the full scale 3.3v capable on my NodeMCU ESP8266 board's AO input. The scaling will result in the correct SPL values per the spec sheet (I believe! Please verify.)

Sample sketch:

//******************************************************************************************
//  File: ST_Anything_SPL_ESP8266WiFi.ino
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
//  Summary:  This Arduino Sketch, along with the ST_Anything library and the revised SmartThings 
//            library, demonstrates the ability of one NodeMCU ESP8266 to 
//            implement a multi input/output custom device for integration into SmartThings.
//            The ST_Anything library takes care of all of the work to schedule device updates
//            as well as all communications with the NodeMCU ESP8266's WiFi.
//
//            ST_Anything_SPL implements the following Hubitat Capability as a demo of what is possible with a single NodeMCU ESP8266
//              - 1 x Sound Pressure Level device (using a simple analog output)
//    
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2019-07-08  Dan Ogorchock  Original Creation
//
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for ESP8266WiFi
//******************************************************************************************
#include <SmartThingsESP8266WiFi.h>

//******************************************************************************************
// ST_Anything Library 
//******************************************************************************************
#include <Constants.h>       //Constants.h is designed to be modified by the end user to adjust behavior of the ST_Anything library
#include <Device.h>          //Generic Device Class, inherited by Sensor and Executor classes
#include <Sensor.h>          //Generic Sensor Class, typically provides data to ST Cloud (e.g. Temperature, Motion, etc...)
#include <Executor.h>        //Generic Executor Class, typically receives data from ST Cloud (e.g. Switch)
#include <InterruptSensor.h> //Generic Interrupt "Sensor" Class, waits for change of state on digital input 
#include <PollingSensor.h>   //Generic Polling "Sensor" Class, polls Arduino pins periodically
#include <Everything.h>      //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications

#include <PS_Illuminance.h>  //Implements a Polling Sensor (PS) to measure light levels via a photo resistor

#include <PS_TemperatureHumidity.h>  //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <PS_DS18B20_Temperature.h>  //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries 
#include <PS_Water.h>        //Implements a Polling Sensor (PS) to measure presence of water (i.e. leak detector)
#include <PS_Voltage.h>      //Implements a Polling Sensor (PS) to measure voltage
#include <IS_Motion.h>       //Implements an Interrupt Sensor (IS) to detect motion via a PIR sensor
#include <IS_Contact.h>      //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_Smoke.h>        //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_DoorControl.h>  //Implements an Interrupt Sensor (IS) and Executor to monitor the status of a digital input pin and control a digital output pin
#include <IS_Button.h>       //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin for button presses
#include <EX_Switch.h>       //Implements an Executor (EX) via a digital output to a relay
#include <EX_Alarm.h>        //Implements Executor (EX)as an Alarm Siren capability via a digital output to a relay
#include <S_TimedRelay.h>    //Implements a Sensor to control a digital output pin with timing capabilities

//*************************************************************************************************
//NodeMCU v1.0 ESP8266-12e Pin Definitions (makes it much easier as these match the board markings)
//*************************************************************************************************
//#define LED_BUILTIN 16
//#define BUILTIN_LED 16
//
//#define D0 16  //no internal pullup resistor
//#define D1  5
//#define D2  4
//#define D3  0  //must not be pulled low during power on/reset, toggles value during boot
//#define D4  2  //must not be pulled low during power on/reset, toggles value during boot
//#define D5 14
//#define D6 12
//#define D7 13
//#define D8 15  //must not be pulled high during power on/reset

//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************
#define PIN_VOLTAGE_1               A0  //NodeMCU ESP8266 only has one Analog Input Pin 'A0'


//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "yourSSIDhere";                            //  <---You must edit this line!
String str_password = "yourPASSWORDhere";                          //  <---You must edit this line!
IPAddress ip(192, 168, 1, 227);       //Device IP Address       //  <---You must edit this line!
IPAddress gateway(192, 168, 1, 1);    //Router gateway          //  <---You must edit this line!
IPAddress subnet(255, 255, 255, 0);   //LAN subnet mask         //  <---You must edit this line!
IPAddress dnsserver(192, 168, 1, 1);  //DNS server              //  <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on

// Smartthings Hub Information
//IPAddress hubIp(192, 168, 1, 149);  // smartthings hub ip       //  <---You must edit this line!
//const unsigned int hubPort = 39500; // smartthings hub port
// Hubitat Hub Information
IPAddress hubIp(192, 168, 1, 145);    // hubitat hub ip         //  <---You must edit this line!
const unsigned int hubPort = 39501;   // hubitat hub port

//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine.  This is a sniffer to monitor 
//    data being sent to ST.  This allows a user to act on data changes locally within the 
//    Arduino sktech.
//******************************************************************************************
void callback(const String &msg)
{
//  Serial.print(F("ST_Anything Callback: Sniffed data = "));
//  Serial.println(msg);
  
  //TODO:  Add local logic here to take action when a device's value/state is changed
  
  //Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
  //st::receiveSmartString("Put your command here!");  //use same strings that the Device Handler would send
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
  //******************************************************************************************
  //Declare each Device that is attached to the Arduino
  //  Notes: - For each device, there is typically a corresponding "tile" defined in your 
  //           SmartThings Device Hanlder Groovy code, except when using new COMPOSITE Device Handler
  //         - For details on each device's constructor arguments below, please refer to the 
  //           corresponding header (.h) and program (.cpp) files.
  //         - The name assigned to each device (1st argument below) must match the Groovy
  //           Device Handler names.  (Note: "temphumid" below is the exception to this rule
  //           as the DHT sensors produce both "temperature" and "humidity".  Data from that
  //           particular sensor is sent to the ST Hub in two separate updates, one for 
  //           "temperature" and one for "humidity")
  //         - The new Composite Device Handler is comprised of a Parent DH and various Child
  //           DH's.  The names used below MUST not be changed for the Automatic Creation of
  //           child devices to work properly.  Simply increment the number by +1 for each duplicate
  //           device (e.g. contact1, contact2, contact3, etc...)  You can rename the Child Devices
  //           to match your specific use case in the ST Phone Application.
  //******************************************************************************************
  //Polling Sensors
    static st::PS_Voltage sensor1(F("soundPressureLevel1"), 30, 0, PIN_VOLTAGE_1, 0, 1024, 0.0, 165.0, 3);  
    
  //Interrupt Sensors 

  //Special sensors/executors (uses portions of both polling and executor classes)
  
  //Executors
  
  //*****************************************************************************
  //  Configure debug print output from each main class 
  //  -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
  //         to prevent communication conflicts with the ST Shield communications
  //*****************************************************************************
  st::Everything::debug=true;
  st::Executor::debug=true;
  st::Device::debug=true;
  st::PollingSensor::debug=true;
  st::InterruptSensor::debug=true;

  //*****************************************************************************
  //Initialize the "Everything" Class
  //*****************************************************************************

  //Initialize the optional local callback routine (safe to comment out if not desired)
  st::Everything::callOnMsgSend = callback;
  
  //Create the SmartThings ESP8266WiFi Communications Object
    //STATIC IP Assignment - Recommended
    st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString, "OfficeESP");
 
    //DHCP IP Assigment - Must set your router's DHCP server to provice a static IP address for this device's MAC address
    //st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, serverPort, hubIp, hubPort, st::receiveSmartString);

  //Run the Everything class' init() routine which establishes WiFi communications with SmartThings Hub
  st::Everything::init();
  
  //*****************************************************************************
  //Add each sensor to the "Everything" Class
  //*****************************************************************************
  st::Everything::addSensor(&sensor1);
      
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************
    
  //*****************************************************************************
  //Initialize each of the devices which were added to the Everything Class
  //*****************************************************************************
  st::Everything::initDevices();
  
}

//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
  //*****************************************************************************
  //Execute the Everything run method which takes care of "Everything"
  //*****************************************************************************
  st::Everything::run();
}
1 Like

@signal15 - I have finished the development of a high-speed SPL measurement device for ST_Anything/HubDuino. I have added the new PS_SoundPressureLevel.h and PS_SoundPressureLevel.cpp files to the ST_Anything library.

This new class polls the analog input pin every 50ms (by default) and keeps the MAX SPL value. It then transmits this value ~every 30 seconds (defined in the example sketch) to Hubitat and then resets the local variable to gather the next MAX value.

The new example sketch is named ST_Anything_SPL_ESP8266WiFi.ino.

This should get you going. Can't wait to hear how the children react! :wink:

Here is the documentation for the new SPL class/device.

//  Summary:  PS_SoundPressureLevel is a class which implements the "Sound Pressure Level" device capability.
//			  It inherits from the st::PollingSensor class.  The current version uses an analog input to measure the 
//			  voltage on an anlog input pin and then scale it to engineering units.
//
//			  The last four arguments of the constructor are used as arguments to an Arduino map() function which 
//			  is used to scale the analog input readings (e.g. 0 to 1024) to Engineering Units before sending to SmartThings. 
//
//			  Create an instance of this class in your sketch's global variable section
//			  For Example: static st::PS_SoundPressureLevel sensor1(F("soundPressureLevel1"), 60, 0, PIN_SPL, 0, 1024, 0.0, 165.0, 50);
//
//			  st::PS_SoundPressureLevel() constructor requires the following arguments
//				- String &name - REQUIRED - the name of the object - must match the Groovy ST_Anything DeviceType tile name
//				- long interval - REQUIRED - the polling interval in seconds
//				- long offset - REQUIRED - the polling interval offset in seconds - used to prevent all polling sensors from executing at the same time
//				- byte pin - REQUIRED - the Arduino Pin to be used as an analog input
//				- double s_l - OPTIONAL - first argument of Arduino map(s_l,s_h,m_l,m_h) function to scale the output - minimum raw AI value
//				- double s_h - OPTIONAL - second argument of Arduino map(s_l,s_h,m_l,m_h) function to scale the output - maximum raw AI value
//				- double m_l - OPTIONAL - third argument of Arduino map(s_l,s_h,m_l,m_h) function to scale the output - Engineering Unit Min (or Max if inverting)
//				- double m_h - OPTIONAL - fourth argument of Arduino map(s_l,s_h,m_l,m_h) function to scale the output - Engineering Unit Max (or Min if inverting)
//              - long m_nHighSpeedPollingInterval - OPTIONAL - number of milliseconds between high speed analog reads - defaults to 50ms

Ok, all installed. Man, the HE guys need to work on the driver import stuff, that's a whole lot of clicking and copy pasta. Too bad we can't just feed it a list of URL's or a JSON file that details where to get everything (with regular update checks). :slight_smile:

I needed to compile this for an ESP32, so I made some modifications to the sketch you posted. I'm seeing 2 problems:

  1. The dBA level is like 600 something, so it's not being calculated correctly.
  2. The child device only gets on dBA update, and then no more. See Event table below.

Here's my sketch for the ESP32:

//******************************************************************************************
//  File: ST_Anything_SPL_ESP8266WiFi.ino
//  Authors: Dan G Ogorchock & Daniel J Ogorchock (Father and Son)
//
//  Summary:  This Arduino Sketch, along with the ST_Anything library and the revised SmartThings 
//            library, demonstrates the ability of one NodeMCU ESP8266 to 
//            implement a multi input/output custom device for integration into SmartThings.
//            The ST_Anything library takes care of all of the work to schedule device updates
//            as well as all communications with the NodeMCU ESP8266's WiFi.
//
//            ST_Anything_SPL implements the following Hubitat Capability as a demo of what is possible with a single NodeMCU ESP8266
//              - 1 x Sound Pressure Level device (using a simple analog output)
//    
//  Change History:
//
//    Date        Who            What
//    ----        ---            ----
//    2019-07-08  Dan Ogorchock  Original Creation
//
//******************************************************************************************
//******************************************************************************************
// SmartThings Library for ESP32WiFi
//******************************************************************************************
#include <SmartThingsESP32WiFi.h>

//******************************************************************************************
// ST_Anything Library 
//******************************************************************************************
#include <Constants.h>       //Constants.h is designed to be modified by the end user to adjust behavior of the ST_Anything library
#include <Device.h>          //Generic Device Class, inherited by Sensor and Executor classes
#include <Sensor.h>          //Generic Sensor Class, typically provides data to ST Cloud (e.g. Temperature, Motion, etc...)
#include <Executor.h>        //Generic Executor Class, typically receives data from ST Cloud (e.g. Switch)
#include <InterruptSensor.h> //Generic Interrupt "Sensor" Class, waits for change of state on digital input 
#include <PollingSensor.h>   //Generic Polling "Sensor" Class, polls Arduino pins periodically
#include <Everything.h>      //Master Brain of ST_Anything library that ties everything together and performs ST Shield communications

#include <PS_Illuminance.h>  //Implements a Polling Sensor (PS) to measure light levels via a photo resistor

#include <PS_TemperatureHumidity.h>  //Implements a Polling Sensor (PS) to measure Temperature and Humidity via DHT library
#include <PS_DS18B20_Temperature.h>  //Implements a Polling Sesnor (PS) to measure Temperature via DS18B20 libraries 
#include <PS_Water.h>        //Implements a Polling Sensor (PS) to measure presence of water (i.e. leak detector)
#include <PS_Voltage.h>      //Implements a Polling Sensor (PS) to measure voltage
#include <IS_Motion.h>       //Implements an Interrupt Sensor (IS) to detect motion via a PIR sensor
#include <IS_Contact.h>      //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_Smoke.h>        //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin
#include <IS_DoorControl.h>  //Implements an Interrupt Sensor (IS) and Executor to monitor the status of a digital input pin and control a digital output pin
#include <IS_Button.h>       //Implements an Interrupt Sensor (IS) to monitor the status of a digital input pin for button presses
#include <EX_Switch.h>       //Implements an Executor (EX) via a digital output to a relay
#include <EX_Alarm.h>        //Implements Executor (EX)as an Alarm Siren capability via a digital output to a relay
#include <S_TimedRelay.h>    //Implements a Sensor to control a digital output pin with timing capabilities

//*************************************************************************************************
//NodeMCU v1.0 ESP8266-12e Pin Definitions (makes it much easier as these match the board markings)
//*************************************************************************************************
//#define LED_BUILTIN 16
//#define BUILTIN_LED 16
//
//#define D0 16  //no internal pullup resistor
//#define D1  5
//#define D2  4
//#define D3  0  //must not be pulled low during power on/reset, toggles value during boot
//#define D4  2  //must not be pulled low during power on/reset, toggles value during boot
//#define D5 14
//#define D6 12
//#define D7 13
//#define D8 15  //must not be pulled high during power on/reset

//******************************************************************************************
//Define which Arduino Pins will be used for each device
//******************************************************************************************
#define PIN_VOLTAGE_1               A19  //NodeMCU ESP8266 only has one Analog Input Pin 'A0'


//******************************************************************************************
//ESP8266 WiFi Information
//******************************************************************************************
String str_ssid     = "**";                            //  <---You must edit this line!
String str_password = "***";                          //  <---You must edit this line!
IPAddress ip(*****);       //Device IP Address       //  <---You must edit this line!
IPAddress gateway(***);    //Router gateway          //  <---You must edit this line!
IPAddress subnet(255, 255, 255, 0);   //LAN subnet mask         //  <---You must edit this line!
IPAddress dnsserver(8, 8, 8, 8);  //DNS server              //  <---You must edit this line!
const unsigned int serverPort = 8090; // port to run the http server on

// Smartthings Hub Information
//IPAddress hubIp(192, 168, 1, 149);  // smartthings hub ip       //  <---You must edit this line!
//const unsigned int hubPort = 39500; // smartthings hub port
// Hubitat Hub Information
IPAddress hubIp(***);    // hubitat hub ip         //  <---You must edit this line!
const unsigned int hubPort = 39501;   // hubitat hub port

//******************************************************************************************
//st::Everything::callOnMsgSend() optional callback routine.  This is a sniffer to monitor 
//    data being sent to ST.  This allows a user to act on data changes locally within the 
//    Arduino sktech.
//******************************************************************************************
void callback(const String &msg)
{
//  Serial.print(F("ST_Anything Callback: Sniffed data = "));
//  Serial.println(msg);
  
  //TODO:  Add local logic here to take action when a device's value/state is changed
  
  //Masquerade as the ThingShield to send data to the Arduino, as if from the ST Cloud (uncomment and edit following line)
  //st::receiveSmartString("Put your command here!");  //use same strings that the Device Handler would send
}

//******************************************************************************************
//Arduino Setup() routine
//******************************************************************************************
void setup()
{
  //******************************************************************************************
  //Declare each Device that is attached to the Arduino
  //  Notes: - For each device, there is typically a corresponding "tile" defined in your 
  //           SmartThings Device Hanlder Groovy code, except when using new COMPOSITE Device Handler
  //         - For details on each device's constructor arguments below, please refer to the 
  //           corresponding header (.h) and program (.cpp) files.
  //         - The name assigned to each device (1st argument below) must match the Groovy
  //           Device Handler names.  (Note: "temphumid" below is the exception to this rule
  //           as the DHT sensors produce both "temperature" and "humidity".  Data from that
  //           particular sensor is sent to the ST Hub in two separate updates, one for 
  //           "temperature" and one for "humidity")
  //         - The new Composite Device Handler is comprised of a Parent DH and various Child
  //           DH's.  The names used below MUST not be changed for the Automatic Creation of
  //           child devices to work properly.  Simply increment the number by +1 for each duplicate
  //           device (e.g. contact1, contact2, contact3, etc...)  You can rename the Child Devices
  //           to match your specific use case in the ST Phone Application.
  //******************************************************************************************
  //Polling Sensors
static st::PS_Voltage sensor1(F("soundPressureLevel1"), 30, 0, PIN_VOLTAGE_1, 0, 1024, 0.0, 165.0, 3);  

  //Interrupt Sensors 

  //Special sensors/executors (uses portions of both polling and executor classes)
  
  //Executors
  
  //*****************************************************************************
  //  Configure debug print output from each main class 
  //  -Note: Set these to "false" if using Hardware Serial on pins 0 & 1
  //         to prevent communication conflicts with the ST Shield communications
  //*****************************************************************************
  st::Everything::debug=true;
  st::Executor::debug=true;
  st::Device::debug=true;
  st::PollingSensor::debug=true;
  st::InterruptSensor::debug=true;

  //*****************************************************************************
  //Initialize the "Everything" Class
  //*****************************************************************************

  //Initialize the optional local callback routine (safe to comment out if not desired)
  st::Everything::callOnMsgSend = callback;
  
  //Create the SmartThings ESP8266WiFi Communications Object
//STATIC IP Assignment - Recommended
//    st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString, "OfficeESP");
st::Everything::SmartThing = new st::SmartThingsESP32WiFi(str_ssid, str_password, ip, gateway, subnet, dnsserver, serverPort, hubIp, hubPort, st::receiveSmartString);

//DHCP IP Assigment - Must set your router's DHCP server to provice a static IP address for this device's MAC address
//st::Everything::SmartThing = new st::SmartThingsESP8266WiFi(str_ssid, str_password, serverPort, hubIp, hubPort, st::receiveSmartString);

  //Run the Everything class' init() routine which establishes WiFi communications with SmartThings Hub
  st::Everything::init();
  
  //*****************************************************************************
  //Add each sensor to the "Everything" Class
  //*****************************************************************************
  st::Everything::addSensor(&sensor1);
  
  //*****************************************************************************
  //Add each executor to the "Everything" Class
  //*****************************************************************************

  //*****************************************************************************
  //Initialize each of the devices which were added to the Everything Class
  //*****************************************************************************
  st::Everything::initDevices();
  
}

//******************************************************************************************
//Arduino Loop() routine
//******************************************************************************************
void loop()
{
  //*****************************************************************************
  //Execute the Everything run method which takes care of "Everything"
  //*****************************************************************************
  st::Everything::run();
}
1 Like

Please see my post just prior to your most recent one for the latest files. You'll want to use my new PS_SoundPressureLevel device instead of the PS_Voltage device.

Also, to fix the scaling issue, change the "1024" to "4096" as the ESP32 has a 12bit ADC versus the ESP8266's 10bit ADC.