EF230 Smart Home Project

Parts and Materials Needed:

  • 1 Arduino MKR 1000
  • 3 Breadboards
  • 2 Mini Photocells
  • 1 NPN Transistors
  • 1 Mini Power Switch
  • 1 LED – RGB (4 prong)
  • 1 LED (color of your choice)
  • 1 Diode 1N4148
  • 1 10K Ohm Resistors
  • 5 100 Ohm Resistor
  • 1 Temperature Sensor TMP36
  • 1 DAGU 48:1 Ratio Gearmotor
  • 25 Jumper Wires
  • USB Cord
  • MATLAB Program
  • SIK Experiment Guide for the Arduino 101/Genuino 101 Board - SIK Experiment Guide Link

This project details the conceptual design of a smart home system that would use data to help homeowners optimize their energy usage and security. It includes a light sensor to turn on outdoor lights at night, a light sensor for security, and a temperature sensor and fan for indoor temperature control.

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: Light Sensitive LED

  • The light sensitive LED setup is meant to represent the outdoor lights at a house coming on at night.
  • When the mini photocell senses a reduced amount of light the LED will light up.
  • For a smart home this has energy and security implications. It will save energy by leaving the lights off during the day and will provide increased security at night.
  • The exact wiring and setup for this part of the project can be found under experiment 7 in the SIK Experiment Guide.

Step 2: Mini Power Switch

  • The switch is the first step in the security process of the smart home.
  • When turned on, the switch will initiate a response asking the user if they wish to enter 'Home' mode or 'Away' mode.
  • If 'Home' mode is selected the security is considered disarmed, but selecting 'Away' mode will arm the security system.
  • The wiring for this portion of the project can be found under experiment 6 in the Experiment Guide. For the purposes of the smart home, the LED's and their connecting wires found in experiment 6 do not need to be included.

Step 3: Second Photocell

  • The second photocell serves as a motion sensor for the security system of the smart home.
  • The sensor is only used when the system is put in 'Away' mode as described in the previous step.
  • If the photocell experiences a decrease in the amount of light it receives, it recognizes this as motion inside the house.
  • The setup for this part of the project can be found under experiment 7 in the SIK Experiment Guide. However, only the photocell and its connecting wires needs to be included in the wiring.

Step 4: RGB LED

  • The RGB LED is used in conjuction with the mini power switch and the second photocell for the security system of the smart home.
  • The three different colors are used as indicators for the smart home resident.
  • When the system is placed in 'Home' mode, the LED turns blue. When the system is placed in 'Away' mode the LED turns green. When the photocell used as a motion sensor is tripped, the light flashes red.
  • The wiring for the RGB LED can be found in experiment 3 of the SIK Experiment Guide.

Step 5: Temperature Sensor

  • The temperature sensor is major part of conserving energy in the smart home.
  • The resident is able to input a desired temperature for their home when the smart home is in use.
  • Temperature sensor is how the system knows how far the actual temperature is from the desired temperature.
  • Setup for the temperature sensor can be found in experiment 9 of the SIK Experiment Guide.

Step 6: DAGU Gearmotor

  • The motor allows the smart home to regulate the temperature in the house based on the desired temperature and the readings of the temperature sensor.
  • Acting as the AC unit in the home, the motor will spin at different speeds based on how much higher the actual temperature is than the desired temperature. The higher the difference, he faster the motor spins.
  • The wiring for the motor can be found in the Experiment Guide under experiment 11.

Step 7: Code

  • The code for the smart home includes multiple user interfaces that allows the resident to easily understand how it works and to easily change the settings.
  • With the smart home system, the resident will receive and email alert if the motion sensor is set off while they are away.
  • The only change that needs to made is inserting the information for the sender's email and the recipient's email address.

clear a; clear s; clear m; clc; close all; % Clear arduino and servo variables so they can be redefined each time so the code will run effectively ("clear m" is necessary for one of the while loops to function properly)
a = arduino(); % Set the arduino variable

s = servo(a, 'D6'); % Set the servo variable

% Initialize email variables for security system warning email

emails = {'insert recipient address'}; % Array of emails to have the security email sent to

% Email preference settings necessary for using a Gmail to send mail from

