flying goat gaming
Published

DHTxx for Arduino Code

An Arduino project.

BeginnerProtip30 minutes657
DHTxx for Arduino Code

Things used in this project

Story

Read more

Schematics

dht22_design_bb_WrlRPehiA8.jpg

Code

DHT XX sensor code for Arduino

C/C++
//Libraries
#include <DHT.h>;
//#include<iostream>:
//Constants
#define DHTPIN 7     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino


//Variables
int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value
float faran;
float kel;
void setup()
{
  Serial.begin(9600);
  dht.begin();
}

void loop()
{
    delay(2000);
    //Read data and store it to variables hum and temp
    hum = dht.readHumidity();
    temp= dht.readTemperature();
    
    //Print temp and humidity values to serial monitor
    
    Serial.print("Humidity : ");
    Serial.print(hum);
    Serial.println(" %");
    
    Serial.print("Temp     :");
    Serial.print(temp);
    Serial.println(" Celsius");
   
    faran = (temp * 9.0) / 5.0 + 32;
    Serial.print("Faranheit: ");
    Serial.print(faran);
    Serial.println(" F");
    
    kel = temp + 273.15;
    Serial.print("Kelvin: ");
    Serial.print(kel);
    Serial.println(" K");
    
    Serial.println("");
    Serial.println("");
    delay(5000); //Delay 5 sec
    
    
    
    
    
    
    
   // This is free and unencumbered software released into the public domain Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
   
   
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OROTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER DEALINGS IN THE SOFTWARE.

//For more information, please refer to <http://unlicense.org>
}

Credits

flying goat gaming
1 project • 0 followers

Comments