background image

 

VMA345 

V. 01 

 10/02/2020 

©Velleman nv 

 

8.

 

Example Sketch 

 

 

/* How to use the DHT-22 sensor with Arduino uno 

 

   Temperature and humidity sensor 

 

   More info: http://www.ardumotive.com/how-to-use-dht-22-sensor-en.html 

 

   Dev: Michalis Vasilakis // Date: 1/7/2015 // www.ardumotive.com */ 

 

 

 

//Libraries 

 

#include <dht.h> 

 

dht DHT; 

 

//Constants 

 

#define DHT22_

PIN 2     

// DHT 22  (AM2302) - 

what pin we're connected to

 

 

 

 

//Variables 

 

float hum;  //Stores humidity value 

 

float temp; //Stores temperature value 

 

 

 

void setup() 

 

 

    Serial.begin(

9600

); 

 

 

 

 

//Variables 

 

 

 

void loop() 

 

 

    int chk = DHT.read22(DHT22_PIN); 

 

    //Read data and store it to variables hum and temp 

 

    hum = DHT.humidity; 

 

    temp= DHT.temperature; 

 

    //Print temp and humidity values to serial monitor 

 

    Serial.print("Humidity: "); 

 

    Serial.print(hum); 

 

    Serial.print(" %, Temp: "); 

 

    Serial.print(temp); 

 

    Serial.println(" Celsius"); 

 

    delay(1000); //Delay 1 sec. 

 

 

Reviews: