Professional Documents
Culture Documents
Competer Visitor
Competer Visitor
Multan
Supervisor:
Hammad Abbas
Department of Physics
Govt Emerson College, Multan
2016-2020
Department of Physics,
Govt Emerson College, Multan
Session 2016-2020
DECLARATION
This is to certify that the project “Microcontroller Based Fan and Light Control By Presence
of Human Body” is our original work. No part of this work is being submitted anywhere else
partially or fully for the award of any degree or diploma. Any material reproduced in this
project, has been properly acknowledged.
Certificate of Approval
The project titled - “Microcontroller Based Fan and Light Control By Presence of Human
Body and ” prepared by the following students has been submitted to the following respective
members of Department of Physics, Govt Emerson College, Multan in partial fulfillment of
the requirements for the degree of BS Physics.
Project Supervisor
Hammad Abbas
Department of Physics ………………………………
Govt Emerson College, Multan
Head of Department
Nadeem Iqbal
Department of Physics ………………………………..
Govt Emerson College, Multan
External Examiner
………………………………………..
Department of Physics ………………………………..
Bahauddin Zakariya University, Multan
s
Declaration…………………………………………………………………………………….
03
Approval
………………………………………………………………………………………..04
Acknowledgement………………………………………………………………………………
07
Abstract …………………………………………………………………………………………
08
Chapter-1
1.0
Introduction………………………………………………………………………………….10
1.1 Objective of the
Project……………………………………………………………………...10
Chapter-2
2.1 Literature Review……………………………………………………………………………
12
2.2 Project Report Organization…………………………………………………………………
13
Chapter-3
3.1 List of
Components………………………………………………………………………….16
3.2 Power Supply
……………………………………………………………………………….17
3.3 Arduino Uno
………………………………………………………………………………...23
3.4 16*2 LCD Display
Module………………………………………………………………….29
3.5 IR Sensor ……………………………………………………………………………………
34
3.6 Relay
Module………………………………………………………………………………..38
3.7 DC Fan………………………………………………………………………………………
41
3.8 Incandecent
Bulb…………………………………………………………………………….42
Chapter-4
4.1
Introduction………………………………………………………………………………….45
4.2 Hardware Design ……………………………………………………………………………
45
4.3 LCD Display Connection with
Arduino…………………………………………………….46
4.4 Connection of Arduino with
Arduino……………………………………………………….47
4.5 Overall Circuit
Diagram…………………………………………………………………….49
4.6 Software
Design……………………………………………………………………………..49
4.7 Installing Arduino
…………………………………………………………………………...50
4.8 Verify the Hardware…………………………………………………………………………
47
4.9 Arduino Language
…………………………………………………………………………..50
Chapter-5
5.2)
Limitations…………………………………………………………………………………..
52
5.4)
Conclusion…………………………………………………………………………………..52
5.5)
Bibliography…………………………………………………………………………………54
ACKNOWLEDGEMENT
At first, we utter our deepest gratitude to the almighty Allah, whose boundless mercy made
the completion of the project.
We are very much happy that we have taken efforts. However, it would not be possible on
our part to complete it without the kind support and help of many individuals and
organization. We would like to express our gratitude towards all of them.
We are grateful to our supervisor Hammad Abbas for his continuous guidance and
supervision, and also for providing us the necessary information and equipment needed for
the project. We highly appreciate his time and encouragement that helps us to complete this
project. We would like to express our special thanks to the Department Chairman Nadeem
Iqbal
Our appreciation also goes to our beloved Department of Physics for providing us the
opportunities to prove ourselves.
As a developing country power sources of Pakistan are limited. We know, a major part of our
electricity is being wasted due to our incognizance. After leaving the room the fans, lights etc.
remain on unnecessarily. The main object of this project is to minimize the wastage of
electricity. The other objective of this project is to detect the gas or smoke level in kitchen
room and take necessary action to protect firing. When a person enters into the room, the load
will get power and can be run by their switches. The counter circuit can count the number of
persons staying in the room. If a person enters into the room the counter will be incremented
and if a person leaves the room the counter will be decremented. After the last person leaving
the room the value of the counter will be zero and the load will be disconnected from the
power. The gas sensor always senses the gas or smoke level in the kitchen room. If the level
of gas/smoke is above a predefined threshold, it will give an alarm sound. Moreover, if there
is no person in the room the power main switch will be automatically OFF. But if there is
someone inside the room it will only give the alarm so that the person can take necessary
action. Arduino board has been used in this project as a control circuit. Two laser diodes and
two photodiodes work as person counter and a gas sensor unit have been used. The project
has been completed and tested. It works properly and its performance is satisfactory.
Chapter 1
Introduction
P a g e | 11
CHAPTER ONE
Introduction
1.0 INTRODUCTION
The need for a device that can automatically control the lightening system of a room and
capability of taking count of number of people in a room and sensing of smoke on its own has
been long overdue.
Wastage of electricity is one of the main problems which we are facing now-a-days. In our
home, school, colleges or industry we see that fan and lighting point are kept on even if there
are nobody in the room or area and passage. This happens due to negligence or because we
forgot to turn lights off or we are in a hurry. To avoid all such situations this project called
“Automatic room light and fan controller with visitor counter” is designed. This project has
two modules, first one is known as “Digital Visitor counter” and second module is known as
“Automatic room light controller”. Main concept behind this project is known as “Visitor
counter” which measures the number of persons entering in any room like seminar hall,
conference room, hotel rooms. This function is implemented using laser diode and
photodiode. Here Arduino receives the signals from the sensors, and this signal is operated
under the control of software which is stored in the ROM.
LCD display placed outside the room displays this value of person count. This person count
will be incremented if somebody enters inside the room and at that time lights are turned on.
And in reverse way, person count will be decremented if somebody leaves the room. When
number of persons inside the room is zero, lights inside the room are turned off.
Literature Review
P a g e | 13
Although not same but many related work have been done by many researchers. Some of the
papers have been studied and described below.
Asha Rawat, et al. [2016] has done an “Automated Room Light Controller with Visitor
[1]
Counter” . The main purpose of the project is automation, saving electricity, increasing
appliance life span and yet providing a desired output smartly.
E.Shilpa et al[2017] has done a” Implementation of Automatic Room Light Controller with
Visitor Counter Design using 8051 Microcontroller”[4]. This project compacts with the usage
of the energy in this competitive world of electricity. This project is well-organized enough to
let someone know about the accuracy of the person entered and have taken the exit from the
room.
Winfred Adjardjah et al[2016] has done “Design and Construction of a Bidirectional Digital
Visitor Counter”[7]. This paper presents the design and construction of a digital bidirectional
visitor counter (DBVC). The DBVC is a reliable circuit that takes over the task of counting
number of persons / visitors in the room very accurately and beeps a warning alarm when the
number of visitors exceeds the capacity limit of the auditorium/hall.
Gaurav Waradkaret al [2016] has done “Automated Room Light Controller with Visitor
Counter”[8]. This paper presents the design and construction of a digital bidirectional visitor
counter . This is reliable project that takes over the task of counting number of visitors in the
room.
Sibu Skaria et al [2014]has done a “Automatic Lighting Controller”[10]. Based on the paper
title, “AUTOMATIC LIGHTING CONTROLLER”, controls the amount of lighting in a
room by constantly monitoring the level of luminance in a room. Lights are then controlled
such that required illumination is available in the room. It can be applied effectively in
commercial buildings, homes, colleges etc.
Chapter 1 serves as the introductory chapter and Theory literature review where we try to
relay the concept and acceptable reasons why the project should be implemented for the
intending user of the work.
Chapter 2 deals with the Related of all possible related or closely related work of the design.
The evolutionary trend in automatic room light controller operations and design, specification
will also be looked at. The use and importance of this project design will also be mentioned
here. It will be looking at the best place where this project design can be use and where it
cannot. This chapter will also make room for adding additional information on past works in
the area that will help in the actualization of this project design.
Chapter 3 treats system component description of this project design. It comprises of the
information gathering, the source of the materials used in designing and writing the project
report. The components and devices used in the course of designing this project will be
analyzed to know their basic means of operation and how they will help in putting up this
design, system design approach; the possible way to tackled the project design from scratch,
bottom-up; it will treat how the practical detail was gotten before considering about the
general principle of the system design, choice of design system; it focuses on why the project
design was done using a microcontroller rather than using only digital logic.
In chapter 4, it presents the detail design work and discusses the system, test carried out,
Expected results, and Performance evaluation. The schematic diagram of the design and the
source code (in C language) used in programming the microcontroller were also outlined.
Summary and conclusion of the design will be presented in Chapter 5. It will be looking at the
problems encountered in designing the project and possible solutions to them. From the
problems and solutions of this work, the suggestion for further improvement will be stated.
CHAPTER THREE
Related Theory
Following is the list of components that are necessary to build the assembly the project.
Voltage Regulator
Resistors
IR Sensor
LED
Potentiometer – 10kΩ
Table of Contents
Introduction
A Brief Note on 7805 Voltage Regulator
Pin Diagram of 7805 Voltage Regulator IC
Basic Circuit of 7805
How to Get Constant DC Power Supply from AC?
o Circuit Diagram
o Components Required
o Working
Important Points on 7805 Voltage Regulator IC
Introduction
In this tutorial, we will see about one of the most commonly used regulator IC’s, the 7805
Voltage Regulator IC. A regulated power supply is very much essential for several electronic
devices due to the semiconductor material employed in them have a fixed rate of current as
well as voltage. The device may get damaged if there is any deviation from the fixed rate.
One of the important sources of DC Supply are Batteries. But using batteries in sensitive
electronic circuits is not a good idea as batteries eventually drain out and loose their potential
over time.
Also, the voltage provided by batteries are typically 1.2V, 3.7V, 9V and 12V. This is good for
circuits whose voltage requirements are in that range. But, most of the TTL IC’s work on 5V
logic and hence we need a mechanism to provide a consistent 5V Supply.
Here comes the 7805 Voltage Regulator IC to the rescue. It is an IC in the 78XX family of
linear voltage regulators that produce a regulated 5V as output.
7805 is a three terminal linear voltage regulator IC with a fixed output voltage of 5V which is
useful in a wide range of applications. Currently, the 7805 Voltage Regulator IC is
manufactured by Texas Instruments, ON Semiconductor, STMicroelectronics, Diodes
incorporated, Infineon Technologies, etc.
They are available in several IC Packages like TO-220, SOT-223, TO-263 and TO-3. Out of
these, the TO-220 Package is the most commonly used one (it is the one shown in the above
image).
As mentioned earlier, 7805 is a three terminal device with the three pins being 1. INPUT, 2.
GROUND and 3. OUTPUT. The following image shows the pins on a typical 7805 IC in To-
220 Package.
2 GROUND Pin 2 is the GROUND Pin. It is common to both Input and Output.
3 OUTPUT Pin 3 is the OUTPUT Pin. The output regulated 5V is taken at this
pin of the IC.
As I have previously talked about regulated power supply as a device that works on DC
voltages and it can uphold its output accurately at a fixed voltage all the time even if there is a
significant alteration in the DC input voltage.
As per the datasheets of 7805 IC, the basic circuit required for 7805 to work as a complete
regulator is very simple. In fact, if the input supply is an unregulated DC Voltage, then all you
need are two capacitor (even those are not mandatory depending on the implementation).
The above circuit shows all the components required for a 7805 IC to work properly. The
0.22μF Capacitor near the input is required only if the distance between the regulator IC and
the power supply filter is high. Also, the 0.1μF Capacitor near the output is optional and if
used, it helps in the transient response.
In this circuit, VIN is the input voltage to the 7805 IC and the source can be from either a
battery of an unregulated DC. VOUT is the output of the 7805 IC, which is a Regulated 5V.
Although batteries can be used as input to the 7805 Voltage Regulator IC, we face certain
bumps like frequent discharge of batteries and reduction of battery voltage levels over a
period of time.
The best alternative to using Batteries is to provide an unregulated but rectified DC Voltage
from an AC Source. Since AC Source is easily available as mains supply, we can design a
circuit to convert AC Mains to DC and provide it as input to the 7805 Voltage regulator IC.
Circuit Diagram
The following image shows the circuit diagram of producing a regulated 5V from AC Mains
supply.
Components Required
Working
The AC power supply from mains first gets converted into and unregulated DC and then into
a constant regulated DC with the help of this circuit. The circuit is made up of transformer,
bridge rectifier made up from diodes, linear voltage regulator 7805 and capacitors.
If you observe, the working of the circuit can be divided into two parts. In the first part, the
AC Mains is converted into unregulated DC and in the second part, this unregulated DC is
converted into regulated 5V DC. So, let us start discussing the working with this in mind.
Initially, a 230V to 12V Step down transformer is taken and its primary is connected to mains
supply. The secondary of the transformer is connected to Bridge rectifier (either a dedicated
IC or a combination of 4 1N4007 Diodes can be used).
A 1A fuse is placed between the transformer and the bridge rectifier. This will limit the
current drawn by the circuit to 1A. The rectified DC from the bridge rectifier is smoothened
out with the help of 1000μF Capacitor.
So, the output across the 1000μF Capacitor is unregulated 12V DC. This is given as an input
to the 7805 Voltage Regulator IC. 7805 IC then converts this to a regulated 5V DC and the
output can be obtained at its output terminals.
The first important point to note is that the input voltage should always be greater than
the output voltage (atleast by 2.5V).
The input current and output current are almost identical. This means that when a 7.5V
1A supply is given at input, the output will be 5V 1A.
The remaining power is dissipated as heat and hence a heat sink like the one shown
below must be used with 7805 IC.
Arduino UNO
Developer Arduino
Manufacturer Many
CPU Microchip AVR (8-bit)
Memory SRAM
Storage Flash, EEPROM
various expansion boards (shields) and other circuits. The board has 14 Digital pins, 6 Analog
pins, and programmable with the Arduino IDE (Integrated Development Environment) via a
type B USB cable.[4] It can be powered by a USB cable or by an external 9 volt battery,
though it accepts voltages between 7 and 20 volts. It is also similar to the Arduino Nano and
Leonardo. The hardware reference design is distributed under a Creative
Commons Attribution Share-Alike 2.5 license and is available on the Arduino website.
Layout and production files for some versions of the hardware are also available. "Uno"
means one in Italian and was chosen to mark the release of Arduino Software (IDE) 1.0.The
Uno board and version 1.0 of Arduino Software (IDE) were the reference versions of
Arduino, now evolved to newer releases. The Uno board is the first in a series of USB
Arduino boards, and the reference model for the Arduino platform. The ATmega328 on the
Arduino Uno comes preprogrammed with a bootloader that allows uploading new code to it
without the use of an external hardware programmer. It communicates using the original
STK500 protocol. The Uno also differs from all preceding boards in that it does not use the
FTDI USB-to-serial driver chip. Instead, it uses the Atmega16U2 (Atmega8U2 up to version
R2) programmed as a USB-to-serial converter. ‘
Contents
1Background
2Technical specifications
3Pins
o 3.1General Pin functions
o 3.2Special Pin Functions
4Communication
o 4.1Automatic (Software) Reset
5See also
6References
7External links
Background
The Arduino project started at the Interaction Design Institute Ivrea (IDII) in Ivrea, Italy. At
that time, the students used a BASIC Stampmicrocontroller at a cost of $100, a considerable
expense for many students. In 2003 Hernando Barragán created the development
platform Wiring as a Master's thesis project at IDII, under the supervision of Massimo Banzi
and Casey Reas, who are known for work on the Processing language. The project goal was to
create simple, low-cost tools for creating digital projects by non-engineers. The Wiring
platform consisted of a printed circuit board (PCB) with an ATmega168 microcontroller, an
IDE based on Processing and library functions to easily program the microcontroller. [8] In
2003, Massimo Banzi, with David Mellis, another IDII student, and David Cuartielles, added
support for the cheaper ATmega8 microcontroller to Wiring. But instead of continuing the
work on Wiring, they forked the project and renamed it Arduino. Early arduino boards used
the FTDI USB-to-serial driver chip and an ATmega168.The Uno differed from all preceding
boards by featuring the ATmega328P microcontroller and an ATmega16U2 (Atmega8U2 up
to version R2) programmed as a USB-to-serial converter.
Technical specifications
Microcontroller: Microchip ATmega328P
Operating Voltage: 5 Volts
Input Voltage: 7 to 20 Volts
Digital I/O Pins: 14 (of which 6 provide PWM output)
Analog Input Pins: 6
DC Current per I/O Pin: 20 mA
Pins
Arduino UNO
LED: There is a built-in LED driven by digital pin 13. When the pin is HIGH value,
the LED is on, when the pin is LOW, it's off.
VIN: The input voltage to the Arduino/Genuino board when it's using an external
power source (as opposed to 5 volts from the USB connection or other regulated power
source). You can supply voltage through this pin, or, if supplying voltage via the power
jack, access it through this pin.
5V: This pin outputs a regulated 5V from the regulator on the board. The board can be
supplied with power either from the DC power jack (7 - 20V), the USB connector (5V),
or the VIN pin of the board (7-20V). Supplying voltage via the 5V or 3.3V pins bypasses
the regulator, and can damage the board.
3V3: A 3.3 volt supply generated by the on-board regulator. Maximum current draw is
50 mA.
GND: Ground pins.
IOREF: This pin on the Arduino/Genuino board provides the voltage reference with
which the microcontroller operates. A properly configured shield can read the IOREF pin
voltage and select the appropriate power source or enable voltage translators on the
outputs to work with the 5V or 3.3V.
Reset: Typically used to add a reset button to shields which block the one on the
board.
Each of the 14 digital pins and 6 Analog pins on the Uno can be used as an input or output,
using pinMode(),digitalWrite(), and digitalRead() functions. They operate at 5 volts. Each pin
can provide or receive 20 mA as recommended operating condition and has an internal pull-
up resistor (disconnected by default) of 20-50k ohm. A maximum of 40mA is the value that
must not be exceeded on any I/O pin to avoid permanent damage to the microcontroller.The
Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of resolution
(i.e. 1024 different values). By default they measure from ground to 5 volts, though is it
possible to change the upper end of their range using the AREF pin and the analogReference()
function.[
Serial / UART: pins 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL
serial data. These pins are connected to the corresponding pins of the ATmega8U2 USB-
to-TTL Serial chip.
External Interrupts: pins 2 and 3. These pins can be configured to trigger an
interrupt on a low value, a rising or falling edge, or a change in value.
PWM (Pulse Width Modulation): 3, 5, 6, 9, 10, and 11 Can provide 8-bit PWM
output with the analogWrite() function.
SPI (Serial Peripheral Interface): 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These
pins support SPI communication using the SPI library.
TWI (Two Wire Interface) / I²C: A4 or SDA pin and A5 or SCL pin. Support TWI
communication using the Wire library.
AREF (Analog REFerence): Reference voltage for the analog inputs.[
Department of Physics, Govt Emerson College, Multan
P a g e | 30
Communication
The Arduino/Genuino Uno has a number of facilities for communicating with a computer,
another Arduino/Genuino board, or other microcontrollers. The ATmega328 provides UART
TTL (5V) serial communication, which is available on digital pins 0 (RX) and 1 (TX). An
ATmega16U2 on the board channels this serial communication over USB and appears as a
virtual com port to software on the computer. The 16U2 firmware uses the standard USB
COM drivers, and no external driver is needed. However, on Windows, a .inf file is required.
The Arduino Software (IDE) includes a serial monitor which allows simple textual data to be
sent to and from the board. The RX and TX LEDs on the board will flash when data is being
transmitted via the USB-to-serial chip and USB connection to the computer (but not for serial
communication on pins 0 and 1). A SoftwareSerial library allows serial communication on
any of the Uno's digital pins.
Rather than requiring a physical press of the reset button before an upload, the
Arduino/Genuino Uno board is designed in a way that allows it to be reset by software
running on a connected computer. One of the hardware flow control lines (DTR) of the
ATmega8U2/16U2 is connected to the reset line of the ATmega328 via a 100 nanofarad
capacitor. When this line is asserted (taken low), the reset line drops long enough to reset the
chip.
This setup has other implications. When the Uno is connected to a computer running Mac OS
X or Linux, it resets each time a connection is made to it from software (via USB). For the
following half-second or so, the bootloader is running on the Uno. While it is programmed to
ignore malformed data (i.e. anything besides an upload of new code), it will intercept the first
few bytes of data sent to the board after a connection is opened.
All the above mentioned LCD display will have 16 Pins and the programming approach is
also the same and hence the choice is left to you. Below is the Pinout and Pin Description of
16x2 LCD Module:
Sr.
Pin No. Pin Name Pin Type Pin Description Pin Connection
No
1 Pin 1 Ground Source Pin This is a ground pin of Connected to the
LCD ground of the MCU/
Power source
Connected to the
This is the supply
2 Pin 2 VCC Source Pin supply pin of Power
voltage pin of LCD
source
Connected to a
Adjusts the contrast of
3 Pin 3 V0/VEE Control Pin variable POT that
the LCD.
can source 0-5V
Connected to a MCU
In 4-Wire Mode
Okay, what is this two black circle like things on the back of our LCD?
These black circles consist of an interface IC and its associated components to help us use this
LCD with the MCU. Because our LCD is a 16*2 Dot matrix LCD and so it will have
(16*2=32) 32 characters in total and each character will be made of 5*8 Pixel Dots. A Single
character with all its Pixels enabled is shown in the below picture.
So Now, we know that each character has (5*8=40) 40 Pixels and for 32 Characters we will
have (32*40) 1280 Pixels. Further, the LCD should also be instructed about the Position of
the Pixels.
It will be a hectic task to handle everything with the help of MCU, hence an Interface IC like
HD44780 is used, which is mounted on LCD Module itself. The function of this IC is to get
the Commands and Data from the MCU and process them to display meaningful
information onto our LCD Screen.
Let’s discuss the different type of mode and options available in our LCD that has to be
controlled by our Control Pins.
The LCD can work in two different modes, namely the 4-bit mode and the 8-bit mode. In 4
bit mode we send the data nibble by nibble, first upper nibble and then lower nibble. For
those of you who don’t know what a nibble is: a nibble is a group of four bits, so the lower
four bits (D0-D3) of a byte form the lower nibble while the upper four bits (D4-D7) of a byte
form the higher nibble. This enables us to send 8 bit data.
Whereas in 8 bit mode we can send the 8-bit data directly in one stroke since we use all the 8
data lines.
Now you must have guessed it, Yes 8-bit mode is faster and flawless than 4-bit mode. But the
major drawback is that it needs 8 data lines connected to the microcontroller. This will make
us run out of I/O pins on our MCU, so 4-bit mode is widely used. No control pins are used to
set these modes. It's just the way of programming that change.
As said, the LCD itself consists of an Interface IC. The MCU can either read or write to this
interface IC. Most of the times we will be just writing to the IC, since reading will make it
more complex and such scenarios are very rare. Information like position of cursor, status
completion interrupts etc. can be read if required, but it is out of the scope of this tutorial.
The Interface IC present in most of the LCD is HD44780U, in order to program our LCD we
should learn the complete datasheet of the IC. The datasheet is given here.
LCD Commands:
There are some preset commands instructions in LCD, which we need to send to LCD
through some microcontroller. Some important command instructions are given below:
02 Return home
IR Sensor Module
IR Sensor Module Pinout
Pin Configuration
Range: Up to 20cm
Mounting hole
The IR sensor module consists mainly of the IR Transmitter and Receiver, Opamp, Variable
Resistor (Trimmer pot), output LED in brief.
IR LED Transmitter
Photodiode Receiver
Photodiode acts as the IR receiver as its conducts when light falls on it. Photodiode is a
semiconductor which has a P-N junction, operated in Reverse Bias, means it start conducting
the current in reverse direction when Light falls on it, and the amount of current flow is
proportional to the amount of Light. This property makes it useful for IR detection.
Photodiode looks like a LED, with a black colour coating on its outer side, Black colour
absorbs the highest amount of light.
LM358 Opamp
Photodiode’s series resistor voltage drop > Threshold voltage = Opamp output is High
Photodiode’s series resistor voltage drop < Threshold voltage = Opamp output is Low
When Opamp's output is high the LED at the Opamp output terminal turns ON (Indicating
the detection of Object).
Variable Resistor
The variable resistor used here is a preset. It is used to calibrate the distance range at which
object should be detected.
The 5 VDC supply input is given to the VCC pin and the supply negative is connected to the
GND terminal of the module. When no object is detected within the range of the IR receiver,
the output LED remains off.
When a object is detected within the range of the IR sensor the LED glows.
Applications
Obstacle Detection
Industrial safety devices
Wheel encoder
2D-Model
We can control high voltage electronic devices using relays. A Relay is actually a switch
which is electrically operated by an electromagnet. The electromagnet is activated with a low
voltage, for example 5 volts from a microcontroller and it pulls a contact to make or break a
high voltage circuit.
As an example for this Arduino Relay Tutorial we will use the HL-52S 2 channel relay
module, which has 2 relays with rating of 10A @ 250 and 125 V AC and 10A @ 30 and 28 V
DC. The high voltage output connector has 3 pins, the middle one is the common pin and as
we can see from the markings one of the two other pins is for normally open connection and
the other one for normally closed connection.
On the other side of the module we have these 2 sets of pins. The first one has 4 pins, a
Ground and a VCC pin for powering the module and 2 input pins In1 and In2. The second set
of pins has 3 pins with a jumper between the JDVcc and the Vcc pin. With a configuration
like this the electromagnet of the relay is directly powered from the Arduino Board and if
something goes wrong with the relay the microcontroller could get damaged.
For better understanding let’s see the circuit schematics of the relay module in this
configuration. So we can see that the 5 volts from our microcontroller connected to the Vcc
pin for activating the relay through the Optocoupler IC are also connected to the JDVcc pin
which powers the electromagnet of the relay. So in this case we got no isolation between the
relay and the microcontroller.
In order to isolate the microcontroller from the relay, we need to remove the jumper and
connect separate power supply for the electromagnet to the JDVcc and the Ground pin. Now
with this configuration the microcontroller doesn’t have any physical connection with the
relay, it just uses the LED light of the Optocoupler IC to activate the relay.
There is one more thing to be noticed from this circuit schematics. The input pins of the
module work inversely. As we can see the relay will be activated when the input pin will be
LOW because in that way the current will be able to flow from the VCC to the input pin
which is low or ground, and the LED will light up and active the relay. When the input pin
will be HIGH there will be no current flow, so the LED will not light up and the relay will not
be activated.
3.7 DC Fan ’
A computer fan is any fan inside, or attached to, a computer case used for active cooling. Fans
Department of Physics, Govt Emerson College, Multan
P a g e | 43
are used to draw cooler air into the case from the outside, expel warm air from inside, and
move air across a heat sink to cool a particular component. ‘
The light bulb is supplied with electric current by feed-through terminals or wires embedded
in the glass. Most bulbs are used in a socket which provides mechanical support and electrical
connections.
Chapter 4
SYSTEM DESIGN AND DEVELOPMENT
4.1 Introduction
This project helps those people who interested to build something with Arduino. To Design a
project include into two parts, one is hardware design and another part is software design. We
use laser, Op-Amp, photo diode and gas sensor for the hardware design and we connected
these components with microcontroller. Arduino microcontroller is more suitable for
establishing a new project including robotics. Arduino software is downloaded from
www.arduino.cc and C/C++ programmable language is used. Many examples are given in the
ardiono.cc and this software is easy to usage. ’
The whole system design is divided into three parts to design a smart home appliance control
system. First one is to design the smart system in the breadboard and control the designed
system. Second part is to display part design to count the value in smart system. And third
Finally, the smart home appliance control system is formed a complete integrated system. In
this project Arduino development board is more efficient.
The whole system consists of many sub-systems. The block diagram of the whole system is
given the Figure
We use 16 x 2 LCD and that have a parallel interface, meaning that the microcontroller has
to manipulate several interface pins at once to control the display. We can select the data
register, which holds what goes on the screen. A Read/ Write (R/W) pin that selects reading
mode or writing mode.
The Enable pin that enables writing to the registers .The 8 data pins (D0 -D7). The
states of these pins (high or low) are the bits that we writing to a register. There's also a
display contrast pin (Vo), power supply pins (+5V and Ground)and LED Backlight (Bklt+
and BKlt-) pins that web use to power the LCD, control the display contrast, and turn on
and off the LED backlight, respectively.
We use 12V Relay for connect a light or electricity supply of a room. The main operation of a
relay comes in places where only a low-power signal can be used to control a circuit. It is also
used in places where only one signal can be used to control a lot of circuits. The high end
applications of relays require high power to be driven by electric motors. Relays are called
contactors.
We connect Arduino pin 10 with input pin of relay. The two terminals of a relay operate as a
switch. When the contacts are 'in contact' then the current flows from Terminal to Terminal.
There are two types of contacts, the NO and the NC. NO stands for Normal Open contact,
while NC stands for Normal Closed contact. The Normal Open is a contact like the one
showed in the previous illustration. When the contacts is still, then no current flows through it
(because it is an OPEN circuit). On the other hand, a Normal Closed contact allows the
current to flow when the contact is still. The NC contact is turned upside-down compared to
the NO contact. This way, both contacts (NO and NC) will change state if a force is applied to
the left metal heading from UP to DOWN. The device that forces the terminal to move is
actually an electromagnet. A coil is placed right under the contact. When current is flown
through this coil, magnetism is created. This magnetism can overcome the force of the spring
and can pull the contact towards it, thus it changes its position. And due to the fact that the
contact is usually a small piece of metal not capable to be pulled by the electromagnet,
another piece of metal is attached to the common. The other side of relay is connected to bulb
or electricity supply of a room. We need 12V power supply.
Software design is divided into two parts. First we write the Arduino program in Arduino
software. Then we compile it to the Arduino hardware. This Arduino command is control the
Arduino hardware and other circuit and display connection.
4.10 Code
#include<LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
#define in 8
#define out 9
#define fan 10
int count=0;
void setup()
{
lcd.begin(16,2);
lcd.print("Visitor Counter");
delay(2000);
pinMode(in, INPUT);
pinMode(out, INPUT);
pinMode(fan, OUTPUT);
lcd.clear();
lcd.print("Person In Room:");
lcd.setCursor(0,1);
lcd.print(count);
}
void loop()
{
int in_value = digitalRead(in);
int out_value = digitalRead(out);
if(in_value == LOW)
{
count++;
Department of Physics, Govt Emerson College, Multan
P a g e | 53
lcd.clear();
lcd.print("Person In Room:");
lcd.setCursor(0,1);
lcd.print(count);
delay(1000);
}
if(out_value == LOW)
{
count--;
lcd.clear();
lcd.print("Person In Room:");
lcd.setCursor(0,1);
lcd.print(count);
delay(1000);
}
if(count==0)
{
lcd.clear();
digitalWrite(fan, LOW);
lcd.clear();
lcd.print("Nobody In Room");
lcd.setCursor(0,1);
lcd.print("Fan is Off");
delay(200);
}
else
{
digitalWrite(fan, HIGH);
}
}
Chapter 5
Conclusions
5.1Applications:
1. This circuit can be used domestically to get an indication of number of persons entering a party.
2. It can be used at official meetings.
3. It can be used at homes and other places to keep a check on the number of persons entering a
secured place.
4. It can also be used as home automation system to ensure energy saving by switching on the loads
and fans only when needed.
5.2Limitations:
5.3 It is a theoretical circuit and may require few changes in practical implementation.
5.4 It is a low range circuit and cannot be implemented at large areas.
5.5 More than one candidate should not enter or exit the room. If it happens it will count it as a
single person.
5.6 With frequent change in the count value, after a certain time the output may look confusing
5.7 In this Module we are using a room having capacity of 9 candidates. So we are using only
one segment that can show from 0 to 9999 only. For a large room we will use a no. of
segments. For example for 99999 candidates we will use 9 segments.
5.3Advantages:
1. The Most advantage is that it will help to save electricity. When no one is there in
room the appliances will be off.
5.4 Conclusion
In our project We have designed and implemented a Bi-Directional Counter the concept of
Department of Physics, Govt Emerson College, Multan
P a g e | 56
Embedded System. The target users of the project can be any one right from a common man to
any organization. Lets say if any one uses our project for Seminar Purpose then the track record
of the persons attending the seminar will give the exact idea about the no. of candidate attending
and leaving the seminar and accordingly. In making this project We all team mates have to
really give our best and it was all possible due to unmatched guidelines of our mentor “Prof. Dr.
M. Tariq Bhatti”. We will be highly obliged to you for this kind support.
5.5 Bibliography
Reference Site:
1. www.google.co.i
2.www.wikipedia.com
3.www.cmcjaipur.com
4.www.electronicsfory
ou.com
5.www.encyclpedia.co
Reference Books:
1.E BALAGURUSAMY, “Programming in ANSI C”, Tata McGraw Hill, May 2010.