You are on page 1of 57

Bidirectional Visitor Counter with Automatic Room

Light Control System Using Arduino and IR Sensor

Project Submitted by:

Saeeda Rasool PHY-19-05


Maryam Adrees PHY-19-03
Javeria Jabbar PHY-19-11
Urooj Akhtar PHY-19-15

Under the Supervision of

Mubasshar Siddique

Department of Physics
Beacon Light College Fateh Pur (Layyah)

2019-2023
Bidirectional Visitor Counter with Automatic Room
Light Control System Using Arduino and IR Sensor

A Project submitted to Department of Physics, Beacon Light College Fateh Pur


(Layyah) in partial fulfillment of the requirements for the degree of BS
Physics.

Saeeda Rasool PHY-19-05


Maryam Adrees PHY-19-03
Javeria Jabbar PHY-19-11
Urooj Akhtar PHY-19-15

Department of Physics,
Beacon Light College Fateh Pur (Layyah)
Session 2019-2023
DECLARATION

This is to certify that the project “Bidirectional Visitor Counter with Automatic Room Light
Control System Using Arduino and IR Sensor” 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.
APPROVAL

The project titled - “Bidirectional Visitor Counter with Automatic Room Light Control
System Using Arduino and IR Sensor and ” prepared by the following students has been
submitted to the following respective members of Department of Physics, Beacon Light
College Fateh Pur Layyah in partial fulfillment of the requirements for the degree of BS
Physics.

Saeeda Rasool PHY-19-05


Maryam Adrees PHY-19-03
Javeria Jabbar PHY-19-11
Urooj Akhtar PHY-19-15

------------------------------- ------------------------------------

Mubasshar Siddique External Examiner


……………………………
Department of Physics, Department of Physics,
Beacon Light College Bahauddin Zakariya University
Fateh Pur (Layyah) Multan
Table of Contents
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.1) Applications 52
5.2) Limitations 52
5.3) Advantages 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 Mubasshar Siddique 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.

Our appreciation also goes to our beloved Department of Physics for providing us the
opportunities to prove ourselves.
ABSTRACT

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 | 10

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.

1.1 OBJECTIVE OF THE PROJECT

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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


Chapter 2 ’

Literature Review
P a g e | 12

2.1 LITERATURE REVIEW

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 Counter”
[1]
. The main purpose of the project is automation, saving electricity, increasing appliance life
span and yet providing a desired output smartly.

Subhankar Chattoraj , Aditya Chakraborty et al [2016] has done a “Bidirectional Visitor Counter
with Automatic Room Light Controller and Arduino as the master controller[2]”.This paper gives
the basic idea of how to control the bidirectional visitor counter and room light counter using
Arduino Mega and Ardiono(IDE). The cost of this technology is very economical.

Sonali K. Pawar et al [2016] has done a “AUTOMATIC ROOM LIGHT CONTROLLER


USING MICROCONTROLLER AND VISITOR COUNTER ”[3].This digital world Technology
is very advanced and we prefer things to be done automatically without any human efforts. This
project also helps to reduce human efforts. Also it is very useful to conserve resources.

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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 13

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.

Kimbley et al[2016]has done “AUTOMATIC ROOM LIGHT CONTROLLER USING


MICROCONTROLLER AND VISITOR COUNTER ”[9]. The Project ‘Automatic Room Light
Controller Using microcontroller ATMEGA16A and bidirectional visitor counter’ controls a
room light as well as count the number of individuals entering and leaving a room. When an
individual enters into a room then one counter is incremented by one and one light in a room will
be switched ON and when the individuals leaves a room then the counter is decremented by one.

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.

2.2 PROJECT REPORT ORGANIZATION

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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 14

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 3

Hardware and Components

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 16

CHAPTER THREE

Related Theory

3.0 THEORIES AND MODELS RELEVANT TO THE DESIGN

3.1 List of Components:

Following is the list of components that are necessary to build the assembly the project.

➢ Arduino Uno Board

➢ Voltage Regulator (7805)

➢ 16×2 LCD display

➢ 13V Step Down Transformer

➢ Male and Female Header

➢ Voltage Regulator

➢ Resistors

➢ IR Sensor
➢ LED

➢ Potentiometer – 10kΩ

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 17

➢ Computer with Arduino software installed

The system designed was based on fundamental and principles of electromagnetism, electronic
devices, interfacing, intelligent control systems, and software systems.

3.2 Power Supply


Understanding 7805 IC Voltage Regulator

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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 18

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.

A Brief Note on 7805 Voltage Regulator

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).

Some of the important features of the 7805 IC are as follows:

• It can deliver up to 1.5 A of current (with heat sink).


• Has both internal current limiting and thermal shutdown features.
• Requires very minimum external components to fully function.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 19

Pin Diagram of 7805 Voltage Regulator IC

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.

The pin description of the 7805 is described in the following table:

