Room Light Controller

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

Automatic Fan Controller Using An

Aurdino

A Report on Miniproject Submitted for the requirement of


University of Mumbai
For the Practical work done during Semester-V
Miniproject-I
(Electronics Engineering)
by
Rohit Gopinath (14EE1125)
Satyajit Dash (14EE1152)
Sahil Gavankar (14EE1026)

Under the guidance of


Prof. Savita Bhosle

Department of Electronics Engineering


Ramrao Adik Institute of Technology,
Sector 7, Nerul, Navi Mumbai
(Affiliated to University of Mumbai)
September 2016

Ramrao Adik Education Societys

Ramrao Adik Institute of Technology


(Affiliated to the University of Mumbai)
Dr. D. Y. Patil Vidyanagar, Sector 7, Nerul, Navi Mumbai 400 706.

Certificate
This is to certify that, the Miniproject-I titled
Automatic Fan Controller Using An Aurdino
is a bonafide work done by
Rohit Gopinath (14EE1125)
Satyajit Dash (14EE1152)
Sahil Gavankar (14EE1026)
and is submitted in the partial fulfillment of the requirement for the
degree of
Bachelor of Engineering
in
Electronics Engineering
to the
University of Mumbai

Supervisor

Head of Department

Project Coordinator

Principal

Certificate of Approval by Examiners

This is to certify that the submission entitled for the project Automatic Fan Controller Using An Aurdino is a bonafide work done by Rohit Gopinath, Satyajit
Dash, Sahil Gavankar under the guidance of Prof. Savita Bhosle. This project work
has been approved for Semester-V in Miniproject-I, University of Mumbai.

Examiners:

Internal Examiner:

External Examiner:

Acknowledgments
With great pleasure, I avail this opportunity to express my deep sense of gratitude to my
guide, Prof. Trupti Parag Agarkar. for her inspiration, encouragement and for guiding
and correcting various document of mine with attention and care. She has taken a pain
to go through the project and make necessary correction when needed. It helped me to
work in right direction and to attain desired objective.
I am thankful to our Principal Dr. Ramesh Vasappanavara, HOD Dr. Vishwesh A.
Vyawahare for their support and encouragement. My thanks and appreciations also go to
my colleague in developing the project and people who have willingly helped me out with
their abilities. I cannot end without thanking my lovely family for their encouragement.

Abstract
This project is a standalone automatic fan speed controller that controls the speed of an
electric fan according to our requirement. Use of embedded technology makes this closed
loop feedback control system efficient and reliable. Micro controller (ATMega8 / 168 /
328) allows dynamic and faster control. Liquid crystal display (LCD) makes the system user-friendly. The sensed temperature and fan speed level values are simultaneously
displayed on the LCD panel. It is very compact using few components and can be implemented for several applications including air-conditioners, water-heaters, snow-melters,
ovens, heat-exchangers, mixers, furnaces, incubators, thermal baths and veterinary operating tables. ARDUINO micro controller is the heart of the circuit as it controls all
the functions. The temperature sensor LM35 senses the temperature and converts it into
an electrical (analog) signal, which is applied to the micro controller through ADC. The
analog signal is converted into digital format by the analog-to-digital converter (ADC).
The sensed and set values of the temperature are displayed on the 16x2-line LCD. The
micro controller drives Traic to control the fan speed. This project uses regulated 5V,
500mA 12V, 500mA power supply. 7805 and 7812 three terminal voltage regulators are
used for voltage regulation. Bridge type full wave rectifier is used to rectify the ac out
put of secondary of 230/12V step down transformer. This project is useful in process
industries for maintenance and controlling of Boilers temperature.

List of Figures
2.1

Block Diagram of Basic Microcontroller [8]. . . . . . . . . . . . . . . . . . .

3.1

Arduino and its pins [2]. . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.1
4.2
4.3
4.4

LCD screen.[4]. . .
Keypad.[3]. . . . .
Keypad Matrix.[5].
9g Servo Motor.[4].

5.1

Circuit Diagram.[2]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

6.1

Circuit Diagram.[2]. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

ii

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

. 9
. 10
. 11
. 12

Contents
Abstract

List of Figures

ii

1 Introduction
1.0.1 Then and Now . . . . . . . . . . . . . . .
1.0.2 New technology means new vulnerabilities
1.0.3 Advantages to an electronic lock . . . . . .
1.1 Keywords . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.

