0% found this document useful (0 votes)
57 views37 pages

Project Documentation

This document describes a student project to create a home automation system using Verilog. The project includes modules for home automation control, password security, water tank level monitoring, comfort features for lights and cooling, and emergency response. It will allow automated and remote control of devices in the home, prevent water and energy waste, and send alerts in emergency situations to help ensure home and personal security. The system is designed to address common problems experienced in Indian homes around security, resource management, and assisting elderly family members.

Uploaded by

Sri Karan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views37 pages

Project Documentation

This document describes a student project to create a home automation system using Verilog. The project includes modules for home automation control, password security, water tank level monitoring, comfort features for lights and cooling, and emergency response. It will allow automated and remote control of devices in the home, prevent water and energy waste, and send alerts in emergency situations to help ensure home and personal security. The system is designed to address common problems experienced in Indian homes around security, resource management, and assisting elderly family members.

Uploaded by

Sri Karan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

DSD MINI PROJECT

PROJECT TITLE : HOME AUTOMATION USING VERILOG

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

NATIONAL INSTITUTE OF TECHNOLOGY WARANGAL


(2018-19)

SUBMITTED TO: Dr . V. NARENDAR


SUBMITTED BY: R. GAYATHRI
ROLL NO: 174144
CONTENTS
1.1 INTRODUCTION
1.2 LITERATURE
2.1 MODULES
2.2 FLOWCHART
2.3 BLOCK DIAGRAM
2.4 ASM CHART OF TOP MODULE
2.5 MULTIPLEXER BASED IMPLEMENTATION OF TOP MODULE
2.6 RTL SCHEMATIC
2.7 SIMULATION RESULTS
3.1 CONCLUSION
3.2 FUTURE WORK

APPENDIX
(A) REFERENCES
(B) CODE
HOME AUTOMATION USING VERILOG
1.1 INTRODUCTION
In the present time with the increasing technology everyone wants their home

to be a smart home. Not only smart a home must also be secured due to the increase in of

robberies and thefts in our society. There are many more problems existing in the home which

can be resolved by the growing technology very easily. Many of us while going to jobs leave

our elder family members alone. They are very frequently attacked by health problems like

heart attacks which demands them to admit them in a nearby hospital as soon as possible.

We may not when they need our help. To know their present condition we need to monitor

them almost once in every hour which is almost impossible in our daily hectic life schedule.

Installing a monitoring system for our house not only costs more but also we might be

encountered with situations when we would be very busy and may not be able to answer the

notifications given by the monitoring system. So, it is better the home automation system

installed does this job for us as this is also one of the biggest problem which we are going to

face in the future. It should develop a mechanism to provide help during the emergency

situations and then concentrate on the comfort which most of the home automation models

present in the society do not do. They mostly give priority to the comfort rather than security

and help during emergency situations and make other day to day tasks easier. The other

biggest problem which we are facing is the water scarcity in most of the parts of our country

and in near future we might be facing a situation where we won’t have water to drink. In that

situations we have to avoid the wastage of water by preventing the overhead tank overflows.

In many of the houses we observe the overflow of overhead tanks because of not switching

off the power supply to the motor in time. And we might have also forgot to switch on the

motor to the overhead water tank and realise lately that it is empty. These are some of the

most important problems in our home which seems to be very simple but causes a lot of

trouble to us and they also needs a keen attention to solve them.


A home automation should consider even the very small problems in the home

and make it not only the smart but also the peaceful as well as environment friendly by

preventing the wastage. It should meet our day to day requirements so it is better equipped

with as many facilities as possible to really make it smart from the others. It takes data from

the various sensors like temperature sensor, luminous intensity sensor, fire sensor, motion

sensor and takes necessary actions according to the inputs which it gets. It also gives the

corresponding outputs to control the happening of various action inside the house.

This home automation system controls many inputs at home such as lights

and coolers. The comfort system of this project is limited to the control of just light and cooler.

It ensures the security of home by a password to enter the home by a password to enter the

home and to disarm the security system when the person is not at home and to disarm the

security system when the person is not at home the security system is armed. When the

security system is disturbed when no one is at home it immediately activates an alarm.

Security system is disarmed when person enters the home and stays inside. It also provides

