Kaluma library for DHT humidity and temperature sensor
Here is a wiring example for DHT11.
Raspberry Pi Pico | DHT11 |
---|---|
3V3 | VCC |
GND | GND |
GP15 | DATA |
npm install https://github.com/niklauslee/dht
Here is an example code:
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');
}
pin
<number>
: The pin number which connected to the data pin of the DHT sensor.type
<number>
: DHT sensor type, the default isDHT11
andDHT12
,DHT21
andDHT22
could be used.
- Return
<number[2]>
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 (℃).
<number>
The humidity value which is red at the last call of the dht.read()
. The unit of the humidity is percentage (%).
<number>
The temperature value which is red at the last call of the dht.read()
. The unit of the temperature is degrees celsius (℃).
<number>
=0
<number>
=1
<number>
=2
<number>
=3