# Sound Pressure Sensor

Working with a [Sound Pressure Level](https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Sound_Pressure_Level.html) sensor works as described in the general article on [how to use sensors](https://iot.datalit.de/2-internet-of-things/iot-in-our-apps/program-the-devices/sensors). In this article, we assume you have successfully initialized the devices with the [Tinkerforge Device Manager](https://iot.datalit.de/2-internet-of-things/iot-in-our-apps/connect-to-devices/the-tinkerforge-device-manager), and you stored all connected devices on a global variable `devices`. We also declared a global variable called `sound`.&#x20;

Next, we need to know the device identifier, which **290**:

```javascript
// Get the sound pressure level sensor via its device identifer
sound = devices.getDeviceByIdentifier(290);
```

Once we have a reference to the sensor, we can register a callback function:

```javascript
// We want to be informed when a new sensor value arrives
sound.registerListener(soundChanged);
```

Of course, we have to actually define the function:

```javascript
function soundChanged(val) {
   // Do something with the value object
}
```

## Reading the sound pressure level

Instead of just one single value, the sensor delivers four different values:

1. Sound level in decibel
2. Spectrum length
3. Spectrum chunk offset
4. Spectrum chunk data

We can access the array of value via the `val` object:

```javascript
function soundChanged(val) {

    // Get the decibel value
    var decibelValue = val.getValue("decibel_value");
    
    // Check if this actually was decibel event, if not we get -1 as result
    if(decibelValue !== -1 && decibelValue.type === "decibel_value") {
        log("Decibel: " + decibelValue.value)
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://iot.datalit.de/appendix/other-sensors/sound-pressure-sensor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
