Close
0%
0%

Humidity/Temp Controlled Power Outlet

A standard USA 110v power outlet which is connected to an arduino via a relay and activated based on certain temperature and humidity ranges

Similar projects worth following
A standard USA 110v power outlet which is connected to an arduino via a relay and activated based on certain temperature and humidity ranges. This will also make use of a photoresistor to be able to apply different 'day' and 'night' settings.

Goals:
- Cheap as possible while being as safe as one can be when playing with mains voltage.
- Modular and flexible design.

Why?:
- Commercial products are too expensive for the functionality provided
- Lack of precision/control compared to my unit
- Not very modular and/or bad form factors (i want to be able to move my sensor around)
- More fun and learn how to use the arduino for more stuff :)

I know very little about the arduino platform in general as well as hardware design, so this will be an adventure for me. I will be trying to modify code i find online and relying on the community to help me along. I am a developer/analyst by trade so i should be able to pick up the arduino language pretty quick. I am good at soldering and similar apsects of hardware development from some work i have done in the past on consoles.

At this point i need help picking out all the parts i will need. Below i have listed some parts i plan on using for the build. Need suggestions on if these will work together or not.

View all 8 components

  • New Circuit with Solid State Relay

    Brian01/02/2015 at 20:32 0 comments

    Is this circuit safe the way i wired up the relay? I notice in alot of other circuit designs they use transistors but i can't see the reason why it is needed.

  • Ideas for Features

    Brian01/02/2015 at 17:35 0 comments

    - Potentiometer to control 'day' and 'night' light threshold instead of using hard coded value.

    - Potentiometer to control Temp and Humidity thresholds instead of using hard coded values.

  • Parts Analysis and Schematic Help

    Brian01/02/2015 at 01:04 0 comments

    Hi Everyone, I have listed the parts i believe i will need to build my outlet.

    My plan is to make 1 outlet humidity controlled, and one outlet temperature controlled. To achieve this i will cut the tabs connecting the outlets so i can wire each one separately to a relay. I can obtain both of the readings from the same sensor. I will also have a photo-resistor attached so i can determine 'day' and 'night'.

    All i would like to be able to do is hard code some humidity and temperature values for a 'day' and 'night' setting that will trip the power outlet.

    Am i on the right track parts wise? Can anyone help me build a schematic that i can wire up?