help during the emergency situations for the people inside by sending information to the

hospital and the concerned people. And it also prevents the overflow and empty of the

overhead water tank by switching on and off the power supply to the motor which supplies

water to the overhead water tank in the correct time.

1.2 LITERATURE

Home automation began with the labour saving machines like washing

machine and vacuum cleaner. All these machines discovered to do their job efficiently and

decrease the human effort. Most of the commercially available home automation systems

requires all the controllable appliances from the same company or which supports that

company type. These devices come with a dedicated controlled device which need to be
purchased separately. These complex systems need to be integrated during the construction

of the building and also it is very difficult to upgrade them once installed. It costs very high

and need a separate specialised system to operate all the home appliances. But in later time

home automation system controlled by a wifi or a bluetooth mobile device were introduced

into the market. This reduces the cost of operation from the previous system and also makes

easy to operate. The first ever home automation introduced was a Bluetooth based one in

2001. It uses wireless technology. It also has many disadvantages like slower response,

complex design and large hardware. And it is replaced by a microcontroller based design in

2002 because it works with high speed. Its disadvantages are large programming and having

multiple integrated circuits. Then an automation model was introduced in 2007 which uses

wireless communication and provides easy accessibility which is called as network monitoring

and has disadvantage of hacking and it does not have large features. In 2011 a high feature

FPGA system was introduces which has programmable gates and high speed response with

secured features. It has disadvantage because memory can be easily erases and

reprogrammable, design specific, it costs very high and much memory is required. With the

rapid speed in increasing technology day by day new technology based systems are coming

into the market and replacing the old ones. By the next year high featured FPGA is replaced

by Advanced automation FPGA which provides access to many features, high speed, multiple

appliances has large applications in vast fields. It even has the disadvantages like high cost,

design specific and it uses volatile SRAM type of memory. The home automation system

implemented in hardware using Field Programmable Gate Array uses sensors for controlling

home appliances. This system uses wireless technology to improve the standards of the living

of the people.

2.1 MODULES

This project has various modules for various tasks to be done and are

integrated to form a single top module.


HOME AUTOMATION MODULE

This module is the top module in the project which takes all the external inputs

from the user and the sensors and provide intermediate outputs or inputs to the submodules

and provides the outputs to the external world. The user password which is input from the

user is passed to the password module. And the functioning of both the emergency and

comfort modules is done only when they are high which is externally given by the user and is

sent to the respective modules. It also constantly receives input from the fire sensor which is

placed everywhere in the home except in the kitchen which warn us about the short circuit

situations occurs in the home. This is the only module which has the connection from the

external world.

PASSWORD MODULE

It is the one which takes input from the home automation module and is the

only way through which user can enter his home by entering the user password. Only if the

user enters the correct password he can go inside the home otherwise he cannot enter. If the

entered password goes wrong alarm system will be activated. If the person is leaving the

home reset input goes high and the security system of the home is activated. When the

person enters the home security system of the home is disarmed.

WATERTANK MODULE

Water tank module receives the input from the sonar sensor which is attached

to the top of the overhead water tank. The sonar sensor is used to detect an obstacle at

particular minimum and maximum amount of distance. It sends high input to the motor

switch which supplies power to the motor which supplies water to overhead water tank when

the obstacle is detected at maximum defined distance which means when the tank goes

empty. It makes the power supply to the motor switch low when the obstacle is detected at
minimum predefined distance which means when the tank becomes full. Thus, it prevents the

overflow of overhead water tank and prevents the wastage of water. For this system to work

properly sonar sensor must be attached properly to the overhead water tank.

COMFORT MODULE

It controls the light and cooler in the home. It has one external input comfort

which when goes high cooler will be even when the temperature is more than 33 degrees

even when no motion is detected by the motion sensor. Inputs to this module is taken from

the motion sensor, temperature sensor and luminous intensity sensor. When the motion in

the room is detected by the motion sensor the light is turned on if the luminous intensity

detected in the room is less than 13 lumens. And the cooler is turned on when the

temperature detected is greater than 33 degrees. If no motion is detected in the room

whatever might these sensors sense no external input to the cooler and light is given unless

and until comfort input is high.

EMERGENCY MODULE

An external input emergency is given to this module by the user. It is given high

