Internet of Things
TinkerforgeCode in ActionAbout Me
  • Course Outline
  • 1 - Getting Started
    • Overview
    • Connect to the LED
    • Getting Started
      • Glitch
      • The Application Template
    • Concepts in Programming
      • What is Programming?
      • Variables
      • Functions and Commands
      • Control Structures
      • Loops
      • Objects and Libraries
    • Programming Simple Web Apps
    • Exercises
      • 1.1 Buttons and Inputs
  • 2 - Internet of Things
    • Overview
    • IoT in our Apps
      • Getting Started
        • Hardware Kit
        • Brick Viewer and Daemon
      • Connect to the Devices
        • The Tinkerforge Device Manager
      • Program the Devices
        • RGB LED
        • RGB LED Button
        • OLED Display
        • Sensors
          • Humidity Sensor
          • Ambient Light Sensor
    • Components and Use Cases
    • Exercises
      • 2.1 Lights and Buttons
      • 2.2 Sensors
      • 2.3 Display
  • 3 - Artificial Intelligence
    • Overview
    • AI in our Apps
      • Google's Teachable Machine
      • Face Recognition
      • Training a Custom Model
    • Rules vs. Learning
    • Learning from Data
    • Use Cases
      • Computer Vision
        • Image Classification
        • Handwriting Recognition
    • Machine Learning Algorithms
      • Artificial Neural Networks
      • Decision Trees
      • Logistic Regression
    • Exercises
      • 3.1 Rules vs. Learning
      • 3.2 Fruits and Vegetables
      • 3.3 Face Recognition
      • 3.4 A Classifier for Iris
  • 4 - Cloud & APIs
    • Overview
    • APIs in our Apps
    • Cloud and APIs
      • Weather API
      • NASA Open APIs
      • EDAMAM Nutrition and Recipes API
    • Push Notifications
    • Exercises
  • 5 - App Project
    • Overview
    • Summer 2021
    • Summer 2022
  • Appendix
    • Other Devices
      • Motorized Linear Poti
      • Sound Pressure Sensor
      • NFC Reader
      • Motion Detector
    • UI Features
      • Realtime Charts
      • Countdown Timer
    • Digital Computers
      • Overview
      • The Binary System
      • Code Systems
      • Logic Gates
      • Binary Addition
      • From Analog to Digital
    • Cheat Sheets
    • Projects
      • IoT @ Pickup-Boxes
Powered by GitBook
On this page

Was this helpful?

  1. Appendix
  2. Other Devices

Sound Pressure Sensor

PreviousMotorized Linear PotiNextNFC Reader

Last updated 4 years ago

Was this helpful?

Working with a sensor works as described in the general article on . In this article, we assume you have successfully initialized the devices with the , and you stored all connected devices on a global variable devices. We also declared a global variable called sound.

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

// 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:

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

Of course, we have to actually define the function:

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:

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)
    }
}
Sound Pressure Level
how to use sensors
Tinkerforge Device Manager