https://github.com/niklauslee/dht
Kaluma library for DHT humidity and temperature sensor
https://github.com/niklauslee/dht
dht humidity kaluma sensor temperature
Last synced: 2 months ago
JSON representation
Kaluma library for DHT humidity and temperature sensor
- Host: GitHub
- URL: https://github.com/niklauslee/dht
- Owner: niklauslee
- License: mit
- Created: 2022-02-17T09:58:39.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-17T11:05:14.000Z (over 3 years ago)
- Last Synced: 2025-01-21T17:30:47.965Z (4 months ago)
- Topics: dht, humidity, kaluma, sensor, temperature
- Language: JavaScript
- Homepage:
- Size: 49.8 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DHT
Kaluma library for DHT humidity and temperature sensor
# Wiring
Here is a wiring example for DHT11.
| Raspberry Pi Pico | DHT11 |
| ----------------- | ----- |
| 3V3 | VCC |
| GND | GND |
| GP15 | DATA |
# Install
```sh
npm install https://github.com/niklauslee/dht
```# Usage
Here is an example code:
```js
const pin = 15;
const {DHT} = require('dht');
const dht = new DHT(pin, DHT.DHT11);
let result = dht.read();
if (result) {
console.log(result);
console.log("Humidity: " + dht.humidity + " %");
console.log("Temperature: " + dht.temperature + " C");
} else {
console.log('Failed to read');
}
```# API
## Class: DHT
### new DHT(pin, [type])
- **`pin`** `` : The pin number which connected to the data pin of the DHT sensor.
- **`type`** ``: DHT sensor type, the default is `DHT11` and `DHT12`, `DHT21` and `DHT22` could be used.### dht.read()
- **Return** ``
It returns humidity and temperature numbers as an array of two numbers or `null` if failed to read data. The first number is humidity (%) and the second is temperature (℃).
### dht.humidity
- ``
The humidity value which is red at the last call of the `dht.read()`. The unit of the humidity is percentage (%).
### dht.temperature
- ``
The temperature value which is red at the last call of the `dht.read()`. The unit of the temperature is degrees celsius (℃).
## DHT.DHT11
* `` = `0`
## DHT.DHT12
* `` = `1`
## DHT.DHT21
* `` = `2`
## DHT.DHT22
* `` = `3`