Temperature and humidity measurement with the AM2120
FunduinoLast updated on
Zwei Messwerte über eine einzige Datenleitung auslesen
You need this
AM2120 temperature and humidity sensor - JST connector, 1-Wire
5,98 € *Item no. F23107861About the product — AM2120 temperature and humidity sensor - JST connector, 1-Wire
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino
Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
1,74 € *Item no. FUN-1010558About the product — Breadboard Cables Male-to-Male - 40 Pieces, 20 cm
All 3 parts together 18,84 € *
* All prices include statutory VAT, plus shipping costs.
Connect the sensor
1 / 2
Install the DHT library
The sketch
Read temperature and humidity
#include "DHT.h"
#define pinDHT 5 // Sensor pin
DHT dht(pinDHT, DHT22); //Create a sensor from the library, configured for the DHT22 type, which uses the same communication method as the AM2120
void setup()
{
Serial.begin(9600); //Initialize serial communication
dht.begin(); //Start communication with the DHT sensor
}
void loop()
{
float temperatur = dht.readTemperature(); //Read the temperature into a variable
float luftfeuchtigkeit = dht.readHumidity(); //Read the humidity into a variable
//Check whether the readings are valid using the isnan function
if (isnan(temperatur) || isnan(luftfeuchtigkeit)) //Display an error message if reading fails
{
Serial.println("Error reading sensor");
delay(800);
return;
}
//Output the measured values via the serial interface
Serial.print("Temperature: ");
Serial.print(temperatur);
Serial.print(" degrees Celsius, ");
Serial.print("Humidity: ");
Serial.print(luftfeuchtigkeit);
Serial.println("% RH.");
delay(800);
}Rate the instructions