Back to Parent

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

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

#define DHTPIN D7    // what pin we are connected to
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

double temperature = 0;
double humidity = 0; 

int led_pin[] = {D2,D3,D4,D5,D6};

int T_set[] = {13, 15, 18, 20, 30, 35, 40, 45};
int H_set[] = {10, 20, 25, 30, 60, 70, 80, 90};
int switchPin = D8;
int status = -1;

void setup() {
    // Set up the LED for output
	for(int i = 0; i < 5; i++)
    	pinMode(led_pin[i], OUTPUT);

    dht.begin();
    Particle.variable("temperature", &temperature, DOUBLE); // api variables
    Particle.variable("humidity", &humidity, DOUBLE);
    Particle.variable("status", status);
     pinMode( switchPin , INPUT_PULLUP); // sets pin as input
}

void loop() {
    
    int buttonState = digitalRead( switchPin );
    
if( buttonState == LOW ){
    
    // Reading temperature or humidlity takes about 250 millisecond
    // Sensor variable also may be 2 second old 
    humidity = dht.getHumidity();
    temperature = dht.getTempCelcius();
    
    if(humidity < H_set[0] || temperature < T_set[0] || humidity > H_set[7] || temperature > T_set[7]) {
        digitalWrite(led_pin[0], LOW);
        digitalWrite(led_pin[1], LOW);
        digitalWrite(led_pin[2], LOW);
        digitalWrite(led_pin[3], LOW);
        digitalWrite(led_pin[4], LOW);
        
        status = 1;
        
        for(int i = 0; i < 15; i++) {
            digitalWrite(led_pin[0], HIGH);
		    delay(100);
		
            digitalWrite(led_pin[0], LOW);
		    delay(100);
        }
	}else if(humidity < H_set[1] || temperature < T_set[1] || humidity > H_set[6] || temperature > T_set[6]) {
        digitalWrite(led_pin[0], LOW);
        digitalWrite(led_pin[1], LOW);
        digitalWrite(led_pin[2], LOW);
        digitalWrite(led_pin[3], LOW);
        digitalWrite(led_pin[4], LOW);
        
        status = 2;
        
        for(int i = 0; i < 15; i++) {
            digitalWrite(led_pin[0], HIGH);
            digitalWrite(led_pin[1], HIGH);
    		delay(300);
    		
            digitalWrite(led_pin[0], LOW);
            digitalWrite(led_pin[1], LOW);
    		delay(300);
        }
    }else if(humidity < H_set[2] || temperature < T_set[2] || humidity > H_set[5] || temperature > T_set[5]) {
        digitalWrite(led_pin[0], LOW);
        digitalWrite(led_pin[1], LOW);
        digitalWrite(led_pin[2], LOW);
        digitalWrite(led_pin[3], LOW);
        digitalWrite(led_pin[4], LOW);
        
        status = 3;
        
        for(int i = 0; i < 15; i++) {
            digitalWrite(led_pin[0], HIGH);
            digitalWrite(led_pin[1], HIGH);
            digitalWrite(led_pin[2], HIGH);
    		delay(500);
    		
            digitalWrite(led_pin[0], LOW);
            digitalWrite(led_pin[1], LOW);
            digitalWrite(led_pin[2], LOW);
    		delay(500);
        }
    }else if(humidity < H_set[3] || temperature < T_set[3] || humidity > H_set[4] || temperature > T_set[4]) {
        digitalWrite(led_pin[0], LOW);
        digitalWrite(led_pin[1], LOW);
        digitalWrite(led_pin[2], LOW);
        digitalWrite(led_pin[3], LOW);
        digitalWrite(led_pin[4], LOW);
        
        digitalWrite(led_pin[0], HIGH);
        digitalWrite(led_pin[1], HIGH);
        digitalWrite(led_pin[2], HIGH);
        digitalWrite(led_pin[3], HIGH);
        digitalWrite(led_pin[4], LOW);
        
        status = 4;
        
    }else {
        digitalWrite(led_pin[0], LOW);
        digitalWrite(led_pin[1], LOW);
        digitalWrite(led_pin[2], LOW);
        digitalWrite(led_pin[3], LOW);
        digitalWrite(led_pin[4], LOW);
        
        digitalWrite(led_pin[0], HIGH);
        digitalWrite(led_pin[1], HIGH);
        digitalWrite(led_pin[2], HIGH);
        digitalWrite(led_pin[3], HIGH);
        digitalWrite(led_pin[4], HIGH);
        
        status = 5;
        
    }
}else{
    for(int i = 0; i < 3; i++) {
            digitalWrite(led_pin[0], HIGH);
            digitalWrite(led_pin[1], HIGH);
            digitalWrite(led_pin[2], HIGH);
            digitalWrite(led_pin[3], HIGH);
            digitalWrite(led_pin[4], HIGH);
    		delay(500);
    		
            digitalWrite(led_pin[0], LOW);
            digitalWrite(led_pin[1], LOW);
            digitalWrite(led_pin[2], LOW);
            digitalWrite(led_pin[3], LOW);
            digitalWrite(led_pin[4], LOW);
    		delay(500);
    		
        status = 0;
        
    }
}
}
Click to Expand

Content Rating

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

0