You are on page 1of 45

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/271647280

Motion Sensor and Temperature Control System using ATmega8 Microcontroller

Technical Report · December 2013


DOI: 10.13140/2.1.5059.1043

CITATIONS READS
0 290

3 authors, including:

Utsho A Arefín
Northern University Bangladesh
53 PUBLICATIONS   44 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Electron Transmission in Double Quantum-Well Tunnel FET View project

All content following this page was uploaded by Utsho A Arefín on 02 February 2015.

The user has requested enhancement of the downloaded file.


MOTION SENSOR AND TEMPERATURE CONTROL
SYSTEM USING ATMEGA8 MICROCONTROLLER

Submitted By

Md. Noor Nawaz Ahsan


ID: EECE 080100046
Shaheen Ahmed
ID: EECE 080100049

Supervised By

Ashraful Arefin
Sr. Lecturer
Department of Electrical &Electronic Engineering
Northern University Bangladesh

December 2013
Department of Electronics and Communication Engineering
NORTHERN UNIVERSITY BANGLADESH
APPROVAL
This is to certify that the Project and Thesis on “Motion Sensor and Temperature Control
System using ATmega8 Microcontroller” by Md. Noor Nawaz Ahsan, ID: EECE 080100046
and Shaheen Ahmed, ID: EECE 080100049 has been carried out under our supervision. The
project has been carried out in partial fulfillment of the requirements for the degree of Bachelor
of Science (B.Sc.) in Electronics and Communication Engineering in the year of 2013 and has
been approved as to its style and contents.

Board of Examination

_____________________________________________
Ashraful Arefin (Supervisor)
Sr. Lecturer
Department of Electrical & Electronic Engineering
Northern University Bangladesh

______________________________________________
Lecturer
Department of Electrical & Electronic Engineering
Northern University Bangladesh

______________________________________________
Lecturer
Department of Electrical & Electronic Engineering
Northern University Bangladesh

_______________________________________________
Professor Dr. Md. Shah Alam
Head
Department of Electronics & Communication Engineering
Northern University Bangladesh

i
DECLARATION

We, hereby, declare that the work presented in this Project and Thesis is the outcome of the
research work performed by us under the supervision of Ashraful Arefin, Sr. Lecturer,
Department of Electrical & Electronic Engineering, Northern University Bangladesh.

We also declare that no part of this project and thereof has been or is being submitted elsewhere
for the award of any degree or Diploma.

Signature

_____________________
Md. Noor Nawaz Ahsan
ID: EECE 080100046

____________________
Shaheen Ahmed
ID:EECE080100049

Countersigned

________________________________________
Ashraful Arefin
Sr. Lecturer
Department of Electrical & Electronic Engineering
Northern University Bangladesh

ii
ABSTRACT

We know that, the automated Motion Sensor system and the Temperature control systems are
getting more valuable in today’s life style. This is more easy and comfortable for user to ensure
security of private or corporate area. It is also very cost efficient.

Now a days security reason is a burning question. There are various types of home security
systems are available. But we wanted to design a automated security system with digital
interface.

So we have taken Microcontroller base fully automated and digital equipment. It can be used
attached with thousands of security systems. The application is more than its building cost and
the operating cost and minimum operational error rate is very interesting.

iii
ACKNOWLEDGEMENT

Thanks to Almighty, the Creator and Sustainer who has given us strength and opportunity to
complete the Project, “Motion Sensor and Temperature Control System using ATmega8
Microcontroller”.

We would like to express our gratitude and appreciation our supervisor, Ashraful Arefin, for his
guidance in the execution of the project, for keeping us on our toes, and for his kind
understanding. Our acknowledgement also goes out to the project presentation assessor.

We would like to thanks our Honorable Head, Faculty of Science and Engineering also.

Finally, I express our greetings to all our friend and teacher who have influenced and encouraged
of us to develop this project.

The Authors
December, 2013

iv
Table of Contents

Approval ...………………………………………………………………………………………...i
Declaration …..……………………………………………………………………………………ii
Abstract …………………………………………………………………………………………..iii

Acknowledgement (iv)

Table of Contents (v)

List of Figure (vii)

Chapter 1: Introduction
1.1 Problem statement
…………………………………………………………………………………………...01
1.2 Objectives of the Project
…………………………………………………………………………………………...01
1.3 Methodology …………………………………………………………………………….02
1.4 Results …………………………………………………………………………………...02
1.4.1 Outline of the Report
……………………………………………………………………………..02

Chapter 2: Circuit Components


2.1 Diode ……………………………………………………………………………………03
2.2 Resistance
………………………………………………………………………………………………… ..05
2.3 Transistor
……………………………………………………………………………………………………08
2.4 Capacitor
…………………………………………………………………………………………………..12
2.5 Relay Switch
…………………………………………………………………………………………….……..13
2.6 LCD Display
.…………………………………………………………………………………………………..14

v
2.7 LM7805
………………………………………………………………………………………....................15
2.8 DS18S20
………………………………………………………………………………………....................15
2.9 Motion Sensor
……………………………………………………………………………....................................15
2.10 ATmega8 Microcontroller
……………………………………………………………….…………………………………...16

Chapter 3: Design and Diagrams


3.1.1 Block Diagram of the Circuit ………………….……………………………..…18
3.1.2 Circuit Diagram of the Circuit ………………………………………………..…19
3.1.3 PCB Layout ……………………………………………………………………...22
3.1.4 Program C. Cod………………………………………………………………….22
3.1.5 Outlook of the Project …………………………………………………………...27

Chapter 4: Working Principles and Applications


4.1Introduction…………………………………………………………………………28
4.2PriceComparison………………………………………………………………….…28
4.3Application…………………………………………………………………………..28

Chapter 5: Futures works in the field 29


Chapter 6: Conclusion
6.1 Achievement …………………………………………………………………………...29
6.2 Limitations………………………………………………………………………………30

References
(i)-(ii)

vi
List of Figures

Figure 2.1.1 : A simple Diode


Figure 2.1.2 : Diode Materials
Figure 2.1.3 : Diode Characteristics Graph
Figure 2.1.4 : Bridge Rectifier
Figure 2.2.1 : A simple Resistor
Figure 2.2.2 : Color Code of Resistance
Figure 2.2.3 : Parallel Connection of Resistors
Figure 2.2.4 : 4.7k Resistor
Figure 2.3.1 : Transistors
Figure 2.3.2 : The relationship between base, emitter and collector
Figure 2.3.3 : n-p-n Transistor Circuit Diagram
Figure 2.3.4 : Transistor internal current flow
Figure 2.3.5 : Transistor BC 5479 and BC547
Figure 2.4.1 : Various types of Relay
Figure 2.4.2 : Relays in Circuits
Figure 2.4.3 : Relay Connections
Figure 2.4.4 : Internal Configuration of a Relay
Figure 2.5.1 : LCD Display
Figure 2.6.1 : A LM7805
Figure 2.8.1 : Motion Sensor
Figure 2.9.1 : ATmega8 Pin Configuration
Figure 2.9.2 : ATmega8 Pin Description
Figure 3.1.1 : Block Diagram of the Project.
Figure 3.2.1 : Power supply, Buzzer and Motion sensor circuit.
Figure 3.2.2 : Relay and Inputs circuit diagram.
Figure 3.2.3 : Circuit Diagram of main control part.
Figure 3.3.1 : PCB Layout.
Figure 3.5.1 : Outlook of the Project.

vii
Chapter 1

Introduction

In Bangladesh the system loss of any system is more than the system error. So we have to think
and make better idea to change the situation. To make our loving country well developed we
have to make it digitalized. The Automated switching systems are more popular to any system
now a day. Our project is about to make the temperature controlling and security system
automated with a programmed microcontroller.

1.1 Problem Statement

Bangladesh is a developing country. But now a day security reasons are a burning question. Also
the manual Air Cooling systems or heaters are crossing limits to use the power unbounded or
unlimited. The security of our home or corporate area is becoming more risky on bad political
situation, when we are not present there. An automated security system and power management
for air cooler or heater can make the demand fulfill easily. So we make an idea how to prevent
this critical problem with smart technologies. In this project, we will see how we can do this.

1.2 Objectives of the project

Page 1
There are many objectives of this project. They are as:

1. To make the motion sensor and alarm system automated.


2. To write the program to make usable of the microcontroller on our project.
3. To ensure the automatic serviced device and develop the temperature controlled air
cooler and heater power management based on digital technology for world-Wide use.

1.3 Methodology
Using two different types of sensors and the most popular ATmega8 microcontroller we can
build a structured device that can work automatically. This is the easiest circuit we think for this
purpose. The cost is also very low. Here we have used the methodologies are:
01. Studying about the ATmega8 Microcontroller.
02. Studying literature on the bridge rectifier and the various sensor circuits.
03. Analyzing and design for proposed system using the special BC5479 Transistor.
04. Implementation of the proposed system.
05. Carrying out experiment and evaluate the system circuit.

1.4 Results
The performance of the system has been tested so as to achieve its desire goal. It can successfully
operate automatically with the increasing or decreasing temperature and motion detection. And
this is the great thing that the device can work automatically without any human touch.

1.5 Outline of the Reports


In chapter 2, we described about the circuit components are used to make the device.
01. The diode characteristics and uses.
02. The resistance and its fundamentals in this device.
03. The Transistor, Motion sensor and the temperature sensor.

Page 2
04. The capacitor working methods and details.
05. In Chapter 3, the circuit diagram and the block diagram is discussed.
06. In Chapter 4, Comparative results for comparing price, working principle and application
of the project is discussed.
07. The last Chapter 5, of the report includes conclusion as well as suggested future works in
the field.

Chapter 2 : Circuit Components

2.1 Diode
In electronics, a diode is a two-terminal electronic component with an asymmetric transfer
characteristic, with low (ideally zero) resistance to current flow in one direction, and high
(ideally infinite) resistance in the other. A semiconductor diode, the most common type today,
is a crystalline piece of semiconductor material with a p-n junction connected to two electrical
terminals. A vacuum tube diode is a vacuum tube with two electrodes, a plate (anode) and
heated cathode.

Page 3
Figure 2.1.1 : A simple Diode