PIN NO. PIN DESCRIPTION

1 INPUT Pin 1 is the INPUT Pin. A positive unregulated voltage is given as


input to this pin.

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

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 20

PIN NO. PIN DESCRIPTION

pin of the IC.

Basic Circuit of 7805

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).

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 21

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.

How to Get Constant DC Power Supply from AC?

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 22

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

• 230V-12V Step Down Transformer


• Bridge Rectifier (or 4 PN Diodes – 1N4007)
• 1A Fuse
• 1000μF Capacitor
• 7805 Voltage Regulator IC
• 0.22μF Capacitor
• 0.1μF Capacitor
• 1N4007 Diode

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 23

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.

Important Points on 7805 Voltage Regulator IC

• 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.

3.3 Arduino Uno


Department of Physics, Beacon Light College Fateh Pur (Layyah)
P a g e | 24

Arduino UNO

Arduino Uno SMD R3

Developer Arduino

Manufacturer Many

Type Single-board microcontroller[1]

Operating system None

CPU Microchip AVR (8-bit)

Memory SRAM

Storage Flash, EEPROM

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 25

The Arduino UNO is an open-source microcontroller board based on


the Microchip ATmega328P microcontroller and developed by Arduino.cc. The board is
equipped with sets of digital and analog input/output (I/O) pins that may be interfaced to 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

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 26

Background

an early production board

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
• DC Current for 3.3V Pin: 50 mA
• Flash Memory: 32 KB of which 0.5 KB used by bootloader

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 27

• SRAM: 2 KB
• EEPROM: 1 KB
• Clock Speed: 16 MHz
• Length: 68.6 mm
• Width: 53.4 mm
• Weight: 25 g

Pins

Arduino UNO

General Pin functions

• 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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 28

• 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.