when there is no one to take care of the elder people present at the home. This module sends

a output to gsm module which activates a protocol and sends a call to the concerned family

member and the hospital ambulance when there is no motion detected in the house in the

predefined amount of time. It shows that there might be a chance that the elder people might

have got a health issue. It also activates an alarm until any motion is detected which means

elder person might get help from the people living in the neighbourhood that is why alarm is

activated until any motion is detected indirectly until any person comes for help.

SECURITY MODULE
It is the backbone for all the security system that is being installed in the home.

It has various submodules which controls the state of window, door as per the input getting

from the window and door sensors. As per the inputs from window and door sensor the state

of window and door is being given as the output. When the security system of the home goes

high and if any of the window or door are left open alarm for the respective part is activated.

If motion is detected in the home when security module is high alarm will be activated as

security module goes high only when no one is present in the home.

DOOR MODULE

Door module receives the security input from the security module. It also

receives input from the magnetic sensor attached to the door which tells us the state of the

door whether the door is opened or closed. The same output is displayed showing the state

of the door to the user in his device. When the input from the security module is high and any

of the door is opened the alarm is activated due to having a suspicion that a theft might have

entered the home through that door.

WINDOW MODULE

Window module receives the security input from the security module. It also

receives input from the magnetic sensor attached to the window which tells us the state of

the window whether the window is opened or closed. The same output is displayed showing

the state of the window to the user in his device. When the input from the security module is

high and any of the window is opened the alarm is activated due to having a suspicion that a

theft might have entered the home through that window.

FIRE MODULE

Fire module is the sub module in the home automation module. It constantly

receives the input from the fire sensor. If the fire sensor goes high there might be a chance

that the home catches fire in a short time. When it goes high alarm is activated. Otherwise

alarm goes low


2.2 FLOW CHART

HOME AUTOMATION

PASSWORD WATER TANK EMERGENCY

SECURITY SONAR SENSOR MOTOR SWITCH

DOOR SENSOR WINDOW SENSOR MOTION SENSOR

DOOR ALARM WINDOW ALARM MOTION ALARM

ALARM COMFORT ALARMM

LIGHT SENSOR TEMPERATURE SENSOR GSM OUTPUT

LIGHT SWITCH
COOLER SWITCH

FIRE SENSOR

FIRE ALARM
2.3 BLOCK DIAGRAM

clk sec
in[3:0] door_state
temp[1:0] door_alarm
lum[1:0] window_state
motion_sensor window_alarm
fire_sensor alarm
HOME AUTOMATION
door_sensor alarmm
window_sensor motion_alarm
comfort motor_switch
emergency gsm
sonar_sensor light
reset cooler
fire_alarm

BLOCK DIAGRAM DESCRIPTION


INPUTS
in[3:0] :
This is the external input given by user to enter his home which is also called as password.

clk :

The clock pulse is also given as the input to the system which changes from low to high for

every predefined amount of time.


temp[1:0] :

It is the input given by the temperature sensor to the comfort system in terms of degrees.

lum[1:0] :

It is the input given by the luminous sensor to the comfort system in terms of lumen.

motion_sensor :

It Is a sensor which detects the motion in a room by sending electromagnetic waves and

observing the disturbance in them because of the movement.

fire_sensor :

This sensor detects the some if any present inside a room.

door_sensor :

A magnetic sensor is attached to a door which tells us the state of the door whether opened

or closed.

window_sensor :

A magnetic sensor is attached to a window which tells us the state of the window whether

opened or closed.

comfort :

This input is high when people are sleeping in the house because at that time motion sensor

might not detect motion inside the home and cannot produce comfort to the people staying

inside the house. It switches on the cooler then the temperature inside the room raises

beyond 33 degrees.

emergency :

It is set high by the house owners when they are leaving elder people alone at the house.

sonar_sensor :
It is the sensor attached to the overhead water tank to know whether water tank became

empty or full.

reset : This input is set high by the user when he is leaving the house.

OUTPUTS
sec :

It is the output given by the password module to tell whether the security of the home should

be activated or not.

door_state :

This shows the state of the door whether opened or closed to the user.

door_alarm :

When the security system of the house is high and then if any of the door is opened door

alarm is activated.

window_state :

This shows the state of the window whether closed or opened to the user.

window_alarm :
When the security system of the house is high and then if the window is opened window

alarm is activated.

alarm :

This alarm is activated when the password entered by the user goes wrong.

alarmm :

This alarm is activated when motion is detected inside the house even after the security

module is working.

motion_alarm :
This alarm is activated when no motion is detected for a predefined amount of time in the

house if the emergency input is set high by the user.

motor_switch : Power supply to motor switch is given when maximum distance is detected
by the sonar sensor.
gsm :
High input is send to this module when no motion is detected inside the house within

predefined amount of the time when the emergency input is set high by the user.

light :
Power supply is given to this switch when the luminous intensity sensor detects the
brightness less than 13 lumen.
cooler :

Power supply is given to this switch when the temperature inside the room is detected more

than 33 degrees.

fire_alarm :
This alarm is activated when smoke is detected by the smoke sensor.

2.4 ASM CHART OF THE TOP MODULE


REPRESENTATIONS OF VARIOUS VARIABLES :
A : reset I : counter for predefined time with input from motion sensor
B : input password J : door sensor input
C : motion sensor input K : window sensor input
D : temperature sensor input
E : luminous intensity sensor input
F: fire sensor input
G : sonar sensor input
H : emaergency input
INITIAL STATE

A T

F
T F
B

COMFORT

F SEC ALARM
C

T
FIRE MODULE

F
F F
D E F

T
T T

FIRE ALARM
COOLER LIGHT
INITIAL STATE

WATER TANK EMERGENCY

F
G H

T
T

MOTOR
SWITCH F
I

MOTION
ALARM GSM

SECURITY

DOOR MODULE WINDOW MODULE C

T
T
T K WINDO SEC
J DOOR
W STATE
STATE

F F T

DOOR WINDOW ALARMM


ALARM ALARM
DESCRIPTION OF ASM CHART
Initially when the system is ON first it checks whether the person is not at home

or not. If person is not at home security of the system is made high. Otherwise the person

needs to enter the password to enter the house. If the password is correct he can enter the

house otherwise the security system of the home as well as alarm system is activated. When

the person enters home the comfort module of the home is activated as the motion is

detected. It checks whether the temperature is greater then a particular value or not if it is

greater the power supply to the cooler switch is given otherwise it again goes to the starting

of the comfort module. Same with the case of luminous intensity sensor if motion is detected

and intensity detected by the luminous intensity sensor is less than a particular lumens then

the power supply is given to the light switch otherwise it again goes to the starting of the

comfort module. Fire sensor is always activated when the person stays in the home or not if

the fire sensor goes high then the fire alarm is activated. Water tank module is also activated

whether a person stays in the house or not. If the sonar sensor goes high then the tank goes

empty and the power supply is given to the motor switch and when the minimum distance is

detected by the sensor it goes low and power supply is removed to the motor switch. When

the emergency input of the system goes high the sensor checks whether the motion is

detected in a particular time or not if not alarm is activated until motion is detected and signal

is sent to gsm module so that it can activate a protocol to call for ambulance. This module

need to activated by the user by giving an external input to the controller.

When the security module is activated which happens when no one is at home or

the password entered by the user goes wrong. If the security system of the house is high it

checks whether the door and window of the house are open or closed. If they are opened

alarm system is activated and the state of the door is displayed to the user. If the security

system of the house is not high then no alarm is activated even if door and window is opened

or not. In this situation it just updates the state of the door to the user. If motion is detected
inside the house when the security system is high alarm is activated. In any one of the cases

the clock pulse again goes to the security module state.

ASM TABLE

PRESENT STATE INPUTS NEXT STATE OUTPUT


XYZ A B C D E F G H I J K xyz M
000 1 X X X X X X X X X X 000 Sec

0 0 X X X X X X X X X X 000 Sec, alarm

0 1 X X X X X X X X X X 001 No output
001 X X 0 X X X X X X X X 001 No output

X X 1 0 0 X X X X X X 001 No output

X X 1 0 1 X X X X X X 001 Light

X X 1 1 0 X X X X X X 001 Fan

X X 1 1 1 X X X X X X 001 Light and Fan


010 X X X X X 0 X X X X X 010 No output

X X X X X 1 X X X X X 010 Motor Switch