1
1
1
1
2

.
.
.
.
.
.

3
3
3
4
4
4
4

3 Arduino Uno
3.1 Whats on the board? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

6
7

2 General Description
2.1 Read Only Memory (ROM) . . . .
2.2 Random Access Memory (RAM) .
2.3 Electrically Erasable Programmable
2.4 Special Function Registers (SFR) .
2.5 Program Counter . . . . . . . . . .
2.6 Central Processor Unit (CPU) . . .

4 Components
4.1 LCD Screen . . . .
4.2 4x4 Keypad . . . .
4.3 Servo Motor . . . .
4.3.1 Mechanism

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

. . . . . . . . . . .
. . . . . . . . . . .
ROM (EEPROM)
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.
.
.

.
.
.
.

9
. 9
. 10
. 11
. 11

5 Circuit Description
13
5.1 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
6 Working of the circuit
15
6.1 Working . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
6.2 Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
7 Conclusion and Future Scope
20
7.1 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
7.2 Future Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Bibliography

21

iii

Chapter 1
Introduction
An electronic lock is a device which has an electronic control assembly attached to it.
They are provided with an access control system. This system allows the user to unlock
the device with a password. The password is entered by making use of a keypad. The user
can also set his password to ensure better protection Electric locks use magnets, solenoids,
or motors to actuate the lock by either sup- plying or removing power. Operating the
lock can be as simple as using a switch, for example an apartment intercom door release,
or as complex as a biometric based access control system.

1.0.1

Then and Now

The idea behind a basic electronic lock is simple: use a keypad or push buttons to enter a code rather than using a key (although most allow the use of a key to lock the
door).Because a mechanical key cylinder can still be used, the basic electronic locks offer
no less security than the mechanical type. Additionally, anyone in the area can observe
the code being used, effectively giving them a key. Todays high-tech electronic locks
operate wirelessly, whether or not they have an exposed keypad.

1.0.2

New technology means new vulnerabilities

The vulnerabilities of mechanical locking systems are well-documented and widely known.
But a physical contact is necessary to bypass a mechanical lock. The necessity for physical
presence is reduced or eliminated when locks are operated wirelessly, and that creates a
new vulnerability: hacking. Cyber criminals delight in overcoming security obstacles, and
its anyones guess how long these technologies will withstand the challenge.

1.0.3

Advantages to an electronic lock

1) Ease of Use With newer electronic locking systems, the option of using a keyless entry
fob device to unlock your door can be easier than fumbling with a key when your arms
are full of groceries.
2) Convenience There are times when convenience is important. If you have several people needing access to a single door, an electronic lock with keypad or push-button code
operation may be a better solution than issuing a number of keys. Remember that the
more ways there are to unlock a door, the more vulnerable it is to being bypassed.

3) If you have children, this can be a good reason to use an electronic lock with a keypad
or push buttons to enter an entry code. They can get in the habit of securing and opening
the home without worrying about lost keys.

1.1

Keywords

Microcontroller - A microcontroller (sometimes abbreviated C, uC or MCU) Input and


Output devices - I/O

Chapter 2
General Description
Microcontrollers are being used increasingly as tools for analysis and design of control
systems. The control Engineer thus has much more powerful tools available now than
in the past. Digital computers are still in a state of rapid development because of the
progress in very-large scale integration(VLSI) technology. Thus substantial technological improvements can be expected in future. A microcontroller (sometimes abbreviated
uC or MCU) is a small computer on a single integrated circuit containing a processor
core, memory, and programmable input peripherals. Microcontrollers are used in automatically controlled products and devices, such as automobile engine control systems,
implantable medical devices, remote controls, office machines, appliances, power tools,
toys and other embedded systems. By reducing the size and cost compared to a design
that uses a separate microprocessor, memory, and input/output devices, microcontrollers
make it economical to digitally control even more devices and processes. Mixed signal microcontrollers are common, integrating analog components needed to control non-digital
electronic systems. All the operations within the microcontroller are performed at high
speed and quite simply, but the microcontroller itself would not be so useful if there are
not special circuits which make it complete. In continuation, we are going to call your
attention to them.

2.1

Read Only Memory (ROM)

It is a type of memory used to permanently save the program being executed. The size
of the program that can be written depends on the size of this memory. ROM can be
built in the microcontroller or added as an external chip, which depends on the type of
the microcontroller.The internal ROM is usually smaller and more expensive, but leaves
more pins available for connecting to peripheral environment. The size of ROM ranges
from 512B to 64KB.

2.2

Random Access Memory (RAM)

It is a type of memory used for temporary storing data and intermediate results created
and used during the operation of the microcontrollers. The content of this memory is
cleared once the power supply is off.The size of RAM goes up to a few KBs.

2.3

Electrically Erasable Programmable ROM (EEPROM)

The EEPROM is a special type of memory not contained in all microcontrollers. Its
contents may be changed during program execution (similar to RAM ), but remains
permanently saved even after the loss of power (similar to ROM). It is often used to store
values, created and used during operation (such as calibration values, codes, values to
count up to etc.), which must be saved after turning the power supply o. A disadvantage
of this memory is that the process of programming is relatively slow. It is measured in
miliseconds.

2.4

Special Function Registers (SFR)

They are part of RAM memory. Their purpose is predefined by the manufacturer and
cannot be changed therefore. Since their bits are physically connected to particular circuits within the microcontroller, such as A/D converter, serial communication module
etc., any change of their state directly affects the operation of the microcontroller or some
of the circuits.

2.5

Program Counter

It is an engine running the program and points to the memory address containing the
next instruction to execute. After each instruction execution, the value of the counter is
incremented by 1. For this reason, the program executes only one instruction at a time
just as it is written.

2.6

Central Processor Unit (CPU)

This is a unit which monitors and controls all processes within the microcontroller and
the user cannot affect its work.It consists of several smaller subunits, of which the most
important are:
Instruction decoder : It is a part of the electronics which recognizes program
instructions and runs other circuits on the basis of that.
Arithmetical Logical Unit (ALU): It performs all mathematical and logical
operations upon data.

Figure 2.1: Block Diagram of Basic Microcontroller [8].

The purpose of this project work is to present control theory that is relevant to
the analysis and design of Microcontroller system with an emphasis on basic concept
and ideas. It is assumed that a microcontroller with reasonable software is available for
computations and simulations so that many tedious details can be left to the Microcontroller. Microcontrollers are embedded inside some other device so that they can control
the features or actions of the product. Another name for a microcontroller, therefore, is
embedded controller. Microcontroller are dedicated to one task and run one specific
program. The Program is stored in ROM and generally does not change. Microcontrollers
are often low power devices. A battery operated Microcontroller might consume 50 mW.
A microcontroller has a dedicated input device and often has a small LED or LCD display
for output. It also takes input from the device it is controlling and controls the device by
sending signals to dierent components in the device.

Chapter 3
Arduino Uno
Arduino is an open-source prototyping platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or
a Twitter message - and turn it into an output - activating a motor, turning on an LED,
publishing something online. You can tell your board what to do by sending a set of
instructions to the microcontroller on the board. To do so you use the Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on Processing.
The Arduino Uno is a microcontroller board based on the ATmega328 ( datasheet). It has
14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs,
a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset
button. It contains everything needed to support the microcontroller; simply connect it
to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get
started. The Uno differs from all preceding boards in that it does not use the FTDI USBto-serial driver chip. Instead, it features the Atmega8U2 programmed as a USB-to-serial
converter. Uno means one in Italian and is named to mark the upcoming release of
Arduino 1.0. The Uno and version 1.0 will be the reference versions of Arduno, moving
forward. The Uno is the latest in a series of USB Arduino boards, and the reference model
for the Arduino platform.
Why Arduino ?
Thanks to its simple and accessible user experience, Arduino has been used in thousands of different projects and applications. The Arduino software is easy-to-use for
beginners, yet flexible enough for advanced users. It runs on Mac, Windows, and Linux.
Teachers and students use it to build low cost scientific instruments, to prove chemistry
and physics principles, or to get started with programming and robotics. Designers and
architects build interactive prototypes, musicians and artists use it for installations and
to experiment with new musical instruments. Makers, of course, use it to build many of
the projects exhibited at the Maker Faire, for example. Arduino is a key tool to learn
new things. Anyone - children, hobbyists, artists, programmers - can start tinkering just
following the step by step instructions of a kit, or sharing ideas online with other members
of the Arduino community.
There are many other microcontrollers and microcontroller platforms available for
physical computing. Parallax Basic Stamp, Netmedias BX-24, Phidgets, MITs Handyboard, and many others offer similar functionality. All of these tools take the messy details
of microcontroller programming and wrap it up in an easy-to-use package. Arduino also
simplifies the process of working with microcontrollers, but it offers some advantage for
6

