Skip to content

Instantly share code, notes, and snippets.

@salmanfarisvp
Created January 6, 2017 17:19
Show Gist options
  • Save salmanfarisvp/affc8aba7d2933bc5beaf81c6cdf4855 to your computer and use it in GitHub Desktop.
Save salmanfarisvp/affc8aba7d2933bc5beaf81c6cdf4855 to your computer and use it in GitHub Desktop.
Arduino Compatable Temprature and Humidit Sensor Based on DHT11/22
#include <DHT.h>;
//Constants
#define DHTPIN A1 // what pin we're connected to
#define DHTTYPE DHT11 // 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
void setup()
{
Serial.begin(9600);
dht.begin();
}
void loop()
{
//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.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(2000); //Delay 2 sec.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment