Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT.h"

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#define DHTPIN D3     // 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);
/**
* Declaring the variables.
*/
unsigned int nextTime = 0;    // Next time to contact the server

int redPin = D0;    // RED pin of the LED to PWM pin **A4**
int greenPin = D1;  // GREEN pin of the LED to PWM pin **D0**
int bluePin = D2;   // BLUE pin of the LED to PWM pin **D1**
int redValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int blueValue = 255;

void setup(){
  //Serial.begin(9600);
	Particle.publish("DEBUG","DHT22 test!");
	dht.begin();
  // Set up our pins for output
  pinMode( redPin, OUTPUT);
  pinMode( greenPin, OUTPUT);
  pinMode( bluePin, OUTPUT);
}

void loop(){
  void loop() {
// Wait a few seconds between measurements.
	delay(1000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a
// very slow sensor)
// Read temperature as Celsius
	float t = dht.getTempCelcius();
// Read dew point
  float dp = dht.getDewPoint();

  Serial.println("\nTemC: ");
  Serial.print(t);
  Serial.println("\nDewPoint: ");
  Serial.print(dp);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
  Particle.publish("DEBUG","Failed to read from DHT sensor!");
  return;
}

  digitalWrite(redPin, redValue);
  digitalWrite( greenPin, greenValue);
  digitalWrite( bluePin, blueValue);
  delay(3000);

if(dp<t){
	if(t<0){
		redValue = 0;
		digitalWrite(redPin, redValue);   // Turn ON the LED pins
		delay(3000);
		redValue = 255;
		digitalWrite(redPin, redValue);
	}
	else {
		blueValue = 0;
		digitalWrite( bluePin, blueValue);
		delay(3000);
		blueValue = 255;
		digitalWrite( bluePin, blueValue);
	}
}
else{
	greenValue = 0;
  digitalWrite( greenPin, greenValue);
  delay(3000);
  greenValue = 255;
  digitalWrite( greenPin, greenValue);
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0