setpref('Internet','E_mail','sender's email address');

setpref('Internet','SMTP_Username','sender's username');

setpref('Internet','SMTP_Password','sender's password');

props = java.lang.System.getProperties;

props.setProperty('mail.smtp.auth','true');

props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory'); props.setProperty('mail.smtp.socketFactory.port','465');

% Email subject and text variables

subj = 'Intruder Alert at Your Home';

text = 'Hello, This is your Smart Home security system informing you that there has been motion detected outside your home. We have taken the necessary measures and contacted authorities for you. Stay safe.';

while true

prompt = {'Enter desired home temperature (between 65F and 85F):'}; % Prompt for user input menu

dlgtitle = 'Temperature Select'; % Title for user input menu

dims = [1 30]; % Dimensions for user input menu

definput = {'72'}; % Default input that shows up when menu is first opened

tempsel_array = inputdlg(prompt, dlgtitle, dims, definput); % Popup user input menu that will save the entered number into an array

if ~isempty(tempsel_array) % If the array is NOT empty

tempsel_char = cell2mat(tempsel_array); % Convert the array to a character string

tempsel = str2double(tempsel_char); % Convert the character string to numbers

thingSpeakWrite(chID, tempsel, 'WriteKey', writeKey, 'Fields', 1); % Write the selected temperature to your ThingSpeak channel

break % Break from the while loop so the menu won't pop up multiple times

else % If the user clicks cancel instead of entering a temperature

msg1 = msgbox('No temperature selected, defaulting to 85F', 'Warning!'); % Message displayed to user after clicking cancel

waitfor(msg1); % Wait for the message box to close before continuing

tempsel = 85; % Set the temperature to what was stated in the message box

thingSpeakWrite(chID, tempsel, 'WriteKey', writeKey, 'Fields', 1); % Write the selected temperature to your ThingSpeak channel

break % Break from the while loop so the menu won't pop up multiple times

end

end

while true

chID = 745517; % ThingSpeak Channel ID

writeKey = 'G9XOQTP8KOVSCT0N'; % Key for access to the ThingSpeak Channel

% Initialize sensors to fetch data

tempread = readVoltage(a, 'A3'); % Read the voltage of the temperature sensor

lightl1 = readVoltage(a, 'A2'); % Light level for the photoresistor going to the red LED

lightl2 = readVoltage(a, 'A5'); % Light level for the photoresistor going to the security system

switchv = readVoltage(a, 'A0'); % Value for the switch

% Convert the temperature data from voltage to degrees Fahrenheit

tempC = (tempread - 0.5) * 100; % Convert voltage to temperature in Celsius

tempF = (tempC * 9/5) + 32; % Convert temperature in Celsius to temperature in Fahrenheit

% Initialize the pin numbers for the multicolor LED

redp = 'D9'; % Pin for red light from LED

greenp = 'D10'; % Pin for green light from LED

bluep = 'D11'; % Pin for blue light from LED

if tempsel < tempF % If the selected temperature is greater than the room temperature

writePosition(s, 1); % Servo will begin moving

pause(10) % Servo will keep spinning for 10 seconds to represent that the AC would turn off after a specified amount of time

writePosition(s,0); % Turn off fan for purpose of continuing code without fan on

tempsel = 150; % Change the temperature value to break out of the loop after the fan has turned off, again just for the purpose of continuing the code

end

if lightl1 <= 3 % If the first photoresistor detects a low light level

writeDigitalPin(a, 'A1', 1); % Turn on red LED that represents outdoor lights

else % If the light level is high again

writeDigitalPin(a, 'A1', 0); % Turn off red LED when the light level is high enough again

end

if switchv > 3 % If the switch is turned on

A = exist('m', 'var'); % Check for the existence of variable 'm', this will initialize for the while loop and allow it to be broken when a menu item is selected (this is why clear m must be done at the start of the code)

while A==0 % Loop will execute until variable 'm' exists

menutext = 'Which security mode would you like to enter?'; % Text for the security popup menu

choices = {'Home', 'Away'}; % Choices for the security popup menu

m = menu(menutext, choices); % Popup menu for security system modes

break % Ensures that the while loop is broken so the menu will not pop up multiple times

end

if m == 1 % If 'Home' mode is selected

writeDigitalPin(a, bluep, 1); % Turn on just blue light in the color changing LED

writeDigitalPin(a, redp, 0);

writeDigitalPin(a, greenp, 0);

elseif m == 2 % If 'Away' mode is selected

writeDigitalPin(a, bluep, 0);

writeDigitalPin(a, redp, 0);

writeDigitalPin(a, greenp, 1); % Turn on just the green light in the color changing LED

if lightl2 <= 3 % If the light level in the second photoresistor is low, representing motion detected by the security system

sendmail(emails, subj, text); % Send an email with the previously defined email properties writeDigitalPin(a, greenp, 0); % Flash red color on and off 2 times

writeDigitalPin(a, redp, 1);

pause(0.3)

writeDigitalPin(a, redp, 0);

pause(0.3)

writeDigitalPin(a, redp, 1);

pause(0.3)

writeDigitalPin(a, redp, 0);

pause(0.3)

writeDigitalPin(a, redp, 1); % Finish with solid red after flashing to show there is motion until the light level goes back up

msg2 = msgbox('Intruder detected by security system, an email has been sent to the homeowners to inform them.', 'WARNING!'); % Message box to inform user of motion and to inform about the email sent waitfor(msg2) % Wait for the message box to close before continuing

else

writeDigitalPin(a, greenp, 1); % Once the light level has risen again it will turn back to green

end

end

elseif switchv < 3.3 % If the switch is turned off

writeDigitalPin(a, bluep, 0); % Turn off the LED completely to show the security system is off

writeDigitalPin(a, redp, 0);

writeDigitalPin(a, greenp, 0);

end

end

Be the First to Share

    Recommendations

    • Assistive Tech Contest

      Assistive Tech Contest
    • Reuse Contest

      Reuse Contest
    • Made with Math Contest

      Made with Math Contest

    Discussions