teachers, students, and interested amateurs over other systems.

3.1

Whats on the board?

Figure 3.1: Arduino and its pins [2].

Power(USB / Barrel Jack) -Every Arduino board needs a way to be connected to a


power source. The Arduino UNO can be powered from a USB cable coming from your
computer or a wall power supply (like this) that is terminated in a barrel jack. In the
picture above the USB connection is labeled (1) and the barrel jack is labeled (2). The
USB connection is also how you will load code onto your Arduino board. More on how to
program with Arduino can be found in our Installing and Programming Arduino tutorial.
The recommended voltage for most Arduino models is between 6 and 12 Volts. Pins (5V,
3.3V, GND, Analog, Digital, PWM, AREF) The pins on your Arduino are the places
where you connect wires to construct a circuit (probably in conjuction with a breadboard
and some wire. They usually have black plastic headers that allow you to just plug a
wire right into the board. The Arduino has several different kinds of pins, each of which
is labeled on the board and used for different functions.
GND (3): Short for Ground. There are several GND pins on the Arduino, any of
which can be used to ground your circuit.
5V (4) and 3.3V (5):As you might guess, the 5V pin supplies 5 volts of power, and
the 3.3V pin supplies 3.3 volts of power. Most of the simple components used with the
Arduino run happily off of 5 or 3.3 volts.
Analog (6):The area of pins under the Analog In label (A0 through A5 on the UNO)
are Analog In pins. These pins can read the signal from an analog sensor (like a temperature sensor) and convert it into a digital value that we can read.
7

Digital (7):Across from the analog pins are the digital pins (0 through 13 on the UNO).
These pins can be used for both digital input (like telling if a button is pushed) and digital
output (like powering an LED).
PWM (8):You may have noticed the tilte next to some of the digital pins (3, 5, 6,
9, 10, and 11 on the UNO). These pins act as normal digital pins, but can also be used
for something called Pulse-Width Modulation (PWM). We have a tutorial on PWM, but
for now, think of these pins as being able to simulate analog output (like fading an LED
in and out).
AREF (9):Stands for Analog Reference. Most of the time you can leave this pin alone.
It is sometimes used to set an external reference voltage (between 0 and 5 Volts) as the
upper limit for the analog input pins.
Reset Button -Just like the original Nintendo, the Arduino has a reset button (10).
Pushing it will temporarily connect the reset pin to ground and restart any code that is
loaded on the Arduino. This can be very useful if your code doesnt repeat, but you want
to test it multiple times. Unlike the original Nintendo however, blowing on the Arduino
doesnt usually fix any problems.
Power LED Indicator -Just beneath and to the right of the word UNO on your
circuit board, theres a tiny LED next to the word ON (11). This LED should light up
whenever you plug your Arduino into a power source. If this light doesnt turn on, theres
a good chance something is wrong. Time to re-check your circuit!
TX RX LEDs -TX is short for transmit, RX is short for receive. These markings
appear quite a bit in electronics to indicate the pins responsible for serial communication.
In our case, there are two places on the Arduino UNO where TX and RX appear - once
by digital pins 0 and 1, and a second time next to the TX and RX indicator LEDs (12).
These LEDs will give us some nice visual indications whenever our Arduino is receiving
or transmitting data (like when were loading a new program onto the board).
Main IC -The black thing with all the metal legs is an IC, or Integrated Circuit (13).
Think of it as the brains of our Arduino. The main IC on the Arduino is slightly different
from board type to board type, but is usually from the ATmega line of ICs from the
ATMEL company. This can be important, as you may need to know the IC type (along
with your board type) before loading up a new program from the Arduino software. This
information can usually be found in writing on the top side of the IC. If you want to know
more about the dierence between various ICs, reading the datasheets is often a good idea.
Voltage Regulator -The voltage regulator (14) is not actually something you can (or
should) interact with on the Arduino. But it is potentially useful to know that it is there
and what its for. The voltage regulator does exactly what it says - it controls the amount
of voltage that is let into the Arduino board. Think of it as a kind of gatekeeper; it will
turn away an extra voltage that might harm the circuit. Of course, it has its limits, so
dont hook up your Arduino to anything greater than 20 volts.

Chapter 4
Components
4.1

LCD Screen

LCD stands for liquid crystal display. They come in many sizes 8x1 , 8x2 , 10x2 , 16x1 ,
16x2 , 16x4 , 20x2 , 20x4 ,24x2 , 30x2 , 32x2 , 40x2 etc . Many multinational companies
like Philips Hitachi Panasonic make their own special kind of lcds to be used in their
products.All the lcds performs the same functions(display characters numbers special
characters ASCII characters etc).Their programming is also same and they all have same
14 pins (0-13) or 16 pins (0 to 15).

Figure 4.1: LCD screen.[4].

ALL LCDs have:


Eight(8) Data pins
VCC (Apply 5v here)
(Ground this pin)
9

RS (Register select)
RW (read - write)
EN (Enable)
V0 (Set Lcd contrast)

4.2

4x4 Keypad

Various sizes of keypad modules are avaliable in the market nowadays like 4x4, 4x3 and
in this project a 4x4 keypad is used.

Figure 4.2: Keypad.[3].

How does a Keypad Work?


What you probably have in front of you, is a keyboard with more than 100 keys on it... If
you are not familiar with the key matrices, then you may think that inside this keyboard,
there is a chip (probably a microcontroller) that has at least the same number of inputs
to read each key separately. Well, this is far from true...

What are the key matrices? The matrices are actually an interface technique.
It can be used to interface inputs like the PC keyboard keys, but also to control multiple
outputs like LEDs. According to this technique, the I/O are divided into two sections:
the columns and the rows. You can imagine a matrix as an excel sheet. Here is a 4 x 4
matrix
10

Figure 4.3: Keypad Matrix.[5].

The blue lines are the columns and the red lines the rows. There are 16 knots that
the rows and columns intersect. The columns and the rows are NOT in contact! Suppose
that we want to make a key matrix. To do this, we will have to connect a button to each
knot. The buttons will have a push-to-make contact. When the operator pushes this
button, it will connect the column and the row that it corresponds to. Now i will put the
push-to-make buttons onto the matrix

4.3

Servo Motor

A servomotor is a rotary actuator or linear actuator that allows for precise control of
angular or linear position, velocity and acceleration.[1] It consists of a suitable motor coupled to a sensor for position feedback. It also requires a relatively sophisticated controller,
often a dedicated module designed specifically for use with servomotors. Servomotors are
not a specific class of motor although the term servomotor is often used to refer to a motor
suitable for use in a closed-loop control system. Servomotors are used in applications such
as robotics, CNC machinery or automated manufacturing.

4.3.1

Mechanism

servomotor is closed-loop servomechanism that uses position feedback to control its motion
and final position. The input to its control is some signal, either analogue or digital,
representing the position commanded for the output shaft. The motor is paired with
some type of encoder to provide position and speed feedback. In the simplest case,
only the position is measured. The measured position of the output is compared to the
11

command position, the external input to the controller. If the output position differs
from that required, an error signal is generated which then causes the motor to rotate in
either direction, as needed to bring the output shaft to the appropriate position. As the
positions approach, the error signal reduces to zero and the motor stops.

Figure 4.4: 9g Servo Motor.[4].

The very simplest servomotors use position-only sensing via a potentiometer and
bang-bang control of their motor; the motor always rotates at full speed (or is stopped).
This type of servomotor is not widely used in industrial motion control, but it forms the
basis of the simple and cheap servos used for radio-controlled models. More sophisticated
servomotors use optical rotary encoders to measure the speed of the output shaft and
a variable-speed drive to control the motor speed. Both of these enhancements, usually
in combination with a PID control algorithm, allow the servomotor to be brought to its
commanded position more quickly and more precisely, with less overshooting.

12

Chapter 5
Circuit Description
5.1

Circuit Diagram

Figure 5.1: Circuit Diagram.[2].

The circuit diagram of Passcode based Lock is as shown above. The Arduino Uno board
acts as a microcontroller board with all the peripherals connected to it. It process all
the tasking from asking for passcode to checking and even changing of passcode. Keypad
module has 8 pins amongst which first 4 pins that is the row pins are connected to
Arduinos digital pins D2,D3,D4 and D5, while the remaining 4 pins which are the column
pins are connected to Arduinos analog input pins A4,A3,A2,A1.The instructions that are
to be displayed are displayed on the LCD module. The LCD module has 16 pins amongst
which 12 pins are used since it is used in 4-bit mode. Starting from left the first 2 pins are
13

GROUND and VCC pins respectively. They are connected to Ground and +5V pins of
the Arduino. The next pin is the contrast pin. It is used to obtain appropriate contrast
as per the screens orientation. This pin it connected to a 10k potentiometer for contrast
adjustment purpose. The next 2 pins i.e. RS and R/W pin are connected to ground. The
RS pin stands for Register Select. If RS = 0, the instruction command code register is
selected, allowing the user to send a command such as clear display, cursor at home, etc.
If RS = 1 the data register is selected, allowing the user to send data to be displayed
on the LCD. Since we are using LCD only to give commands and diaplay user input,we
connect it to logic 1 i.e. to D7 pin of Arduino. The next pin is R/W pin .R/W input
allows the user to write information to the LCD or read information from it. .When
R/W = 1 reading mode ; R/W = 0 mode. Since we are using LCD to write data ,it is
connected to the ground. E pin i.e. the ENABLE pins is the next pin. The enable pin is
used by the LCD to latch information presented to its data pins. When data is supplied
to data pins, a high-to-low pulse must be applied to this pin in order for the LCD to
latch in the data present at the data pins. This pulse must be a minimum of 450 ns wide.
Enable pin is connected to D8 pin of arduino. The 8-bit data pins, DO D7, are used to
send information to the LCD or read the contents of the LCDs internal registers. display
letters and numbers, we send ASCII codes for the letters A Z, a z, and numbers 0 9 to
these pins while making RS = 1.We also use RS = 0 to check the busy flag bit to see if
the LCD is ready to receive information. The busy flag is D7 and can be read when R/W
= 1 and RS = 0, as follows: if R/W= 1, RS = 0. When D7 = 1 (busy flag = 1), the
LCD is busy taking care of internal operations and will not accept any new information.
When D7 = 0, the LCD is ready to receive new information. Since LCD is used in 4-bit
mode thus D0,D1,D2,D3 of LCD are not connected and D4,D5,D6,D7 are connected to
D9, D10, D11, D12 of Arduino. The last two pins are Anode and Cathode pins. Usually
Anode is connected to +5V and Cathode to Ground. Also the polarity of these pins can
be reversed. Thus the connected is connected as explained.

14

Chapter 6
Working of the circuit

Figure 6.1: Circuit Diagram.[2].

6.1

Working

On initialization a WELCOME message is displayed on the LCD screen. After this a


request to enter your passcode is made by displaying a message on LCD screen and the
Screen goes blank.User can enter a passcode ranging from 0 to 999999999 via the Keypad module. Initially a default Passcode has been set, however it changed as and when
required. If the passcode matches with the stored Passcode,Welcome User message in displayed on the screen. In case the password does not match.Incorrect Passcode is displayed
and a request to enter your passcode it put up again. Once your enter correct passcode
you are shown two options:
15

1. To Unlock by pressing A
2. To Change your Passcode by pressing C
If A is pressed then the Servo Motor Rotates 90 degrees and a request to Lock again
by PressingB is displayed. The moment your pressB the servo arm moves back to its
original position. And a request to Start again by pressing * is put up.If you press * you
are again asked to enter passcode as explained before.
If C is pressed, that means a change of Passcode is required. For this a request to
enter your current passcode is displayed on LCD. If the entered Passcode matches with
the current Passcode then a request to enter new passcode is put up. This new passcode
is confirmed and the current or the default passcode is erased from EEPROM.
EEPROM stands for Electrically Erasable and Programmable Read Only Memory. This
is the Memory of the Arduino in which the Passcode is stored. Generally, if an Arduino is
reinitialized all the variables are Reset. This means every time you switch on the Arduino
all the variables are set to 0.This means if a user has stored a passcode it will be reset in
case of power failure or disconnection. This makes absolutely no sense. Thus EEPROM
of the Arduino, is used. To use EEPROM a library function is called. By default EEPROM can store passcode only upto 255, how ever after certain in pre defined fuctions it is
possible to store passcode upto number 999999999 (9 times 9) which is a significant step
up as far as the security reasons are concerned.

6.2

Programming

For the programming purpose we have used a software named Arduino IDE.This software
is avaliable for free download on Arduinos website.
Program:
include EEPROM.h
include Keypad.h
include LiquidCrystal.h
include Servo.h
Servo myServo;
LiquidCrystal lcd(7,8,9,10,11,12);
long fpass;
long password;
long a1;
long a2;
long a3;
long a4;
char q;
long newPass;
long address=0;
const byte numRows= 4;
const byte numCols= 4;
16

char keymap[numRows][numCols]=
1, 2, 3, A,
4, 5, 6, B,
7, 8, 9, C,
*, 0, , D
;
byte rowPins[numRows] = 5,4,3,2; //Rows 0 to 3
byte colPins[numCols]= A4,A3,A2,A1; //Columns 0 to 3
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows,
numCols);

void setup()
Serial.begin(9600);
void loop() here:fpass=EEPROMReadlong(0); Serial.println(EEPROMReadlong(0));
password=fpass ; welcome(); wrong:long flag=0; askforPassword(); a1=GetPassword();
a2=compare(a1); if(a2==1) correctPassword(); else incorrectPassword(); flag=1; if(flag==1)
goto wrong; else q=getCharAfterCorrectPassword();
if(q==A) rotateServo();
else a3=checkPassOnC(); if(a3==1) a4=changePass(); lcd.clear(); lcd.setCursor(0,0);
lcd.print(Processing......); delay(1500); lcd.clear(); lcd.setCursor(0,0); lcd.print(Changing);
lcd.setCursor(0,1); lcd.print(Password......); delay(1500); lcd.clear(); lcd.setCursor(0,0);
lcd.print(Your Password); lcd.setCursor(0,1); lcd.print(has been changed); delay(1500);
lcd.clear(); lcd.setCursor(0,0); lcd.print(Initializing....); delay(1000); newPass=a4; EEPROMWritelong(address, newPass); address+=4;
goto here; else lcd.clear(); lcd.setCursor(0,0); lcd.print(Incorrect Pass); delay(1500); goto wrong;
while(1);
void welcome() lcd.begin(16,2); lcd.setCursor(0,0); lcd.print(WELCOME!!!!!!!!);
delay(2000); lcd.setCursor(0,0); lcd.print(THIS IS PASSWORD); lcd.setCursor(0,1);
lcd.print(PROTECTED LOCK); delay(2000); lcd.clear(); lcd.setCursor(0,0); lcd.print(Note:
is used); lcd.setCursor(0,1); lcd.print(as Enter key); delay(2000);
void askforPassword() lcd.clear(); lcd.setCursor(0,0); lcd.print(Enter your); lcd.setCursor(0,1)
lcd.print(numeric password); delay(2000); lcd.clear();
int GetPassword() long num = 0; char key =myKeypad.getKey(); while(key != )
switch (key) case NOK EY : break;
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case
8: case 9: num = num * 10 + (key - 0); lcd.setCursor(16,1); lcd.scrollDisplayLeft();
lcd.print(num);
break; case *: num = 0; break;
key =myKeypad.getKey(); return num; delay(10000);
long compare(long a)
int check=0; if(a==password) check=1; else check=0; return check;
void correctPassword() lcd.clear(); lcd.setCursor(0,0); lcd.print(Welcome User);
delay(2000);
void incorrectPassword() lcd.clear(); lcd.setCursor(0,0); lcd.print(Wrong Password);
lcd.setCursor(0,1); lcd.print(Please Try Again); delay(2000);
17