011 X X X X X X 0 X X X X 011 No output

X X X X X X 1 X X X X 011 Fire alarm


100 X X X X X X X 0 0 X X 100 No output

X X X X X X X 0 1 X X 100 No output

X X X X X X X 1 0 X X 100 No output

X X X X X X X 1 1 X X 100 Motion alarm


101 X X 0 X X X X X X X X 101 No output

X X 1 X X X X X X X X 101 Alarmm
110 X X X X X X X X X 0 X 110 Door state

X X X X X X X X X 1 X 110 Door state and alarm


111 X X X X X X X X X X 0 111 Window state

X X X X X X X X X X 1 111 Window state and alarm


EXPRESSIONS FOR OUTPUTS AND FLIPFLOP INPUTS:
As there are eight states involved three flipflops x, y, z are being used for the
implementation.

x=1
y=1
z=(~A) & B

2.5 MULTIPLEXER BASED IMPLEMENTATION OF THE HOME


AUTOMATION MODULE

8:1 MUX1 D FLIP FLOP


CLK

OUTPUT
8:1 MUX2 D FLIP FLOP MODULE
CLK

8:1 MUX3
D FLIP FLOP
CLK
INPUTS TO THE MULTIPLEXER 1 ARE:
0,0,0,0,1,1,1,1
INPUTS TO THE MULTIPLEXER 2 ARE:
0,0,1,1,0,0,1,1
INPUTS TO THE MULTIPLEXER 3 ARE:
(~A)&B , 1,0,1,0,1,0,1
8:1 multiplexer is used because there are three flip flops and the inputs to the

select lines of the flip flops are X,Y,Z. The inputs to flip flop 1, flip flop 2, flip flop 3 are x, y, z

respectively. Same clock signal is fed to all the flip flops simultaneously. As we are

implementing the project using multiplexer based design implementation the outputs of

flipflops are being fed to a 3:8 decoder to get the external outputs of this project.

OUTPUT MODULE:

3:8 DECODER
OUTPUTS FROM THE DECODER ARE:
Sec, No output, No output, No output, No output, No output, Door, Window

The remaining outputs are obtained by the gate operations with the
external inputs. Here inputs directly depend upon the external inputs so the implementation
is by mealy state machine.
The expressions for the remaining outputs are:
alarm= (first output from decoder) & B
light= (second output from decoder) & E
cooler= (second output from decoder) & D
light & cooler= (second output from decoder) & D & E
fire alarm= (third output from decoder) & F
motor switch= (fourth output from decoder) & G
motion alarm= (fifth output from decoder) & H & I
alarmm= (sixth output from decoder) & C
door state & door alarm= (seventh output from decoder) & J
window state & window alarm= (eighth output from decoder) & K
2.6 RTL SCHEMATIC
RTL stands for Register Transfer Level. It is nothing but a design abstraction

which models the synchronous digital circuit in terms of the flow of the digital signals between

hardware registers and logic operations performed on those signals. Register Transfer Level

is used in hardware description languages like Verilog and VHDL to create high-level

representations of a circuit, from which lower-level representations and ultimately actual

wiring can be derived. RTL Schematic of any project shows all the inputs and outputs included

in the project and the interconnections made among them.


2.7 SIMULATION RESULTS
Behavioral simulation on the design of a project is done before the synthesis. This first

pass simulation is typically performed to verify RTL code and to confirm whether the circuit

which we designed by writing code in behvioral level is functioning as intended or not. A test

bench must be written to perform the simulation of a particular project file. Test bench is

nothing but the sample test cases written manually by the design developer to check whether

we are getting the desired output for the given inputs or not.

The below shows the simulation results of the project home automation using
Verilog. It shows the outputs for the corresponding inputs up to particular clock pulse of time.
3.1 CONCLUSION
The goal of this project to create a controller for all home appliances at cheaper

cost is achieved which provides an automated home security. This is a low cost effective

device and with few more changes it can be made a little more advance making it web

enabled. This method is very easy to adapt and implement and can be easily embedded into

another device. The hardware description language Verilog used to implement the code part

has really helped since it not only combines software and hardware part, it also provides

informative graphs and waveforms which are helpful in understanding the real concept of the

