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
  • Goals
  • Get the humidity sensor and subscribe to updates
  • Distinguish between temperature and humidity

Was this helpful?

  1. 2 - Internet of Things
  2. IoT in our Apps
  3. Program the Devices
  4. Sensors

Humidity Sensor

PreviousSensorsNextAmbient Light Sensor

Last updated 4 years ago

Was this helpful?

Goals

  • You know how to get a handle on the humidity sensor connected to your computer

  • You can get the sensor's values, get frequently notified about new values, and distinguish between humidity and temperature values

Get the humidity sensor and subscribe to updates

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 humiditySensor.

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

// Get the humidity sensor via its device identifer
humiditySensor = devices.getDeviceByIdentifier(283);

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
humiditySensor.registerListener(humidityChanged);

Of course, we have to actually define the function:

function humidityChanged(val) {
   // Do something with the value object
}

Distinguish between temperature and humidity

Since the sensor delivers two different value types, temperature and humidity, why not use the callback function to illustrate how we can distinguish both types:

function humidityChanged(val) {
    // Get the value
    var value = val.getValue():
    
    if(value.type == "temperature") {
        // Do something
    }
    else if (value.type == "humidity") {
        // Do something else
    }
}

That is basically it - we can't do anything else with a sensor.

Humidity 2.0
how to use sensors
Tinkerforge Device Manager
Humidity 2.0