char getCharAfterCorrectPassword() char AorC; lcd.clear(); lcd.setCursor(0,0); lcd.print(Press


A 2 Unlock); lcd.setCursor(0,1); lcd.print(Or C 2 change PW); char key=myKeypad.getKey();
while(key != ) switch (key) case NOK EY : break;
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case
9: break;
case *: break;
caseA: caseC: AorC=key; break; caseB: caseD: break;
key =myKeypad.getKey(); return AorC;
void rotateServo()
myServo.attach(6); myServo.write(180); lcd.clear(); lcd.setCursor(0,0); lcd.print(Unlocking......
delay(1000); myServo.detach();
lcd.clear(); lcd.setCursor(0,0); lcd.print(Press B to lock); char key=myKeypad.getKey();
while(key != ) switch (key) case NOK EY : break;
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case
9: break;
case *: break;
caseA: caseC:caseD:
break; caseB:
myServo.attach(6); myServo.write(-180); lcd.clear(); lcd.setCursor(0,0); lcd.print(Locking.......
delay(2000); lcd.clear(); lcd.setCursor(0,0); lcd.print(THANK YOU); delay(1500); lcd.clear();
lcd.setCursor(0,0); lcd.print(Press RESET to); lcd.setCursor(0,1); lcd.print(initialize);
delay(500);
break;
key =myKeypad.getKey();
long checkPassOnC() lcd.clear(); lcd.setCursor(0,0); lcd.print(Enter Current);
lcd.setCursor(0,1); lcd.print(Password); delay(1500); lcd.clear(); long num=0; long
check=0; char key =myKeypad.getKey(); while(key != ) switch (key) case NOK EY :
break;
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case
8: case 9: num = num * 10 + (key - 0); lcd.setCursor(16,1); lcd.scrollDisplayLeft();
lcd.print(num);
break; case *: num = 0; break;
key =myKeypad.getKey();
if(num==password) check=1; else check=0; return check;
long changePass() lcd.clear(); lcd.setCursor(0,0); lcd.print(Enter New); lcd.setCursor(0,1);
lcd.print(Password); delay(1500); lcd.clear(); long num = 0; char key =myKeypad.getKey();
while(key != ) switch (key) case NOK EY : break;
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7: case
8: case 9: num = num * 10 + (key - 0); lcd.setCursor(16,1); lcd.scrollDisplayLeft();
lcd.print(num);
break; case *: num = 0; break;
key =myKeypad.getKey(); return num;
void EEPROMWritelong(int address, long value) byte four = (value 0xFF); byte
three = ((value 8) 0xFF); byte two = ((value 16) 0xFF); byte one = ((value
24) 0xFF); EEPROM.write(address, four); EEPROM.write(address + 1, three); EEPROM.write(address + 2, two); EEPROM.write(address + 3, one);
long EEPROMReadlong(long address) long four = EEPROM.read(address); long
three = EEPROM.read(address + 1); long two = EEPROM.read(address + 2); long one
18

= EEPROM.read(address + 3); return ((four 0) 0xFF) + ((three 8) 0xFFFF) +


((two 16) 0xFFFFFF) + ((one 24) 0xFFFFFFFF);

19

Chapter 7
Conclusion and Future Scope
7.1

Conclusion

In this project we have studied and successfully implemented a Digital code lock system
using arduino as Micro controller. The programming and interfacing of micro controller
has been mastered during the implementation.Also,an exemplary knowledge of core electronics was obtained.

7.2

Future Scope

With the advent of fullproof electronic locking systems, the future is in favour of technology. As has been witnessed in other areas, analog/mechanical devices are being taken
over by digital/electronic devices. The increase in number of open-source and affordable
microcontrollers such as Arduino, has been a boon as it has made the designing and
implementation of complex systems and projects much simpler for beginners. More powerful, real-time and faster microcontrollers and microprocessors are paving the way for
a bright future in the field of electronic security systems. With security protocols such
as fingerprint scanners, retina scanners and other biometric scanners, electronic security
systems are leagues ahead of traditional locking systems and the innovation in this area
doesnt seem to stop.

20

Bibliography
[1] https://www.arduino.cc/en/Guide/HomePage
[2] https://www.arduino.cc/en/Tutorial/HomePage
[3] http://playground.arduino.cc/
[4] https://forum.arduino.cc/
[5] https://circuits.io/lab/
[6] https://en.wikipedia.org/wiki/Microcontroller
[7] https://www.futureelectronics.com/en/Microcontrollers/microcontrollers.aspx
[8] Demystifying the Microchip PIC Microcontroller for Engineering Students by Charley
Bechara,Lulu Press, Inc
[9] PID Control: New Identification and Design Methods by Michael A Johnson,Muhammad Ali Mazadi
Published by Springer/Star Educational Books Distributor Pvt. Ltd (2008)

21

You might also like