project. The waveforms obtained after simulation are as expected hence we can say that the

project was done successfully and ready for the implementation.

3.2 FUTURE WORK


Devices and sensors can be used to implement the hardware part. The code

can be converted into high level language and can written on a chip creating a physical device.

This can be embedded into a phone or laptop so that it will be easy to operate. And this

implementation can be taken up to gate level so that we can optimise the speed as well as

the power consumption of the device. By taking up to gate level the circuit design of the

project can be optimised. And even this project can be improvised further by adding more

number of actions for cooking range and so on.


APPENDIX
REFERENCES
[1] K. Madhuri, B. L. Sai and B. S. Sirisha, “A home automation system using hardware
descriptive tool,” Ijert, vol.2, July 2013.
[2] C. Links. (2013). Sensors Insights.
[3] Xilinx, “Using Block RAM in Spartan-3 FPGAs”, XAPP463 (v1.1.2), July 23, 2003
[4] Finite State Machine, Wikipedia the free encyclopedia.
[5] Palnitkar, S. (2008). Verilog HDL (2nded.). Pearson Education. [6] Verilog. Wikipedia, the
free encyclopedia. Retrieved March 23, 2012.
[7] Xilinx, “ISE In-Depth Tutorial”, UG695 (v11.2) June 24, 2012
[8] Xilinx, “Spartan-3 Generation Configuration User Guide”, UG332 (v1.6), October 26, 2009
[9] Thomas L. Floyd, “Digital Fundamentals: Eighth edition”, Pearson
[10] Kim, Eung Soo, Kim, Min Sung, “Design and fabrication of security and home automation
system”, ICCSA 2006, International Conference Computational Science and Its Applications,
Proceedings - Part III, 2006, pp. 31-37.
[11] Fujiyama Hiroyuki, “System-on-a-chip with security modules for network home electric
appliances” Fujitsu Scientific and Technical Journal, v 42, n 2 System-on-a-Chip, 2006, pp. 227-
233.
[12] A. Alheraish, “Design and Implementation of Home Automation System,” IEEE
Transactions on Consumer Electronics, vol. 50, no. 4, Nov. 2004, pp. 1087-1092.
[13] Wobschall.D, Circuit Design For Electronic Instrumentation: Analog and Digital Devices
from Sensor to Display, New York: Mcgraw-Hill,1979.
[14] VHDL Tutorial by Jan Van der Spiegel, University of Pennsylvania, Department of Electrical
Engineering . Available: http://www.seas.upenn.edu/~ee201/vhdl/vhdl_prim
er.html#_Toc526061341
[15] Thomas Petruzzellis, The Alarm, Sensor & Security Circuit Cookbook, Mcgraw-Hill, 1994
[16] Ion Grout, Digital Systems Design with FPGAs and CPLDs, Elsevier Ltd, 2008
CODE
TOP MODULE CODE
module home_automation(
input clk,
input [3:0]in,
input reset,
input sonar_sensor,
input emergency,
input motion_sensor,
input comfort,
input [1:0]temp,
input [1:0]lum,
input fire_sensor,
input window_sensor,
input door_sensor,
output wire sec,
output wire alarm,
output wire motor_switch,
output wire gsm,
output wire motion_alarm,
output wire light,
output wire cooler,
output wire fire_alarm,
output wire window_state,
output wire window_alarm,
output wire door_state,
output wire door_alarm,
output wire alarmm
);
password a(reset,in,clk,sec,alarm);
watertank b(sonar_sensor,clk,motor_switch);
emergency c(clk,emergency,motion_sensor,gsm,alarmm);
comfort d(clk,comfort,motion_sensor,temp,lum,light,cooler);
security
e(clk,sec,motion_sensor,window_sensor,fire_sensor,door_sensor,fire_alarm,door_state,do
or_alarm,window_state,window_alarm,motion_alarm);

endmodule

PASSWORD MODULE CODE


module password(
input reset,
//input [15:0]in,
input [3:0]in,
input clk,
output reg sec,
output reg alarm

);
reg [3:0]arr;
integer i;
initial begin
arr<=4'd12;
alarm=1'b0;
sec=1'b0;
end
always @(posedge clk)
begin
if(reset)
begin
alarm=1'b0;
sec=1'b1;
end
else if(arr==in)
begin
alarm=1'b0;
sec=1'b0;
end
else
begin
alarm=1'b1;
sec=1'b1;
end
end
endmodule