View all 3 project logs

  • 1
    Step 1

    Rough Code so far... Was able to get it to verify in the arduino IDE. I had a photo sensor tutorial in my arduino starter kit and was able to piece together part of the circuit. Right now i have another test sketch which turns on an LED to indicate day or night as proof of concept.

    I also added in some logic to check if the relay is already on before switching it on, and to make sure it is on before switching it off so i am not constantly looping and telling it to shut off when already off. Not sure if this is necessary but i wanted to be on the safe side so i don't burn anything out.

    Will probably be a week or so before i get the rest of the parts i need (relays and temp/humidity sensor).


    Questions / Need help with:

    - Should i totally isolate the relays from the arduino (by feeding them a separate power source) as described below?

    NOTES: 
    If you want complete optical isolation, connect "Vcc" to Arduino +5 volts but do NOT connect Arduino Ground.  
    Remove the Vcc to JD-Vcc jumper. 
    Connect a separate +5 supply to "JD-Vcc" and board Gnd. 
    This will supply power to the transistor drivers and relay coils. 


    Work In Progress Mockup:




    CODE:

    /*-----( Import needed libraries )-----*/
    #include "DHT.h"
    
    /*-----( Declare Constants )-----*/
    #define RELAY_ON 0
    #define RELAY_OFF 1
    
    /*-----( Declare Variables )-----*/
    #define DHTPIN 2     // what pin we're connected to for DHT22
    #define Relay_1  3  // Arduino Digital I/O pin number for first outlet
    #define Relay_2  4 // Arduino Digital I/O pin number for second outlet
    #define DHTTYPE DHT22   // DHT 22  (AM2302)
    
    DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino
    
    // Connect pin 1 (on the left) of the sensor to +5V
    // NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
    // to 3.3V instead of 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
    
    int lightPin = 0; //the analog pin the photoresistor is connected to
                      //the photoresistor is not calibrated to any units so
                      //this is simply a raw sensor value (relative light)
    
    int ledPin = 9;   //Night Indicator LED
    int ledPin2 = 10; //Day Indicator LED
    
    int threshold = 700; //Photosensor value for Night time
    int lightVal = 0; //Variable to hold reading from photosensor
    boolean nightInd = false; //True/False to indicate if day or night. True = Night time
    
    //HUMIDITY THRESHOLDS
    float dayRHthresholdUpper = 60.00; //DAY RH High threshold when exhaust is turned on
    float dayRHthresholdLower = 40.00; //DAY RH Low threshold when exhaust is turned off
    
    float nightRHthresholdUpper = 60.00; //NIGHT RH High threshold when exhaust is turned on
    float nightRHthresholdLower = 40.00; //NIGHT RH Low threshold when exhaust is turned off
    
    //TEMP THRESHOLDS
    float dayTempThresholdUpper = 78.00; //DAY Temp High threshold when heat is turned off
    float dayTempThresholdLower = 75.00; //DAY Temp Low threshold when heat is turned on
    
    float nightTempThresholdUpper = 70.00; //NIGHT Temp High threshold when heat is turned off
    float nightTempThresholdLower = 66.00; //NIGHT Temp Low threshold when heat is turned on
    
    
    void setup()   /****** SETUP: RUNS ONCE ******/
    {
    //-------( Initialize Pins so relays are inactive at reset)----
      digitalWrite(Relay_1, RELAY_OFF);
      digitalWrite(Relay_2, RELAY_OFF);
      
    //---( THEN set pins as outputs )----  
      pinMode(Relay_1, OUTPUT); //Humidity outlet (exhaust fan - do not exceed 1200watts)
      pinMode(Relay_2, OUTPUT); //Heat outlet (heater - do not exceed 1200watts)   
      delay(4000); //Check that all relays are inactive at Reset
    
      pinMode(ledPin, OUTPUT); //Night Indicator LED
      pinMode(ledPin2, OUTPUT); //Day Indicator LED
    
      Serial.begin(9600); //start up serial output
      dht.begin(); //assuming this turns on the DHT22 sensor
    
    }//--(end setup )---
    
    
    
    
    void loop()   /****** LOOP: RUNS CONSTANTLY ******/
    {
      lightVal = analogRead(lightPin);  //Read photosensor value
      
      delay(2000);  // Wait a few seconds between measurements. DHT22 is slow.
                   // 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.readHumidity();  // Read Humidity
      float t = dht.readTemperature();  // Read temperature as Celsius
      float f = dht.readTemperature(true);  // Read temperature as Fahrenheit
      
      // 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;
      }
      
      
      if(analogRead(lightPin) > threshold){   //This is NIGHT TIME
       digitalWrite(ledPin, HIGH); //Turn night indicator LED ON.
       digitalWrite(ledPin2, LOW); //Turn day indicator LED OFF.
       nightInd = true;
         }else{  //This is DAY TIME
           digitalWrite(ledPin2, HIGH); //Turn day indicator LED ON.
           digitalWrite(ledPin, LOW); //Turn night indicator LED OFF.
           nightInd = false;
         }
    
      
      
      //------DAY TIME------//
      if (nightInd == false){  //nightInd = false so this means it is daytime
      
      // If humidity hits threshold, turn on exhaust (outlet #1)
      if (h > dayRHthresholdUpper) {
          if (Relay_1 == 1){  //Make sure relay is not already on before switching
        digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
      delay(1000);              // wait for a second
          }
      }
      // If humidity hits threshold, turn off exhaust (outlet #1)
      if (h < dayRHthresholdLower) {
          if (Relay_1 == 0){  //Make sure relay is on before switching off, else do nothing since its already off
          digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
      delay(1000);              // wait for a second
          }
      }
        // If temperature hits threshold, turn heat on. (outlet #2) 
      if (f < dayTempThresholdLower) {
                if (Relay_2 == 1){  //Make sure relay is not already on before switching
            digitalWrite(Relay_2, RELAY_ON);// set the Relay ON
      delay(1000);              // wait for a second
                }
      }
      // If temperature hits threshold, turn heat off. (outlet #2) 
      if (f > dayTempThresholdUpper) {
                if (Relay_1 == 0){  //Make sure relay is on before switching off, else do nothing since its already off
            digitalWrite(Relay_2, RELAY_OFF);// set the Relay OFF
      delay(1000);              // wait for a second
                }
      }
      }//------END DAY TIME-----//
    
    
    
      //------NIGHT TIME------//
      if (nightInd == true){    
      
      // If humidity hits threshold, turn on exhaust (outlet #1)
      if (h > nightRHthresholdUpper) {
        if (Relay_1 == 1){  //Make sure relay is not already on before switching
        digitalWrite(Relay_1, RELAY_ON);// set the Relay ON
      delay(1000);              // wait for a second
        }
      }
      // If humidity hits threshold, turn off exhaust (outlet #1)
      if (h < nightRHthresholdLower) {
            if (Relay_1 == 0){  //Make sure relay is on before switching off, else do nothing since its already off
          digitalWrite(Relay_1, RELAY_OFF);// set the Relay OFF
      delay(1000);              // wait for a second
            }
      }
      // If temperature hits threshold, turn heat on. (outlet #2) 
      if (f < nightTempThresholdLower) {
            if (Relay_2 == 1){  //Make sure relay is not already on before switching
            digitalWrite(Relay_2, RELAY_ON);// set the Relay ON
      delay(1000);              // wait for a second
            }
      }
      // If temperature hits threshold, turn heat off. (outlet #2) 
      if (f > nightTempThresholdUpper) {
            if (Relay_2 == 0){  //Make sure relay is on before switching off, else do nothing since its already off
            digitalWrite(Relay_2, RELAY_OFF);// set the Relay OFF
      delay(1000);              // wait for a second
            }
      }
      
      }//------END NIGHT TIME-----//
    
    
      float hi = dht.computeHeatIndex(f, h);  // Compute heat index, might be useful later...
                                              //Must send in temp in Fahrenheit!
                        
                        
      //DEBUG Outputs
      Serial.println(lightVal); //Photosensor value
      Serial.println(nightInd); // True = Night | False = Day
      Serial.print("Humidity: "); 
      Serial.print(h);
      Serial.print(" %\t");
      Serial.print("Temperature: "); 
      Serial.print(t);
      Serial.print(" *C ");
      Serial.print(f);
      Serial.print(" *F\t");
      Serial.print("Heat index: ");
      Serial.print(hi);
      Serial.println(" *F");
    
    }//--(end main loop )---

View all instructions

Enjoy this project?

Share

Discussions

Brian wrote 01/02/2015 at 19:34 point

Can anyone help me replace the relays in my circuit with these (

http://www.mouser.com/ds/2/365/s216s02_e-184067.pdf) ???

I'm not sure what i need hardware wise and how to activate and deactivate the relay since its not a plug and play arduino board.

Thanks!!!

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates