Software apps and online services

Story

Introduction

I have an Akita mix. She is the definition of a winter dog but with summer coming, I'm worried that she will get too hot in my house during the day. I don't want to leave on the air conditioner all day because that will waste a lot of energy but I need to leave it on because she'll get over heated. I don't have central air in my house so my thermostat only controls my heat. I wanted a way to cool my house to a set temperature without having to buy a whole new air conditioner so I made a device to do it. I used a power switch along with the very capable Particle Photon to build the Air Conditioner Controller.

In normal air conditioning systems, there's either an on or and off. In order to avoid the system from just switching constantly, it overshoots (keeps the air conditioner on past the actual temperature). I decided I wanted to do the same thing for my system. If the temperature gets above my target temperature, I want the air conditioner to turn on and continue to stay on for 5 minutes.

The graph below shows the goal of this device. When there isn't any air conditioning (AC), the temperature will stay at about what the outside temperature is (shown in red). When the AC is on all day, the temperature will plummet down and keep the house very cold which is a waste of electricity (shown in purple). When the AC is only on long enough to overshoot five minutes (shown in aqua), the temperature read inside will start resembling a sine wave (shown in dark blue) with the peak of the sine wave at our threshold temperature.

How the system works

Assembly

I found a case that a flash drive came in that would be just the right size for the controller. It had a larger window on it than I needed some foam could cover that. I used a standard breadboard and fit everything in snugly. See the wiring diagram for specifics on how to wire.

Controller, wired and stuffed in a tin box

I wanted the wires going to the DHT22 to be outside the container and I needed a hole for the wires for the power relay so I took some tin snips and cut a hole. I cut another hole for the micro-usb connector.

DHT22 wired outside the box

I tested some code without hooking up the air conditioner and then I felt like it was good enough to run on the real thing.

There are three separate phases to my code:

Phase 1 - Continuously ON

This phase is when the temperature is above 75 degrees (75 can be easily changed in the code). The air conditioner is then on and will stay on until the sensor reads below 75 degrees.

Phase 2 - Overshooting

This phase occurs right when the temperature transitions from above 75 degrees to below 75 degrees. The air conditioner remains on and stays on for five minutes. At the end of five minutes, it will transition to Phase 3.

Phase 3 - OFF

This phase occurs when the temperature is below 75 degrees and we aren't in the overshooting phase. The air conditioner is off for this phase.

This is will publish the current temperature in Farenheit along with the onOff status (this will always be on but I include for verification that the logging works correctly. The reason for the "|||" (three vertical bars) is because IFTTT interprets that as a break for the next column.

I can connect this to IFTTT by doing the following steps:

;

;

1 / 8 • Start with a new applet. Select "this"

Testing

Testing that the temperature was reading was an informal process where I held an ice cube to the DHT22 and the LCD showed the temperature decreasing and then blowing on it increased the temperature.

Here are the videos for each stage of the device actually working. The hum in the background is the air conditioner working. In the last video, there's a click which is the relay turning off and then the hum goes away.

Phase 1 - Continuously ON

Phase 2 - Overshooting

Phase 2 to Phase 3 - Turning Off

Results/Discussion

Being able to edit code using the Particle Photon in my web browser made the process significantly easier than needing to be physically connected to the device. Integrating the device with IFTTT allows me to track to verify that the air conditioner actually cools when it's on (verification that it operates correctly). I plan on updating this project with the results of this system as the summer gets hotter.

Code

Code for Implementing Design

Arduino

Paste this in your particle program. It requires LiquidCrystal and Adafruit_DHT_Particle libraries

/*
Wiring/instructions for the LCD was done according to:
https://blog.jongallant.com/2015/10/particle-photon-lcd-setup/
Wiring/instructions for the DHT-22 was done according to:
https://learn.adafruit.com/dht?view=all
*/
#include "application.h"#include "LiquidCrystal/LiquidCrystal.h"#include <Adafruit_DHT_Particle.h>#define DHTPIN D6 // what pin we're connected to#define DHTTYPE DHT22 // DHT 22 (AM2302)// 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);// loopCount is what we are going to use as our countdown for the overshooting
int loopCount;// overshootTime is the amount of time you want the air conditioner
// on after it reaches the right temp (in sec)int overshootTime=300;// thresholdTemp is the temperature that you want the device to turn on at
float thresholdTemp=75.0;// averageIndex takes the average of the last five seconds.
// This is so I avoid accidental spikes in reading from DHT22
int averageIndex=0;// averageTemp is the three second average
int averageTemp=0;// average1 and average2 are temporary bits for the average.
int average1=0;int average2=0;// Set up the liquid crystal with the order of how you wired
// (in ascending order so easier)LiquidCrystal lcd(D0, D1, D2, D3, D4, D5);// Set D7 as our relay switch
int relaySwitch= D7;// ########################### SETUP ###########################void setup(){ // set our air conditioner switch to be an output
pinMode(relaySwitch, OUTPUT); // start the DHT-22 device
dht.begin(); // set loopCount to 0loopCount=0; // wait a couple seconds for the DHT-22 to initialize
delay(2000); // set up the LCD's number of columns and rows: lcd.begin(16,2); // Print Temp: to the LCD. lcd.print("Temp: ");}// ########################### LOOP ###########################void loop() { // set the cursor to column 6 ("Test: " takes up 6 characters), line 0 lcd.setCursor(6, 0);// Reading temperature or humidity takes about 250 milliseconds float h = dht.getHumidity();// Read temperature as Celsius float t = dht.getTempCelcius();// Read temperature as Farenheit float f = round(dht.getTempFarenheit()*100)/100; // onOff will indicate whether the air conditioner is on or off. This is for logging. String onOff = "OFF";// Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t) || isnan(f)) { //lcd.print("Failed to read DHT!"); return; } // increase the average index averageIndex++; // if the index is 0 that means that two samples have just // been taken so we can average all three together if ((averageIndex%3) == 0){ averageTemp = (average1 + average2 + f)/3; } else if ((averageIndex%3) == 1){ average1 = f; } else if ((averageIndex%3) == 2){ average2 = f; } // display on the screen the current temperature in farenheight lcd.print(String(int(f)) + " *F "); // we have a one second delay delay(1000); // if the averageTemp is above the thresholdTemp if (averageTemp > thresholdTemp){ // set the cursor on the second row lcd.setCursor(0,1); // display to user that the device is on lcd.print("ON, above " + String(thresholdTemp) + " *F "); // set the loopCount to be the overshootTime loopCount = overshootTime; // set the relaySwitch to LOW (which will turn on the air conditioner) digitalWrite(relaySwitch, LOW); // set the string that gets sent to IFTTT to ON onOff = "ON"; } else if (loopCount > 0){ // set the cursor on the second row lcd.setCursor(0,1); // display to the user that the device is on and how much time is remaining lcd.print("ON, wait: " + String(loopCount) + " s "); // decrease the loopCount loopCount--; // set the relaySwitch to LOW (which will turn on the air conditioner) digitalWrite(relaySwitch, LOW); // set the string that gets sent to IFTTT to ON onOff = "ON"; } else{ // set the cursor on the second row lcd.setCursor(0,1); // display to the user that the device is off // and it's because the temp is below threshold
lcd.print("OFF, below " + String(thresholdTemp) + " *F "); // set the loopCount to 0 which will prevent it
// from turning on unless averageTemp is above threshold
loopCount=0; // set the relaySwitch to HIGH (which will turn off the air conditioner) digitalWrite(relaySwitch, HIGH); // set the string that gets sent to IFTTT to OFF
onOff="OFF";} // Every ten seconds we're going to publish the current temperature
// and the status of whether or not the air conditioner is on or off
if((averageIndex%10)==0&&onOff=="ON"){ Particle.publish("AirConditionerController", String(f) + "|||" + onOff);}}