Skip to content

Instantly share code, notes, and snippets.

@suyashkumar
Last active June 28, 2016 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suyashkumar/fb1f09df4e475bda9cf0ba33cf009bf8 to your computer and use it in GitHub Desktop.
Save suyashkumar/fb1f09df4e475bda9cf0ba33cf009bf8 to your computer and use it in GitHub Desktop.
// This #include statement was automatically added by the Particle IDE.
#include "ThingSpeak/ThingSpeak.h"
// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"
#define DHTTYPE DHT22
#define DHT_POWER D1
#define DHT_GND D4
#define DHT_SENSE D2
DHT dht(DHT_SENSE, DHTTYPE);
/* Thingspeak Setup */
TCPClient client;
unsigned long myChannelID = 127505;
const char * myWriteAPIKey = "Y1ROXRBWFYVMD1OK";
int numSleepMins = 20; // Number of minutes to sleep
void setup() {
ThingSpeak.begin(client); // Start up ThingSpeak library
pinMode(DHT_POWER, OUTPUT); // Set power pin to output
pinMode(DHT_GND, OUTPUT); // Set GND pin to output
// Turn power to sensor on:
digitalWrite(DHT_POWER, HIGH);
digitalWrite(DHT_GND, LOW);
delay(1500); // Let sensor settle
dht.begin(); // init DHT sensor reader
}
void loop() {
digitalWrite(DHT_POWER,HIGH); // Turn power back on
delay(1000); // Let sensor settle
double humidity = dht.getHumidity(); // Read Humidity
double temp = dht.getTempFarenheit(); // Read temp in degrees F
ThingSpeak.setField(1, (float)temp);
ThingSpeak.setField(2, (float)humidity);
ThingSpeak.writeFields(myChannelID, myWriteAPIKey); // Push to ThingSpeak
delay(750); // Wait a little before sleeping
digitalWrite(DHT_POWER,LOW); // Turn power to sensor off
// Go to Sleep:
System.sleep(D0, RISING, numSleepMins*60, SLEEP_NETWORK_STANDBY); // saves more data, uses more power
//System.sleep(SLEEP_MODE_DEEP, numSleepMins*60); // uses more data, uses less power
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment