Smart Home Thermostat

Our Smart Home Thermostat is a program that can automatically save a household money on utility bills based on a person's preferences.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Overview

The Smart Home Thermostat uses a temperature sensor to get the temperature of the home. This temperature reading is put into the program where it will decide whether the air conditioning system needs to heat or cool the house based on the desired homeowner's temperature.

There are two modes for the thermostat: manual and automatic. The manual mode that will adjust the home's temperature to whatever desired temperature is set by the user. And the automatic mode of the thermostat will automatically change the temperature of the home to temperatures preset by the user. There will be two temperature settings for the automatic mode: away temperature and present temperature. The away temperature is used to save energy by changing the thermostat to a preset energy-saving temperature whenever the user is not at home. The present temperature is going to be used when the user is home and wants a comfortable temperature. When in the thermostat's automatic mode, motion sensors actively look for movement to determine if someone is home or not. Based on their reading, the home temperature will either be set to the away temperature or present temperature.

Step 2: Parts and Materials

(15) Jumper Wires

(4) 220 Ohm Resistors

(1) 10K Ohm Resistor

(1) Temp Sensor

(1) Photo Resistor

(1) DAGU Mini DC Gearbox

(1) Diode

(1) Transistor

(1) Photoresistor

(1) Breadboard

(1) Arduino MKR

Step 3: Circuit

Figure 1 = Large Left picture

Figure 2 = Top Right

Figure 3 = Middle Right

Figure 4 = Bottom Right

Figure 1

Using the diagram above, we wired each of our three LEDs. We spaced out each LED since we were working with a large bread board. For smaller bread boards, it may be necessary to put the LEDs closer together. Also, it is unnecessary to power the breadboard since the LEDs draw so little power. We did not use the 5V connection on the breadboard for the LEDs. Each connection from the LEDs to our Arduino was made like the green wire is above. Our red, blue, and green LEDs are connected to the Digital Pin 8,9, and 10 respectively, designated with a red, blue, and green wire in our picture.

Figure 2

The diagram above was used to wire the photoresistor. We made a few corrections of our own; however the concepts are still the same. The photoresistor must be connected to the an analog pin which we have in pin A1. Make sure to use a 10K ohm resistor for the resistor closest to the photoresistor.

Figure 3

This is the diagram used to wire the temperature sensor. Be sure not to mistake the transistor used here with the temperature sensor. They look nearly identical. The temperature sensor will likely have TMP or some other script written on the flat side of the sensor. The wiring here is very simple our temperature sensor is plugged into analog pin A0 with a white wire.

Figure 4

The picture above was used to wire the DAGU Mini DC Gearbox. The green wire attached to the Gearbox is actually the red wire connected to it in our picture. The Gearbox is connected to digital pin 11 with an orange wire in our model. Be sure not to mistake the transistor used here with the temperature sensor. They look nearly identical. The temperature sensor will likely have TMP or some other script written on the flat side of the sensor. You must use the transistor here and not the temperature sensor.


Step 4: Arduino Code

Here, the most important parts of the code are explained. The code will not work with only what is given here. To get the full working code, there is a link at the bottom of the page.

When creating the programmable thermostat's code, one of the first things you do is setup the sensors and create a for loop that will constantly get temperatures readings from the temperature sensor.

Setting up Temperature Sensor and LED:

tempPin = 'A0';<br>%define anonymous function that converts the voltage to temperature
tempCfromVolts = @(volts) (volts-0.5)*100;
samplingDuration = 5; %seconds.  How long do we want to sample for
samplingInterval = 1; %How many seconds between temperature readings
%set up vector of sampling times
samplingTimes = 0:samplingInterval:samplingDuration;
%calculate the number of samples based on the duration and interval
numSamples = length(samplingTimes);
%preallocate temp variables and variable for the number of readings it will store
tempC = zeros(numSamples,1);
tempF = tempC;
%We'll use a for loop this time to take a pre-determined number of
%temperature readings

The for loop:

for index = 1:numSamples<br>    %read the voltage at tempPin and store in variable volts
    volts = readVoltage(a,tempPin);
    tempC(index) = -1*tempCfromVolts(volts+0.3);
    tempF(index) = tempC(index)*(9/5)+32;
    
    %Display formatted output communicating the current temperature reading
    fprintf('Temperature at %d seconds is %5.2f C or %5.2f F.\n',...
    samplingTimes(index),tempC(index),tempF(index));
    %note this display output will only become visiable all at once after the code is
    %done executing unless you copy/paste the code to a plain script mfile.
    pause(samplingInterval) %delay until next sample
