Created
March 14, 2015 14:31
-
-
Save grevian/b0d5c5a839134f589f53 to your computer and use it in GitHub Desktop.
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
// This #include statement was automatically added by the Spark IDE. | |
#include "Adafruit_DHT/Adafruit_DHT.h" | |
#define DHTPIN 4 //Temperature and humidity sensor will connect to digital pin 4 | |
#define DHTTYPE DHT22 // DHT 22 (AM2302) | |
int led = D7; // This one is the built-in tiny one to the right of the USB jack | |
DHT dht(DHTPIN, DHTTYPE); //Create a DHT 22 object on digital pin 6 | |
double temperature = 0.0; | |
void setup() { | |
pinMode(led, OUTPUT); | |
dht.begin(); // Fire up the DHT 22 | |
delay(2000); // Wait 2 seconds, recommended as per the DHT datasheet | |
Spark.variable("temperature", &temperature, DOUBLE); | |
} | |
void loop() { | |
digitalWrite(led, HIGH); // Turn ON the LED pins | |
temperature = dht.getTempCelcius(); //Get temperature from the DHT 22 | |
// float h = dht.getHumidity(); // Get humidity from the DHT 22 | |
unsigned long x = millis(); //Variable to store the time in milliseconds that your Core has been alive | |
delay(1000); // Keep the LED on long enough we know the reading is being taken | |
digitalWrite(led, LOW); | |
delay(3000); // Wait a while before reading again | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment