Motion Sensor and Temperature Control System Using Atmega8 Microcontroller
Motion Sensor and Temperature Control System Using Atmega8 Microcontroller
net/publication/271647280
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:
All content following this page was uploaded by Utsho A Arefín on 02 February 2015.
Submitted By
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)
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
v
2.7 LM7805
………………………………………………………………………………………....................15
2.8 DS18S20
………………………………………………………………………………………....................15
2.9 Motion Sensor
……………………………………………………………………………....................................15
2.10 ATmega8 Microcontroller
……………………………………………………………….…………………………………...16
References
(i)-(ii)
vi
List of Figures
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.
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.
Page 1
There are many objectives of this project. They are as:
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.
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.
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.
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
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:
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.
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:
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:
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.
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.
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:
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
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.
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.
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.
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.
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.
Page 16
Figure 2.5.1 : Digital LCD Display
2.7 LM7805
It’s a 3-Terminal 1 A Positive Voltage Regulator
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.
Page 18
GND: Ground.
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
Page 22
Figure 3.2.1 : Power Supply, Buzzer and Motion Sensor Circuit
Page 23
Figure 3.2.2 : Relay and Inputs Circuit Diagram
Page 24
Figure 3.2.3 : Circuit Diagram of Main Control Part
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’.
Page 26
3.5 Outlook of the Project
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.
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
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
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