// This #include statement was automatically added by the Particle IDE. #include // This #include statement was automatically added by the Particle IDE. //#include // This #include statement was automatically added by the Particle IDE. #include "Adafruit_DHT_Particle.h" // Example testing sketch for various DHT humidity/temperature sensors // Written by ladyada, public domain #define DHTPIN D2 // what pin we're connected to // Uncomment whatever type you're using! #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) // Connect pin 1 (on the left) of the sensor to +5V // Connect pin 2 of the sensor to whatever your DHTPIN is // Connect pin 4 (on the right) of the sensor to GROUND // Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor DHT dht(DHTPIN, DHTTYPE); int loopCount; void setup() { Serial.begin(9600); Serial.println("DHTxx test!"); Particle.publish("state", "DHTxx test start"); dht.begin(); loopCount = 0; delay(2000); } void loop() { // Wait a few seconds between measurements. // delay(2000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a // very slow sensor) float h = dht.getHumidity(); // Read temperature as Celsius float t = dht.getTempCelcius(); // Read temperature as Farenheit float f = dht.getTempFarenheit(); // 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; } // Compute heat index // Must send in temp in Fahrenheit! float hi = dht.getHeatIndex(); float dp = dht.getDewPoint(); float k = dht.getTempKelvin(); Serial.print("Humid: "); Serial.print(h); Serial.print("% - "); Serial.print("Temp: "); Serial.print(t); Serial.print(f); Serial.print("*C "); Serial.print("*F "); Serial.print(k); Serial.print("*K - "); Serial.print("DewP: "); Serial.print(dp); Serial.print("*C - "); Serial.print("HeatI: "); Serial.print(hi); Serial.println("*C"); Serial.println(Time.timeStr()); //String timeStamp = Time.timeStr(); //Particle.publish("readings", String::format("{\"Hum(\%)\": %4.2f, \"Temp(°C)\": %4.2f, \"DP(°C)\": %4.2f, \"HI(°C)\": %4.2f}", h, t, dp, hi)); Particle.publish("readings", String::format("\Humidity(percent)\ = %4.2f, \Temp(°C)\ = %4.2f, \Temp(°F)\ = %4.2f" , h, t, f)); delay(10000); //loopCount++; // if(loopCount >= 6){ // Particle.publish("state", "Going to sleep for 5 minutes"); //delay(1000); // System.sleep(SLEEP_MODE_DEEP, 300); //} } // ********************** // // This #include statement was automatically added by the Particle IDE. // #include // // This #include statement was automatically added by the Particle IDE. // #include // // This #include statement was automatically added by the Particle IDE. // #include // /** // * ReadSHT1xValues // * // * Read temperature and humidity values from an SHT1x-series (SHT10, // * SHT11, SHT15) sensor. // * // * Copyright 2009 Jonathan Oxer // * www.practicalarduino.com // * // * Ported to Spark Core by Anurag Chugh (https://github.com/lithiumhead) on 2014-10-15 // */ // // This #include statement was automatically added by the Spark IDE. // #include "SHT1x.h" // // Specify data and clock connections and instantiate SHT1x object // #define dataPin D0 // #define clockPin D1 // SHT1x sht1x(dataPin, clockPin); // void setup() // { // Serial.begin(9600); // Open serial connection to report values to host // Serial.println("Starting up"); // } // void loop() // { // float temp_c; // float temp_f; // float humidity; // // Read values from the sensor // temp_c = sht1x.readTemperatureC(); // temp_f = sht1x.readTemperatureF(); // humidity = sht1x.readHumidity(); // // Print the values to the serial port // Serial.print("Temperature: "); // Serial.print(temp_c, DEC); // Serial.print("C / "); // Serial.print(temp_f, DEC); // Serial.print("F. Humidity: "); // Serial.print(humidity); // Serial.println("%"); // // Get some data // String temp = String(temp_f); // Particle.publish("Temperature (F)", temp, PRIVATE); // String humidity1 = String(humidity); // Particle.publish("Humidity (%)", humidity1, PRIVATE); // delay(10000); // }