Introduction: EF 230: Home System 3000 Instructable

The Home System 3000 is a device that uses an Arduino, a temperature sensor, a piezo buzzer, an optical detector/phototransistor, and a servo to display ways to improve home energy efficiency.

Step 1: Temperature Sensor

· Run your power and ground wires from

the micro controller to the side of the bread board

· Place the temperature sensor into the bread board, and run the corresponding power and ground wires accordingly

· Notice that the temperature sensor has three prongs, and the middle prong has a wire that runs from the port "A0".

· Code for temperature sensor:

answer = questdlg('Please run arduino and servo start code','response','Ok','Ok')

prompt = 'Press any key to begin'

pause

prompt1 = 'Set minimum temperature'

x = input(prompt1)

prompt2 = 'Set maximum temperature'

y = input(prompt2)

prompt3 = 'press any key to begin'

pause

figure

h = animatedline;

ax = gca;

ax.YGrid = 'on';

ax.YLim = [65 85];

stop = false;

startTime = datetime('now');

while ~stop

% Read current voltage value

v = readVoltage(a,'A0');

% Calculate temperature from voltage (based on data sheet)

TempC = (v - 0.5)*100;

TempF = 9/5*TempC + 32;

% Get current time

t = datetime('now') - startTime;

% Add points to animation

addpoints(h,datenum(t),TempF)

% Update axes

ax.XLim = datenum([t-seconds(15) t]);

datetick('x','keeplimits')

drawnow

% Check stop condition

stop = readDigitalPin(a,'D12');

Step 2: Buzzer

· Wire in the buzzer that will be used to signal an extreme high or extreme low temperature reading

· No wire is run from the positive column to the positive side of the buzzer

· Instead a wire is run from the positive side of the buzzer to a port labeled "11"

This will be used later to call the location of the buzzer in the written code.

· Code for buzzer:

if TempF >= y

disp('close door it''s hot')

playTone(a,'D11',500,1)

elseif TempF <= x

disp('close door it''s cold')

playTone(a,'D11',250,1)

end

end

Step 3: Optical Detector/Phototransistor

· This sensor requires resisters unlike the others

· Make sure all four prongs of the sensor are included in the loop after plugging in the wires

· The sensor detects a change in light, representing motion, and records it as an input

· Code for Optical Detector/Phototransistor:

clear a

a = arduino('/dev/tty.usbserial-DN01DVI2', 'Uno', 'Libraries', 'Servo');

prompt = 'Set light level threshold'

z = input(prompt)

lightLevel = 0

while lightLevel ~= -1

lightLevel = readVoltage (a,'A1')

if lightLevel >= z

answer = questdlg('would to like to alter AC?','Yes','No')

switch answer

case 'Yes'

answer2 = questdlg('Turn AC up or down?','response','Down','Up','Up')

switch answer2

case 'Down'

s = servo(a, 'D10');

for angle = 0:.1:.5

writePosition(s, angle);

current_position = readPosition(s);

current_position = current_position * 180;

% print current position of servo motor

fprintf('Current position is %d\n', current_position);

% small delay is required so that servo can be positioned at the

% angle told to it.

pause(2);

end

% bring back motor to 0 angle position

writePosition(s, 0);

clear s

prompt = 'Press any key to continue'

questdlg('AC turned down','response','Ok','Ok')

case 'Up'

s = servo(a, 'D10');

for angle = .5:.1:1

writePosition(s, angle);

current_position = readPosition(s);

current_position = current_position * 180;

% print current position of servo motor

fprintf('Current position is %d\n', current_position);

% small delay is required so that servo can be positioned at the

% angle told to it.

pause(2);

end

Step 4: Servo

· The servo represents

an air conditioner, and is an output of the motion detection input

· It requires a positive wire, ground wire, and a wire from port "D9" to the servo

· Code for servo:

% bring back motor to 0 angle position

writePosition(s, 0);

clear s

prompt = 'Press any key to continue'

questdlg('AC turned up','response','Ok','Ok')

end

end

pause

break

end

end

*Special note: some of the code for the servo is integrated with the code for the optical detector/phototransistor.