You are on page 1of 7

Home Automation System

Introduction: The Smart Home Automation System is an application of microcontrollers that


provides convenience, energy efficiency, and enhanced security for residential homes. By
utilizing sensors, actuators, and the PIC18F4520 microcontroller chip, the system can monitor
temperature, motion, and door status to automate various aspects of home control. The system
has three inputs (temperature sensor, motion sensor, and door sensor) and two outputs (smart
thermostat control and smart lighting control).
Inputs:
Temperature Sensor: This sensor measures the ambient temperature inside the home. It provides
real-time temperature readings to the microcontroller, allowing it to make intelligent decisions
based on temperature conditions.
Motion Sensor: This sensor detects motion within a specified area of the home. It uses infrared
or microwave technology to sense human presence or movement.
Door Sensor: This sensor is placed on doors to monitor their status (open or closed). It triggers
when the door is opened or closed, providing information about access to different areas of the
home.
Outputs:
Smart Thermostat Control: The system controls the thermostat to adjust the heating or cooling of
the home based on temperature conditions and occupancy. It can automatically regulate the
temperature to provide comfort and energy efficiency.
Smart Lighting Control: The system controls the lighting in different areas of the home based on
occupancy and time of day. It can turn lights on or off automatically, dim lights, or adjust
lighting levels to conserve energy and provide convenience.
Functionality:
Temperature Monitoring: The microcontroller continuously monitors the temperature sensor
input to determine the current temperature inside the home. It can analyze temperature trends and
compare them to predefined thresholds to assess the comfort level and trigger appropriate
actions.
Occupancy Detection: The microcontroller receives input from the motion sensor to detect
occupancy in different areas of the home. It identifies when someone enters or leaves a room,
providing valuable information for automation and security purposes.
Access Monitoring: The microcontroller utilizes the door sensor input to monitor the status of
doors throughout the home. It detects when doors are opened or closed, allowing for security
monitoring and automation of related systems.
Smart Thermostat Control: Based on temperature readings and occupancy detection, the
microcontroller adjusts the smart thermostat to maintain desired temperature levels. It can turn
on heating or cooling systems when needed and optimize energy usage based on occupancy
patterns.
Smart Lighting Control: The microcontroller controls the smart lighting system, considering
inputs from both the motion sensor and door sensor. It can automatically turn lights on when
motion is detected in a room or when a door is opened. Additionally, it can turn lights off when
no motion is detected or when doors are closed.
Energy Optimization: By integrating temperature control and smart lighting based on occupancy
and time of day, the system aims to optimize energy usage and reduce wastage. It ensures that
heating, cooling, and lighting systems are only active when required, leading to energy savings
and increased efficiency.

Mplab code
#include <p18f4520.inc>

; Configuration bits
CONFIG FOSC = HS ; High-Speed External oscillator (HS)
CONFIG WDTE = OFF ; Watchdog Timer disabled
CONFIG LVP = OFF ; Low-Voltage Programming disabled

; Define I/O pins


TEMP_SENSOR_CHANNEL EQU 0
MOTION_SENSOR_PIN EQU PORTB 0
DOOR_SENSOR_PIN EQU PORTB 1
THERMOSTAT_PIN EQU LATC 0
LIGHTING_PIN EQU LATC 1

; Variables
TEMP_TEMP EQU 0x20
TEMP_RESULT EQU 0x21
TEMP_TEMP1 EQU 0x22
TEMP_TEMP2 EQU 0x23

; Reset vector
ORG 0000
GOTO main

; Interrupt vector
ORG 0008
RETFIE 1

main:
; Initialize I/O ports
BANKSEL TRISB
CLRF TRISB
BANKSEL TRISC
CLRF TRISC

; Initialize ADC
CALL initializeADC

loop:
; Read temperature from sensor
CALL readTemperature
; Control smart thermostat based on temperature
CALL controlThermostat

; Read motion and door sensor inputs


BTFSC MOTION_SENSOR_PIN
GOTO motionHigh
MOVLW 0
MOVWF TEMP_TEMP
GOTO doorCheck
motionHigh:
MOVLW 1
MOVWF TEMP_TEMP
doorCheck:
BTFSC DOOR_SENSOR_PIN
GOTO doorHigh
MOVLW 0
MOVWF TEMP_RESULT
GOTO controlLighting
doorHigh:
MOVLW 1
MOVWF TEMP_RESULT

controlLighting:
; Add code here for controlling lighting based on motion and door status
RETURN

; Delay
delayLoop1:
MOVLW 0xFF
MOVWF TEMP_TEMP1
delayLoop2:
MOVLW 0xFF
MOVWF TEMP_TEMP2
delayLoop3:
DECFSZ TEMP_TEMP2, F
GOTO delayLoop3
DECFSZ TEMP_TEMP1, F
GOTO delayLoop2

; Repeat the loop


GOTO loop

initializeADC:
BANKSEL ADCON1
MOVLW 0x0F
MOVWF ADCON1
MOVLW 0x00
MOVWF ADCON0
BANKSEL ADCON0
BSF ADCON0, ADON
RETURN

readTemperature:
BANKSEL ADCON0
MOVLW TEMP_SENSOR_CHANNEL
MOVWF ADCON0
BSF ADCON0, GO_DONE
readLoop:
BTFSC ADCON0, GO_DONE
GOTO readLoop
MOVF ADRESH, W
MOVWF TEMP_TEMP
MOVLW 0x00
MOVWF TEMP_RESULT
MOVLW 0x01
SUBWF ADRESL, W
BTFSC STATUS, C
INCF TEMP_RESULT, F
RETURN

controlThermostat:
BANKSEL TEMP_TEMP
MOVF TEMP_TEMP, W
SUBWF TEMP_RESULT, W
BTFSS STATUS, Z
GOTO tempHigh
BCF THERMOSTAT_PIN
GOTO tempDone
tempHigh:
BSF THERMOSTAT_PIN
tempDone:
RETURN
END

ERRORS

You might also like