end

Next, we create our user menu for the user to decide whether to put the Thermostat in Manual or Automatic mode. We also create an error code if the user doesn't select either of the two options.

The Manual mode menu requires the user to set a number for the thermostat temperature, then it will either heat the home, cool the home, or idle based on readings. To setup this part of the code, you used temperature readings from the temperature sensor and create code that will cool the home when the temperature reading is higher than the set temperature, and heat the home when the temperature reading is lower than the set temperature.

Once you have the temperature readings, you can create the code that will tell the thermostat to cool the home when the temperature reading is higher than the set temperature, and heat the home when the temperature reading is lower than the set temperature. For the prototype, the blue light comes on when the thermostat should cool and the red light comes on when the thermostat should heat.


Menu Setup:

choices = {'Automatic','Manual'};<br>imode = menu('Mode',choices)

if imode>0
	h=msgbox(['You chose ' choices{imode}]);
    else
	h=warndlg('You closed the menu without making a choice')
end
waitfor(h);

The Manual mode requires the user to input a temperature for the thermostat, then based off of the readings from the temperature sensor, it will begin either cooling the house of heating the house. If it the temperature sensor's reading is higher than the set temperature, it will begin cooling the home. If the temperature sensor's reading is lower than the set temperature, it will heat the home.

The Manual mode will start:

if imode == 2<br>	dlg_prompts = {'What temperature would you prefer?'};
	dlg_title = 'Temperature';
	dlg_defaults = {'68'};
	opts.Resize = 'on';  
	dlg_ans = inputdlg(dlg_prompts,dlg_title,1,dlg_defaults,opts);
	if isempty(dlg_ans)
            h=warndlg('You canceled the inputdlg command');
        else
            temp_manual = str2double(dlg_ans{1})
        %[Add Temperature Regulation Setup slide below]
end

Inside of the if statement for the manual mode, you need to write the menu interface for the user to pick their desired home temperature, and then implement a while statement that will regulate the home temperature.

Temperature Regulation Setup:

while temp_manual < tempF<br>	writeDigitalPin(a,'D9',1) 
	writeDigitalPin(a, 'D11', 1);
end
while temp_manual > tempF
	writeDigitalPin(a,'D8',1) 
	writeDigitalPin(a, 'D11', 1);
end

The Automatic mode requires more inputs than the manual mode. After entering the Automatic mode, the user will set a Normal and an Away temperature for their thermostat.After selecting these, based on which mode the thermostat is in, it will go back into the temperature regulation mode

Setup the Automatic mode:

elseif imode == 1<br>	dlg_prompts = {'Normal','Away'};
	dlg_title = 'Temperature Settings';
	dlg_defaults = {'68','64'};
	opts.Resize = 'on';  
	dlg_ans = inputdlg(dlg_prompts,dlg_title,1,dlg_defaults,opts);

	if isempty(dlg_ans)
        h=warndlg('You canceled the inputdlg command');
        else
        temp_normal = str2double(dlg_ans{1})
        temp_away = str2double(dlg_ans{2})
        end
        waitfor(h);
        %[Add Motion Detector Step below]

We also need to setup the motion sensor for the Automatic mode settings. When the motion detector picks up motion, it will keep the temperature on the present temperature setting, otherwise it will set to the away temperature setting.

Run_Motion_Detector(a,inf)<br>
while lightStr == 0 
	temp = temp_away
	while temp < tempF
	   writeDigitalPin(a,'D6',1) whatever pin blue light is in
	   also motor for fan
           writeDigitalPin(a, 'D9', 1);
	end
	while temp > tempF
	   writeDigitalPin(a,'D6',1) whatever pin red light is in
	   also motor for fan
	   writeDigitalPin(a, 'D9', 1);
	end
end

while lightStr == 1
	temp = temp_normal
	writeDigitalPin(a,'D6',1) %change to whatever pin the normal light is in
	while temp < tempF
	   writeDigitalPin(a,'D6',1) whatever pin blue light is in
	   also motor for fan
	   writeDigitalPin(a, 'D9', 1);
	end
	while temp > tempF
	   writeDigitalPin(a,'D6',1) whatever pin red light is in
	   also motor for fan
	   writeDigitalPin(a, 'D9', 1);
	end       
end

The full code can be found here.

Be the First to Share

    Recommendations

    • CNC Contest

      CNC Contest
    • Make it Move

      Make it Move
    • Teacher Contest

      Teacher Contest

    Discussions

    0
    None
    audreyobscura

    6 months ago

    This is an interesting concept! You should enter it into the Epilog Contest!