WATERTANK MODULE CODE


module watertank(
input sonar_sensor,
input clk,
output reg motor_switch
);
initial begin
motor_switch=1'b0;
end
always @(posedge clk)
begin
if(sonar_sensor)
begin
motor_switch=1'b1;
end
else
begin
motor_switch=1'b0;
end
end
endmodule

EMERGENCY MODULE CODE


module emergency(
input clk,
input emergency,
input motion_sensor,
output reg gsm,
output reg motion_alarm
);
reg [10:0]count;
reg x;
reg [4:0]i;
initial begin
x=1'd0;
i=x;
end
always @(posedge clk)
begin
motion_alarm=1'b0;
gsm=1'b0;
if(emergency)
begin
count[i]=motion_sensor;
i=i+1'd1;
if(motion_sensor)
begin
i=x;
end
if(i>'d5)
begin
motion_alarm=1'b1;
gsm=1'b1;
end
end
else
begin
motion_alarm=1'b0;
end
end
endmodule

COMFORT MODULE CODE


module comfort(
input clk,
input comfort,
input motion_sensor,
//input [6:0]temp,
//input [6:0]lum,
input [1:0]temp,
input [1:0]lum,
output reg light ,
output reg cooler
);
reg [1:0]tem,lu;
initial begin
tem=2'd1;
lu=2'd3;
end
always @(posedge clk)
begin
light=1'b0;
cooler=1'b0;
if(motion_sensor)
begin
if(temp>tem)
begin
cooler=1'b1;
end
if(lum<lu)
begin
light=1'b1;
end
end
if(comfort)
begin
if(temp>tem)
begin
cooler=1'b1;
end
end
end
endmodule

SECURITY MODULE CODE


module security(
input clk,
input sec,
input motion_sensor,
input window_sensor,
input fire_sensor,
input door_sensor,
output wire fire_alarm,
output wire door_state,
output wire door_alarm,
output wire window_state,
output wire window_alarm,
output reg alarmm
);

initial begin
alarmm=1'b0;
end
fire a(fire_sensor,clk,fire_alarm);
window b(window_sensor,clk,sec,window_state,window_alarm);
door c(door_sensor,clk,sec,door_state,door_alarm);
always @(posedge clk)
begin
if(sec)
begin
if(motion_sensor)
begin
alarmm=1'b1;
end
else
begin
alarmm=1'b0;
end
end
else
begin
alarmm=1'b0;
end
end
endmodule

FIRE MODULE CODE


module fire(
input fire_sensor,
input clk,
output reg fire_alarm
);
initial begin
fire_alarm=1'b0;
end
always @(posedge clk)
begin
if(fire_sensor)
begin
fire_alarm=1'b1;
end
else
begin
fire_alarm=1'b0;
end
end
endmodule

WINDOW MODULE CODE


module window(
input window_sensor,
input clk,
input sec,

output reg window_state,


output reg window_alarm
);
initial begin
window_state=1'b1;
window_alarm=1'b0;
end
always @(posedge clk)
begin
if(sec)
begin
if(!window_sensor)
begin
window_state=1'b0;
window_alarm=1'b1;
end
else
begin
window_state=1'b1;
window_alarm=1'b0;
end
end
else
begin
if(window_sensor)
begin
window_state=1'b1;
window_alarm=1'b0;
end
else
begin
window_state=1'b0;
window_alarm=1'b0;
end
end
end
endmodule

DOOR MODULE CODE


module door(
input door_sensor,
input clk,
input sec,
output reg door_state,
output reg door_alarm
);
initial begin
door_state=1'b1;
door_alarm=1'b0;
end
always @(posedge clk)
begin
if(sec)
begin
if(!door_sensor)
begin
door_state=1'b0;
door_alarm=1'b1;
end
else
begin
door_state=1'b1;
door_alarm=1'b0;
end
end
else
begin
if(door_sensor)
begin
door_state=1'b1;
door_alarm=1'b0;
end
else
begin
door_state=1'b0;
door_alarm=1'b0;
end
end
end
endmodule

You might also like