Last active
September 2, 2015 06:37
-
-
Save K-ways/7e50a0b8fad3328246c0 to your computer and use it in GitHub Desktop.
Arduino Code for 2nd EE Summer Camp © 2015 by K-ways.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DHT.h" | |
#define DHTPIN 3 | |
#define DHTTYPE DHT11 | |
DHT dht(DHTPIN, DHTTYPE); | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("Initializing..."); | |
pinMode(2, OUTPUT); | |
pinMode(5, OUTPUT); | |
digitalWrite(2, HIGH); | |
digitalWrite(5, LOW); | |
dht.begin(); | |
} | |
void loop() { | |
delay(2000); | |
float h = dht.readHumidity(); | |
float t = dht.readTemperature(); | |
float f = dht.readTemperature(true); | |
// Check if any reads failed and exit early (to try again). | |
if (isnan(h) || isnan(t) || isnan(f)) { | |
Serial.println("Failed to read from DHT sensor!"); | |
return; | |
} | |
Serial.print("Humidity: "); | |
Serial.print(h); | |
Serial.print(" %\t"); | |
Serial.print("Temperature: "); | |
Serial.print(t); | |
Serial.print(" *C "); | |
Serial.print(f); | |
Serial.println(" *F\t"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "DHT.h" | |
#define DHTPIN 3 | |
#define DHTTYPE DHT11 | |
DHT dht(DHTPIN, DHTTYPE); | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("Initializing..."); | |
pinMode(2, OUTPUT); | |
pinMode(5, OUTPUT); | |
pinMode(13, OUTPUT); | |
digitalWrite(2, HIGH); | |
digitalWrite(5, LOW); | |
digitalWrite(13, LOW); | |
dht.begin(); | |
} | |
void loop() { | |
delay(2000); | |
float h = dht.readHumidity(); | |
float t = dht.readTemperature(); | |
float f = dht.readTemperature(true); | |
// Check if any reads failed and exit early (to try again). | |
if (isnan(h) || isnan(t) || isnan(f)) { | |
Serial.println("Failed to read from DHT sensor!"); | |
return; | |
} | |
Serial.print("Humidity: "); | |
Serial.print(h); | |
Serial.print(" %\t"); | |
Serial.print("Temperature: "); | |
Serial.print(t); | |
Serial.print(" *C "); | |
Serial.print(f); | |
Serial.println(" *F\t"); | |
if ( t >= 30 || h >= 75 ){ | |
digitalWrite(13, HIGH); | |
} | |
else{ | |
digitalWrite(13, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment