Code gets:
- Temperature and Humidity from a DHT11 sensor
Prints the data to the Serial Monitor
Please let me know if you experience any problems with this
code. Be sure to check back for more Arduino code.
Schematic:
Code:
/*
Oliver Holden
Created 28/10/2014
Components:
* Arduino UNO
* DHT11
* 4.7K resistor
- Gets Temperature and Humidity from a DHT11 sensor
Prints the data to the Serial Monitor
Schematic for this project is on
http://breadboarder.blogspot.co.uk/
*/
#include <dht.h> // Including libary to read DHT11
dht DHT; // Need this
int dht_dpin = 2; // DHT11 data pin attached to A2
void setup(){
Serial.begin(9600); // Opening serial connection at 9600bps
Serial.println("Humidity and temperature"); // Printing Serial Monitor header
delay(1000); // Wait 1 second before printing data to Serial Monitor
}
void loop(){
DHT.read11(dht_dpin); // Reading data from DHT11
Serial.print("Current humidity = "); // Printing text
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
delay(1000); // Sensor shouldn't be read too frequently so delay of 1s
}
No comments:
Post a Comment