Special Pin Functions

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.[

In addition, some pins have specialized functions:

• 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.[

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
Department of Physics, Beacon Light College Fateh Pur (Layyah)
P a g e | 29

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.

Automatic (Software) Reset

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.

3.4 16x2 LCD Display Module

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 30

16x2 LCD Display Module with HD44780 Controller


16×2 LCD is named so because; it has 16 Columns and 2 Rows. There are a lot of combinations
available like, 8×1, 8×2, 10×2, 16×1, etc. But the most used one is the 16*2 LCD, hence we
are using it here.

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

Connected to the
1 Pin 1 Ground Source Pin This is a ground pin of
ground of the MCU/

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 31

LCD 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 can
the LCD.
source 0-5V

Connected to a MCU

Toggles between pin and gets either 0


4 Pin 4 Register Select Control Pin Command/Data or 1.

Register 0 -> Command Mode

1-> Data Mode

Connected to a MCU

Toggles the LCD pin and gets either 0


5 Pin 5 Read/Write Control Pin between Read/Write or 1.
Operation 0 -> Write Operation

1-> Read Operation

Must be held high to


Connected to MCU
6 Pin 6 Enable Control Pin perform Read/Write
and always held high.
Operation

In 4-Wire Mode

Only 4 pins (0-3) is


Pins used to send
Data/Command connected to MCU
7 Pin 7-14 Data Bits (0-7) Command or data to the
Pin In 8-Wire Mode
LCD.
All 8 pins(0-7) are
connected to MCU

Normal LED like


8 Pin 15 LED Positive LED Pin operation to illuminate Connected to +5V
the LCD

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 32

Normal LED like


operation to illuminate
9 Pin 16 LED Negative LED Pin Connected to ground
the LCD connected with
GND.

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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 33

4-bit and 8-bit Mode of LCD:

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.

Read and Write Mode of LCD:

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:

Hex Code Command to LCD Instruction Register

0F LCD ON, cursor ON

01 Clear display screen

02 Return home

04 Decrement cursor (shift cursor to left)

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 34

06 Increment cursor (shift cursor to right)

05 Shift display right

07 Shift display left

0E Display ON, cursor blinking

80 Force cursor to beginning of first line

C0 Force cursor to beginning of second line

38 2 lines and 5×7 matrix

83 Cursor line 1 position 3

3C Activate second line

08 Display OFF, cursor OFF

C1 Jump to second line, position 1

OC Display ON, cursor OFF

C1 Jump to second line, position 1

C2 Jump to second line, position 2

3.5 IR Sensor Module

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 35

IR Sensor Module
IR Sensor Module Pinout

Pin Configuration

Pin Name Description

VCC Power Supply Input

GND Power Supply Ground

OUT Active High Output

IR Sensor Module Features

• 5VDC Operating voltage

• I/O pins are 5V and 3.3V compliant

• Range: Up to 20cm

• Adjustable Sensing range

• Built-in Ambient Light Sensor

• 20mA supply current

• Mounting hole

Brief about IR Sensor Module

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 36

The IR sensor module consists mainly of the IR Transmitter and Receiver, Opamp, Variable
Resistor (Trimmer pot), output LED in brief.

IR LED Transmitter

IR LED emits light, in the range of Infrared frequency. IR light is invisible to us as its
wavelength (700nm – 1mm) is much higher than the visible light range. IR LEDs have light
emitting angle of approx. 20-60 degree and range of approx. few centimeters to several feets, it
depends upon the type of IR transmitter and the manufacturer. Some transmitters have the range
in kilometers. IR LED white or transparent in colour, so it can give out amount of maximum
light.

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

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 37

LM358 is an Operational Amplifier (Op-Amp) is used as voltage comparator in the IR sensor. the
comparator will compare the threshold voltage set using the preset (pin2) and the photodiode’s
series resistor voltage (pin3).

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.

How to Use IR Sensor Module?

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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 38

Applications

• Obstacle Detection
• Industrial safety devices
• Wheel encoder

2D-Model

3.6 Relay Module

.Overview

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.

HL-52S Relay Module

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 39

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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 40

You can get the components from any of the sites below:
• 5V Relay Module
• Arduino Board
• Breadboard and Jump Wires
• Cable, Plug, Socket
Circuit Schematic

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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 41

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.
Department of Physics, Beacon Light College Fateh Pur (Layyah)
P a g e | 42

3.7 DC Fan ’
A computer fan is any fan inside, or attached to, a computer case used for active cooling. Fans
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. ‘

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 43

3.8 Incandescent Bulb ’


An incandescent light bulb, incandescent lamp or incandescent light globe is an electric light with
a wire filament heated to such a high temperature that it glows with visible light (incandescence).
The filament is protected from oxidation with a glass or fused quartz bulb that is filled with inert
gas or a vacuum. In a halogen lamp, filament evaporation is slowed by a chemical process that
redeposits metal vapor onto the filament, thereby extending its life.

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.

Incandescent bulbs are manufactured in a wide range of sizes, light output, and voltage ratings,
from 1.5 volts to about 300 volts. They require no external regulating equipment, have
low manufacturing costs, and work equally well on either alternating current or direct current. As
a result, the incandescent bulb is widely used in household and commercial lighting, for portable
lighting such as table lamps, car headlamps, and flashlights, and for decorative and advertising
lighting.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 44

Department of Physics, Beacon Light College Fateh Pur (Layyah)


Chapter 4

Setup and Connections

Department of Physics, Govt Emerson College, Multan


P a g e | 46

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. ’

4.2 Hardware design

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

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 47

4.3 16×2 LCD Display connections with Arduino Uno

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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 48

Figure : 16×2 LCD Display connections with Arduino UNO

4.4 Connection of Relay with Arduino

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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 49

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 50

Figure : Connection of Load and Relay

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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 51

4.5 Overall Circuit Diagram

4.6 Software design

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.7 Installing Arduino

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 52

Arduino runs on Windows. Go to the Arduino software web site at


http://arduino.cc/en/Main/Software and download the version of the software compatible
with our system. We use Arduino 1.0.5 version.

4.8 Verifying the Hardware


Now that we have the Arduino IDE software installed, let’s connect the computer to the mc
board, load a small program, and verify that all components are working together. First, need to
connect the USB cable to our mc board and then plug the other end of the USB cable into our
computer.

4.9 Arduino Language


The Arduino language is implemented in C/C++ and based in Wiring. When we write an Arduino
sketch, we are implicitly making use of the Wiring library, which is included with the Arduino
IDE. This allows us to make run able programs by using only two functions: setup () and loop ().
As mentioned, the Wiring language is inspired by Processing, and the Arduino language structure
is inherited from the Processing language, where the equivalent functions are called setup (). We
need to include both functions in every Arduino program, even if we don’t need one of them.

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()
{

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 53

int in_value = digitalRead(in);


int out_value = digitalRead(out);
if(in_value == LOW)
{
count++;
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);
}
}

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 54

Chapter 5

Conclusions

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 55

5.1 Applications:

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.2 Limitations:
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.3 Advantages:
1. The Most advantage is that it will help to save electricity. When no one is there in
room the appliances will be off.

2. For School/colleges/companies it will help to check if somebody is there in the zone


or not. If the data on display unit is zero the peons or security guards can shut the gate easily.

3. Whole system will work automatically so it reduces the human work.

5.4 Conclusion

In our project We have designed and implemented a Bi-Directional Counter the concept of

Department of Physics, Beacon Light College Fateh Pur (Layyah)


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.

Department of Physics, Beacon Light College Fateh Pur (Layyah)


P a g e | 57

5.5 Bibliography

Reference Site:

1. www.google.co.in

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.

2. MUHAMMAD ALI, MAZID JANICE, GILLISPIE MAZIDI, “The


8051microcontroller
and embedded systems”, Pearson Education, April 2009.

Department of Physics, Beacon Light College Fateh Pur (Layyah)

You might also like