The most common function of a diode is to allow an electric current to pass in one
direction (called the diode's forward direction), while blocking current in the opposite direction
(the reverse direction). Thus, the diode can be viewed as an electronic version of a check valve.
This unidirectional behavior is called rectification, and is used to convert alternating current to
direct current, including extraction of modulation from radio signals in radio receivers—these
diodes are forms of rectifiers.

Figure 2.1.2 : Diode Materials

p–n junction diode :

When two materials i.e. n-type and p-type are attached together, a momentary flow of electrons
occur from n to p side resulting in a third region where no charge carriers are present. It is called
Depletion region due to the absence of charge carriers (electrons and holes in this case).

Page 4
Figure 2.1.3 : Diode Characteristics Graph

Figure 2.1.4 : Bridge Rectifier

A bridge rectifier makes use of four diodes in a bridge arrangement to achieve full-wave
rectification. This is a widely used configuration, both with individual diodes wired as shown
and with single component bridges where the diode bridge is wired internally.

2.2 Resist

Page 5
A resistor is a passive two-terminal electrical component that implements electrical resistance as
a circuit element.

The current through a resistor is in direct proportion to the voltage across the resistor's terminals.
This relationship is represented by Ohm's law:

Figure 2.2.1 : A simple Resistor

Where I am the current through the conductor in units of amperes, V is the potential difference
measured across the conductor in units of volts, and R is the resistance of the conductor in units
of ohms.

Figure 2.2.2 : Color Code of Resistance

Page 6
The resistance (R) of an object is defined as the ratio of voltage across it (V) to current through it
(I), while the conductance (G) is the inverse:

Thus the equivalent resistance (Req) of the network can be computed:

Figure 2.2.3 : Parallel Connection of Resistors

The parallel equivalent resistance can be represented in equations by two vertical lines "||" (as in
geometry) as a simplified notation. Occasionally two slashes "//" are used instead of "||", in case
the keyboard or font lacks the

Page 7
A 4.7 K Resistor Details :

Resistors are color coded. To read the color code of a common 4 band 1K ohm resistor with a
5% tolerance, start at the opposite side of the GOLD tolerance band and read from left to right.
Typical 4.7k ohm, 1/4 watt resistor that can be

used with various circuits. The color band on the resistor is Yellow, Purple, Red and Gold.

Key Features:

 4.7k ohm resistance


 1/4 watt
 Flexible leads

Figure 2.2.4 : 4.7k Resistor


A 220ohm Resistor Details :

 1/4W
 Tolerance 5%
 1206 SMD

Page 8
2.3 Transistor

A transistor is a semiconductor device used to amplify and switch electronic signals and
electrical power. It is composed of semiconductor material with at least three terminals for
connection to an external circuit. A voltage or current applied to one pair of the transistor's
terminals changes the current flowing through another pair of terminals. Because the controlled
(output) power can be higher than the controlling (input) power, a transistor can amplify a signal.
Today, some transistors are packaged individually, but many more are found embedded in
integrated circuits.

Figure 2.3.1 : Transistors

Page 9
The transistor is the fundamental building block of modern electronic devices, and is ubiquitous
in modern electronic systems. Following its development in the early 1950s the transistor
revolutionized the field of electronics, and paved the way for smaller and cheaper radios,
calculators, and computers, among other things.

A bipolar junction transistor (BJT or bipolar transistor) is a type of transistor that relies on the
contact of two types of semiconductor for its operation. BJTs can be used as amplifiers,
switches, or in oscillators. BJTs can be found either as individual discrete components, or in
large numbers as parts of integrated circuits.

Forward-active (or simply, active): The base–emitter junction is forward biased and the
base–collector junction is reverse biased.

Reverse-active (or inverse-active or inverted): By reversing the biasing conditions of


the forward-active region, a bipolar transistor goes into reverse-active mode. In this mode, the
emitter and collector regions switch roles.

Saturation: With both junctions forward-biased, a BJT is in saturation mode and facilitates
high current conduction from the emitter to the collector (or the other direction in the case of
NPN, with negatively charged carriers flowing from emitter to collector). This mode corresponds
to a logical "on", or a closed switch.

Cutoff: In cutoff, biasing conditions opposite of saturation (both junctions reverse biased) are
present. There is very little current, which corresponds to a logical "off", or an open switch.

Page 10
Figure 2.3.2 : The relationship between , and .

In the diagram, the arrows representing current point in the direction of conventional current –
the flow of electrons is in the opposite direction of the arrows because electrons carry negative
electric charge. Active-mode PNP and NPN transistors in circuits:

Figure 2.3.3 : n-p-n Transistor Circuit Diagram

As shown in the diagram, the emitter current, , is the total transistor current, which is the sum
of the other terminal currents (i.e., IE = IB + IC).

Page 11
Figure 2.3.4 : Transistor internal current flow

Transistor BC547(N-P-N) Details :

BC547 is an NPN bi-polar junction transistor. A transistor, stands for transfer of resistance, is
commonly used to amplify current. A small current at its base controls a larger current at
collector & emitter terminals. BC547 is mainly used for amplification and switching purposes. It
has a maximum current gain of 800.

Figure 2.3.5 : Transistor BC 5479 and BC 547

Transistor BC 5479(N-P-N) Details :

 NPN Epitaxial Silicon Transistor.


 Absolute Maximum Ratings Ta=25°C unless otherwise noted.
 Electrical Characteristics Ta=25°C unless otherwise noted.
 Amplifier Transistors.
 Features BENT LEAD.
 TAPE & REEL.

Page 12
2.4 Capacitor
On our circuit diagram we can see that 2 pies 680uf and 1500uf capacitor is used. The data sheet
of the capacitor is given below:

Page 13
2.5 Relay Switch
Relay is one of the most important electromechanical devices highly used in industrial
applications specifically in automation. A relay is used for electronic to electrical interfacing i.e.

Page 14
it is used to switch on or off electrical circuits operating at high AC voltage using a low DC
control voltage.

Figure 2.4.1 : Various types of Relay Switches

A relay generally has two parts, a coil which operates at the rated DC voltage and a mechanically
movable switch. The electronic and electrical circuits are electrically isolated but magnetically
connected to each other; hence any fault on either side does not affects the other side.

Figure 2.4.2 : Relays in Circuits

Relay switch shown in the image above consists of five terminals. Two terminals are used to
give the input DC voltage also known as the operating voltage of the relay. Relays are available
in different operating voltages like 6V, 12V, 24V etc. The rest of the three terminals are used to
connect the high voltage AC circuit.

Figure 2.4.3 : Relay Connections

Page 15
The terminals are called Common, Normally Open (NO) and Normally Closed (NC). Relays are
available in various types & categories and in order to identify the correct configuration of the
output terminals.

Figure 2.4.4 : Internal Configuration of a Relay

2.6 LCD Display


A liquid-crystal display (LCD) is a flat panel display, electronic visual display, or video
display that uses the light modulating properties of liquid crystals. Liquid crystals do not emit
light directly.

LCDs are used in a wide range of


applications including computer monitors,
televisions, instrument panels, aircraft
cockpit displays, and signage. They are
common in consumer devices such as video
players, gaming devices, clocks, watches,
calculators, and telephones, and have
replaced cathode ray tube (CRT) displays in
most applications.

Page 16
Figure 2.5.1 : Digital LCD Display

2.7 LM7805
It’s a 3-Terminal 1 A Positive Voltage Regulator

Output Current up to 1 A. Output Voltages: 5, 6,

8, 9, 10, 12, 15, 18, 24 V. Thermal Overload

Protection, Short-Circuit Protection, Output

Transistor Safe Operating Area Protection.

Figure
Figure2.6.1
2.8.1: :ALM78058
LM7805
2.8 DS18S20
The 64-bit ROM stores the device’s unique serial code. The scratchpad memory contains the 2-
byte temperature register that stores the digital output from the temperature sensor. In addition,
the scratchpad provides access to the 1-byte upper and lower alarm trigger registers (TH and
TL). The TH and TL registers are nonvolatile (EEPROM), so they will retain data when the
device is powered down.

2.9 Motion Sensor

A motion sensor is a device that detects moving objects,


particularly people. A motion detector is often integrated
as a component of a system that automatically performs a
task or alerts a user of motion in an area. Motion detectors
form a vital component of security, automated lighting
control, and other useful systems.
Page 17
An electronic motion detector contains a motion sensor
that transforms the detection of motion into an electric
Figure 2.8.2 : Motion Sensor

2.10 ATmega8 Microcontroller


Here is the ATmega8 pin configuration.

Figure 2.9.1 : ATmega8 Pin Configuration

Here is the Pin Description :

VCC : Digital supply voltage.

Page 18
GND: Ground.

Port B is an 8-bit bi-directional I/O port with


internal pull-up resistors (selected for each bit).
PortB
The Port B output buffers have symmetrical drive
characteristics with both high sink and source
capability.

Port C is an 7-bit bi-directional I/O port with internal


pull-up resistors (selected for each bit). The Port C
Port C (PC5..PC0)
output buffers have symmetrical drive characteristics
with both high sink and source capability.

PC6/RESET If the RSTDISBL Fuse is programmed,


PC6 is used as an I/O pin. Note that the electrical
characteristics of PC6 differ from those of the other
PC6/RESET
pins of Port C.
If the RSTDISBL Fuse is un programmed, PC6 is used
as a Reset input.
Port D is an 8-bit bi-directional I/O port with internal
pull-up resistors (selected for each bit). The Port D
Port D (PD7..PD0)
output buffers have symmetrical drive characteristics
with both high sink and source capability.
Reset input. A low level on this pin for longer than the
minimum pulse length will generate a reset, even if the
RESET clock is not running. The minimum pulse length is
given in Table 15 on page 38. Shorter pulses are not
guaranteed to generate a reset.

Page 19
AVCC is the supply voltage pin for the A/D Converter,
AVCC Port C (3..0), and ADC (7..6). It should be externally
connected to VCC, even if the ADC is not used
AREF is the analog reference pin for the A/D
AREF
Converter.
In the TQFP and QFN/MLF package, ADC7..6 serve as
ADC7..6
analog inputs to the A/D converter.

Chapter 3 :: ATmega8
Figure 2.9.2 DesignPinand Diagrams
Description

Page 20
3.1 Block Diagram of the Circuit
The block diagram of the circuit is given below:

Page 21
Figure 3.1.1 : Block Diagram of the Circuit

3.2 Circuit Diagram of the Project


Part 01 : Power Supply

Part 02 : Buzzer & Motion Sensor

Page 22
Figure 3.2.1 : Power Supply, Buzzer and Motion Sensor Circuit

Part 03 : Relay & Inputs

Page 23
Figure 3.2.2 : Relay and Inputs Circuit Diagram

Part 04 : Main Control Part

Page 24
Figure 3.2.3 : Circuit Diagram of Main Control Part

3.3 PCB Layout


Here is the PCB Layout of the Project:

Page 25
Figure 3.3.1 : PCB Layout

Programming C. Code

The main part of the project is the programming. We have programmed our Microcontroller with
the most popular programming language ‘C’.

The code is shown in Appendix A.

Page 26
3.5 Outlook of the Project

Here is the outlook of the Project:

Figure 3.5.1 : Outlook of the Project


Page 27
Chapter 4 : Working Principles and Applications

4.1 Introduction
In this chapter, we have compared the price, Application and some other relevant
aspect of automated sensor switching systems on aviation light.

4.2 Price Comparison

We have compared our project with human controlled security systems. But it is
cheaper than that. Because any human attendance is not required on the spot to
operate it. It is totally automated. It is to say that it will totally kill the extra costs
of valuable time and salary of an associate. Only the ac/dc power is needed. No
other cost is needed.
The circuit components are also very cost efficient in the market. The capacitors,
transistors, diodes, rectifiers, amplifiers and resistors are very cheap and no IC is
used to make the device.

Page 28
4.3 Features and Applications

This system can be used for multi task, such as:


a. Home Use.
b. On the big industries, where huge products are available.
c. On the Private area.
d. To reduce the employee number.
e. Only one man is enough to operate and maintenance of the device.
f. Multiple Purposes.
g. Fully Digital.
h. Fully Automated.

Chapter 5 : Future works in the field


In future this system will be able to focus on the following areas:

 We will try to develop to decrease the response time of this device for complex and
sophisticated uses.
 We will work on the operation ranges also.
 The interval between the readings of the thermometer of 1 degree which can be
reduced to smaller the function.
 We can use more expensive motion sensor.
 We can use a rechargeable battery in this system for continuous power supply.
 Bridge connected sensors can be used to operate the device like a network.
 We can improve the device to minimize error.

Chapter 6 : Conclusion
Page 29
Making an automated system or device is really very challenging task and although it is very
interesting and creative. By using this proposed method we have been able to make a strong
automated security system and also we can use the temperature sensor for home use. We can
operate our AC and cooling fans automatically with this device. In future I will try to introduce
several automated microcontroller based projects.

6.1 Achievement
The major achievement of our project is to control the devices and systems power supply
automatically with cellular network from any distance. When we call the fixed number installed
on the circuit, the circuit will make short on its output. This is called the On-Condition. When we
call again on the fixed number the circuit will remain open. It is called Off-Condition.

The main thing is that the call will not received and when the call finishes the On-Condition
remains on always until Off-Condition remains.

6.2 Limitations

There are two limitations of this device. They are:

 The response time of the device is around 3 seconds which very high for complex
and sophisticated uses.
 The operation ranges of the device not enough.
 The interval between readings are high.
 The range of the motion sensor is at best five meter.
 The device has no internal power supply system

Page 30
 There are small operating errors.

Page 31
Appendix A
#include <mega8.h>
#include <stdio.h>
#include <delay.h>
lcd_user_interface(int lcd_temp);
low_temp_limit_set();
high_temp_limit_set();
running();
// 1 Wire Bus functions
#asm
.equ __w1_port=0x18 ;PORTB
.equ __w1_bit=2
#endasm
#include <1wire.h>
// DS18B20 Temperature Sensor functions
#include <ds18b20.h>
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x12 ;PORTD
#endasm
#include <lcd.h>
char lcd_buffer[33];
#define MAX_DEVICES 8
#define ON 1
#define OFF 0
#define motion_sensor PINB.1
#define RELAY_1 PORTC.4
#define RELAY_2 PORTC.5
#define START PINC.0
#define STOP PINC.1
#define UP PINC.2
#define DOWN PINC.3
#define PRESS 0
#define RELEASE 1
#define BUZZER PORTB.0
#define MAX_DEVICES 8
#define ON 1
#define OFF 0
#define motion_sensor PINB.1
#define RELAY_1 PORTC.4
#define RELAY_2 PORTC.5
#define START PINC.0
#define STOP PINC.1
#define UP PINC.2
#define DOWN PINC.3

Page 32
#define PRESS 0
#define RELEASE 1
#define BUZZER PORTB.0
unsigned char rom_code[MAX_DEVICES][9];
// Declare your global variables here
unsigned char devices;
int temp;
eeprom int high_limit[2]={0,0};
eeprom int low_limit[2]={0,0};
int h_temp, l_temp;

void main(void)

{
PORTB=0x00;
DDRB=0x01;
PORTC=0x0F;
DDRC=0x30;
devices=w1_search(0xf0,rom_code);
if(DOWN==PRESS)
{
high_limit[1]=40;
low_limit[1]=30;
}
if(motion_sensor==ON)
{
BUZZER=OFF;
}
else if(motion_sensor==OFF)
{
BUZZER=ON;
}
if(STOP==PRESS)
{
high_temp_limit_set();
}
if(START==PRESS)
{
running();
} temp=ds18b20_temperature(&rom_code[0][0]);
lcd_user_interface(temp);
};
}
running()
{
lcd_clear();
lcd_gotoxy(0,0);

Page 33
lcd_putsf("SYSTEM RUNNING");
delay_ms(2000);
lcd_clear();
while(START==PRESS)delay_ms(50);

while(STOP==RELEASE)
{
if(temp<=l_temp)
{
RELAY_2=ON;
RELAY_1=OFF;
//BUZZER=ON;
}
if(temp>=h_temp)
{
RELAY_2=OFF;

RELAY_1=ON;
//BUZZER=OFF;
}
temp=ds18b20_temperature(&rom_code[0][0]);
sprintf(lcd_buffer,"Temperature=%i\xdfC",temp); //\xdf= Degree sign
lcd_gotoxy(0,1);
lcd_puts(lcd_buffer);

delay_ms(10);
lcd_gotoxy(0,0);
sprintf(lcd_buffer,"H-%2d** NUB**L-%2d",h_temp,l_temp);
lcd_puts(lcd_buffer);
}
while(STOP==PRESS)
{
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf(" SYSTEM STOP");
delay_ms(2000);
lcd_clear();
RELAY_2=OFF;
//BUZZER=OFF;
}
}
lcd_user_interface(int lcd_temp)
{
lcd_clear();
sprintf(lcd_buffer,"Temperature=%i\xdfC",lcd_temp); //\xdf= Degree
sign
lcd_gotoxy(0,1);

Page 34
lcd_puts(lcd_buffer);
delay_ms(10);
lcd_gotoxy(0,0);
sprintf(lcd_buffer,"H-%2d** NUB**L-%2d",h_temp,l_temp);
lcd_puts(lcd_buffer);
}
high_temp_limit_set()
{
lcd_clear();
sprintf(lcd_buffer,"High Temp=%2d\xdfC",h_temp); //\xdf= Degree sign
lcd_gotoxy(0,0);
lcd_puts(lcd_buffer);
delay_ms(40);
while(STOP==PRESS)delay_ms(50); while(STOP==RELEASE)
{
if(UP==PRESS)
{
h_temp++;
if(h_temp>=50)
{
h_temp=50;
}
sprintf(lcd_buffer,"High Temp=%2d\xdfC",h_temp); //\xdf= Degree sign

lcd_gotoxy(0,0);
lcd_puts(lcd_buffer);
delay_ms(40);
while(UP==PRESS)delay_ms(40);;
}
if(DOWN==PRESS)
{
h_temp--;
if(h_temp<=10)
{

h_temp=10;
}
sprintf(lcd_buffer,"High Temp=%2d\xdfC",h_temp); //\xdf= Degree sign
lcd_gotoxy(0,0);
lcd_puts(lcd_buffer);
delay_ms(40);
while(DOWN==PRESS)delay_ms(40);;
}
}
while(STOP==PRESS)
{
low_temp_limit_set();
}

Page 35
}
low_temp_limit_set()
{
lcd_clear();
sprintf(lcd_buffer,"Low Temp=%2d\xdfC",l_temp); //\xdf= Degree sign
lcd_gotoxy(0,0);
lcd_puts(lcd_buffer);
delay_ms(40);
while(STOP==PRESS)delay_ms(50);
while(STOP==RELEASE)
{
if(UP==PRESS)
{
l_temp++;
if(l_temp>=50)
{
l_temp=50;
}
sprintf(lcd_buffer,"Low Temp=%2d\xdfC",l_temp); //\xdf= Degree sign
lcd_gotoxy(0,0);
lcd_puts(lcd_buffer);
delay_ms(40);
while(UP==PRESS)delay_ms(40);;
if(DOWN==PRESS)
{
l_temp--;
if(l_temp<=10)
{
l_temp=10;
}
sprintf(lcd_buffer,"Low Temp=%2d\xdfC",l_temp); //\xdf= Degree sign
lcd_gotoxy(0,0);
lcd_puts(lcd_buffer);
delay_ms(40);
while(DOWN==PRESS)delay_ms(40);;
}
}
}
while(STOP==PRESS)
{
delay_ms(200);
}
lcd_clear();
lcd_gotoxy(0,0);
lcd_putsf("***** NUB ******");
high_limit[1]=h_temp;
low_limit[1]=l_temp;
}

Page 36

View publication stats

You might also like