Magnetic door lock

15
Magnetic Door Lock employing Arduino Technology

Transcript of Magnetic door lock

Page 1: Magnetic door lock

Magnetic Door Lock employing Arduino Technology

Page 2: Magnetic door lock

Abstract

The Magnetic Door lock is a simple locking device that consists of a magnetic lock and armature plate with no moving parts and it purely works due to the magnetic field. Therefore the magnetic lock is truly fail-safe (Power to lock). Thus, the magnetic lock is met with both security and fire safety requirements

and is available for emergency exit doors. While the magnetic door lock might be quite a simplistic locking device, but the efficiency of the locking gadget can certainly not be denied. The purpose of this

paper is to design Magnetic Door Lock employing Arduino Technology. Magnetic lock or mag lock uses an electrical current to produce a magnetic force. When a current is passed through the coil, the magnet

lock becomes magnetized. The door will be securely bonded when the electromagnet is energized holding against the armature plate. Access control systems are operated by peripheral device (ie. keypad reader here ) to identify the user whether access is permitted or not. The power will be

automatically turned off by the user and gains access through a reader. The objective of the work undertaken in this paper is to sense the correctness of a secret code using the Arduino technology.

Page 3: Magnetic door lock

I.INTRODUCTION

THIS section gives a brief introduction about the work, which describes all the components namely Magnetic Door Lock, Arudino platform, Atmeg168. Followed by design of Magnetic Door Lock by Arudino Technology. Door locks are certainly considered to be the basic modes of the everyday household door and keeping this fact in mind, door locks hold an immense importance for the protection of doors. While the magnetic door lock might be quite a simplistic locking device, but the efficiency of the locking gadget can certainly not be denied. Magnetic Door Lock employing Arduino Technology. The main aim of the work undertaken in this paper is to sense the correctness of a secret code using the Arduino technology. When the correct code is entered through keypad, it lights a green LED in addition to operating a small solenoid which when powered, will strongly attract the metal slug in its center, pulling it into place, when the power is removed, it is free to move. Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. Arduino can sense the environment by receiving input from a variety of sensors and can affect its surroundings by controlling lights, motors, and other actuators. The microcontroller on the board is programmed using the Arduino programming language (based on Wiring) and the Arduino development environment (based on Processing). Arduino projects can be stand-alone or they can communicate with software running on a computer (e.g. Flash, Processing, MaxMSP). Arduino is a small microcontroller board with a USB plug to connect to your computer and a number of connection sockets that can be wired up to external electronics, such as motors, relays, light sensors, laser diodes, loudspeakers, microphones, etc. They can either be powered through the USB connection from the computer or from a 9V battery. They can be controlled from the computer or programmed by the computer and then disconnected and allowed to work independently. Since the Arduino is an open-source hardware design,anyone is free to take the designs and create their own clones of the Arduino and sell them, so the market for the boards is competitive.

II.DESCRIPTION ABOUT THE MICROCONTROLLER This section gives a brief idea about the ATMEGA168 microcontroller its core features, block diagram, pin diagram and its description. A. INTRODUCTION Circumstances that we find ourselves today in the field of microcontrollers had their beginnings in the development of technology of integrated circuits. This development had made it possible to store hundreds of thousands of transistors into one chip. That was a prerequisite for production of microcontrollers, and adding external peripherals such as memory, input-output lines, timers and other made the first computers. Further increasing of the volume of the package resulted in creation of integrated circuits. These integrated circuits contained both processor and peripherals. That is how the first chip containing a microcomputer, or what would later be known as a microcontroller came out .

B. MICROCONTROLLER VERSUS MICROPROCESSORS Microcontroller differs from a microprocessor in many ways. First and the most important is its functionality. In order for a microprocessor to be used, other components such as memory, or components for receiving and sending data must be added to it. In sort that means that microprocessor is the very heart of the computer. On the other and , microcontroller is designed to be all of that in one. No other external components are needed for its application because all necessary peripherals are already built in to it. Thus, we save the time and space needed to construct devices. C. ATMEL ATMEGA168 MICROCONTROLLER Overview:ATmega168 is widely used because it supports wide range of system development tools such as C Compliers, Macro assemblers, Program Debugger/Simulators, In-circuit Emulators and Evaluation Kits . Its features includes: 23 general purpose I/O lines, 32 general purpose working registers, three flexible timer/counters with compare/capture/PWM mode, a SPI serial port, 16K bytes of in-system programmable Flash with Read-while-Write capabilities. 512 bytes of EEPROM and 1K bytes SRAM. In Idle mode

Page 4: Magnetic door lock

CPU stops working while allowing the SRAM, timers/counters, USART, SPI port and interrupt system to continue functioning. It also has 6

channel 10-bit ADC, a programmable watchdog timer with internal oscillator .

Description: The device is manufactured using Atmel’s high-density non-volatile memory technology.“The on-chip ISP flash allows the program memory to be reprogrammed in-system

through an SPI serial interface, by a conventional non-volatile memory programmer, or by an on chip boot program running the AVR core”.

PIN Description: VCC

Digital supply voltage. GND

Ground voltage for the microcontroller chip. PORT B (PB7:0)

Port B is an 8-bit bi-directional I/O Port with internal pull-up resistors. As Inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated .

Depending on the clock selection fuse settings, PB6 can be used as input to the inverting oscillator amplifier and input to the internal clock operating circuit Depending on the clock selection fuse settings, PB7 can be used as output from inverting oscillating amplifier PORT C (PC5:0)

Port C is a 7-bit bi-directional I/O port with internal pull-up resistors. As inputs, Port C pins that are externally pulled low will source current if the pull-up resistors are activated PC6/RESET If the RSTDISBL register is programmed, PC6 is used as I/O pin. Behavior of PC6 is different from other Port C pins. If RSTDISBL is not programmed, PC6 can be used as a Reset input. A low level on this pin for longer than the minimum pulse length will generate a reset even without the clock signal. Shorter pulses are not guaranteed to generate a Reset PORT D (PD7:0)

Port D is an 8-bit bi-directional I/O port with internal pull-up resistors. As inputs, Port C pins that are externally pulled low will source current if the pull-up resistors are activated. The Port D pins become tri-stated if the reset condition become active, even if the clock is running . AVCC

AVCC is the supply pin for the A/D Convertor, PC[5:0]. It should be externally connected to VCC, even if the ADC is not used. If the ADC is used it should be connected to VCC through low pass filter AREF

AREF is an analog reference pin for the A/D convertor. XTAL1It is an input to the inverting oscillator amplifier and the internal clock circuit [2]. XTAL2It is an output pin from the inverting oscillator amplifier.

Page 5: Magnetic door lock

Oscillator Characteristics: As shown in Figure , XTAL1 is input and XTAL2 is output of an inverting amplifier that can be configured for use as an on-chip oscillator. To use external oscillator as clock source, XTAL2 should be left unconnected while XTAL1 is driven. Quartz crystal or ceramic resonator can be used as oscillator.

Block Diagram Figure below shows the block diagram of the ATMEL ATmega168 microcontroller. The AVR core has 32 general-purpose registers. All these registers are directly connected to the Arithmetic Logic Unit (ALU), allowing two independent registers to be accessed in 20 one single instruction executed in one clock cycle. The resulting architecture is code efficient. The device is manufactured using Atmel’s high-density non-volatile memory technology.

ATmega168 CCP Modules Each CCP (Capture/Compare/PWM) module contains a 16-bit register which can be operate as 16-bit capture register, as a 16-bit compare register or as a 16-bit PWM master/slave duty cycle register. The CCP modules are identical in operation, with the exception of the operation of the special event trigger .Most registers and bit references for this IC are written in general form. For example, a lower case “n” replaces the Timer/Counter number, and a lower case “x” replaces the output compare unit channel. When these registers or bits are defined in a program, they are declared as TCNT2 for accessing Timer/Counter2 counter value and so on. Figure below shows a block diagram for the 16-bit Timer/Counter

Page 6: Magnetic door lock

Registers

• TCCR1A – Timer/Counter1 Control Register A

Bit [7:6] – COM1A1:0 Compare Output Mode for Channel A Bit [5:4] - COM1B1:0 Compare Output Mode for Channel B • TCCR1B – Timer/Counter1 Control Register A

Bit [0:2] – CS[10:12] Clock Select Bits Bit [4:3] – WGM[13:12] Waveform Generation Mode These bits are used in conjunction with TCCR1A Control Register bits WGM[11:10] to set the timer/counter mode as 8-bit Fast PWM.

Arduino

Introduction

• Arduino is a tool for making computers

that can sense and control more of the

physical world than your desktop

computer.

• It's an open-source physical computing

platform based on a simple microcontroller

board, and a development environment for

writing software for the board.

• Arduino can be used to develop interactive

objects, taking inputs from a variety of

switches or sensors, and controlling a

variety of lights, motors, and other

physical outputs.

• Arduino projects can be stand-alone, or

they can be communicate with software

running on your computer (e.g. Flash,

Processing, MaxMSP.)

• The Arduino programming language is an

implementation of Wiring, a similar

physical computing platform, which is

based on the Processing multimedia

programming environment.

Advantages

• There are many other microcontrollers and

microcontroller platforms available for

physical computing. Parallax Basic Stamp,

Netmedia's BX-24, Phidgets, MIT's

Handyboard, and many others offer similar

functionality.

• Inexpensive - Arduino boards are

relatively inexpensive compared to other

microcontroller platforms.

• Cross-platform - The Arduino software

runs on Windows, Macintosh OSX, and

Linux operating systems.

• Simple, clear programming environment -

The Arduino programming environment is

easy-to-use for beginners, yet flexible

enough for advanced users to take

advantage of as well.

• Open source and extensible software- The

Arduino software is published as open

source tools, available for extension by

experienced programmers.

• The language can be expanded through

C++ libraries, and people wanting to

understand the technical details can make

the leap from Arduino to the AVR C

programming language on which it's

based.

Page 7: Magnetic door lock

Introduction to Arduino Duemilanove

Overview The Arduino Duemilanove ("2009") is a microcontroller board based on the ATmega168 or ATmega328. 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.

Summary

Microcontroller ATmega168

Operating Voltage 5V

Input Voltage (recommended)

7-12V

Input Voltage (limits) 6-20V

Digital I/O Pins 14 (of which 6 provide PWM output)

Analog Input Pins 6

DC Current per I/O Pin

40 mA

DC Current for 3.3V Pin

50 mA

Flash Memory

16 KB (ATmega168) or 32 KB (ATmega328) of which 2 KB used by bootloader

SRAM 1 KB (ATmega168) or 2 KB (ATmega328)

EEPROM 512 bytes (ATmega168) or 1 KB (ATmega328)

Clock Speed 16 MHz

Power The Arduino Duemilanove can be powered via the USB connection or with an external power supply. The power source is selected automatically. External (non-USB) power can come either from an AC-to-DC adapter (wall-wart) or battery. The adapter can be connected by plugging a 2.1mm center-positive plug into the board's power jack. Leads from a battery can be inserted in the Gnd and Vin pin headers of the POWER connector. The board can operate on an external supply of 6 to 20 volts. If supplied with less than 7V, however, the 5V pin may supply less than five volts and the board may be unstable. If using more than 12V, the voltage regulator may overheat and damage the board. The recommended range is 7 to 12 volts. The power pins are as follows: VIN. The input voltage to the Arduino 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. The regulated power supply used to power the microcontroller and other components on the board. This can come either from VIN via an on-board regulator, or be supplied by USB or another regulated 5V supply. 3V3. A 3.3 volt supply generated by the on-board FTDI chip. Maximum current draw is 50 mA. GND. Ground pins. Memory The ATmega168 has 16 KB of flash memory for storing code (of which 2 KB is used for the bootloader); the ATmega328has 32 KB, (also with 2 KB used for the bootloader). The ATmega168 has 1 KB of SRAM and 512 bytes of EEPROM (which can be read and written with the EEPROM library. the ATmega328 has 2 KB of SRAM and 1 KB of EEPROM.

Page 8: Magnetic door lock

Input and Output Each of the 14 digital pins on the Duemilanove can be used as an input or output, using pinMode(), digitalWrite(), anddigitalRead() functions. They operate at 5 volts. Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms. In addition, some pins have specialized functions: Serial: 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 FTDI USB-to-TTL Serial chip. External Interrupts: 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. See the attachInterrupt() function for details. PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function. SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication using the SPI library. LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's off. The Duemilanove has 6 analog inputs, 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. Additionally, some pins have specialized functionality: I2C: analog input pins A4 (SDA) and A5 (SCL). Support I2C (TWI) communication using the Wire library. There are a couple of other pins on the board: AREF. Reference voltage for the analog inputs. Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to shields which block the one on the board.

The mapping between Arduino pins and ATmega168 ports

Communication The Arduino Duemilanove has a number of facilities for communicating with a computer, another Arduino, or other microcontrollers. The ATmega168 and ATmega328 provide UART TTL (5V) serial communication, which is available on digital pins 0 (RX) and 1 (TX). An FTDI FT232RL on the board channels this serial communication over USB and the FTDI drivers (included with Windows version of the Arduino software) provide a virtual com port to software on the computer. The Arduino software includes a serial monitor which allows simple textual data to be sent to and from the Arduino board. The RX and TX LEDs on the board will flash when data is being transmitted via the FTDI chip and USB connection to the computer (but not for serial communication on pins 0 and 1).A SoftwareSerial library allows for serial communication on any of the Duemilanove's digital pins. The ATmega168 and ATmega328 also support I2C (TWI) and SPI communication. The Arduino software includes a Wire library to simplify use of the I2C bus.

Page 9: Magnetic door lock

Programming The Arduino Duemilanove can be programmed with the Arduino software. The ATmega168 or ATmega328 on the Arduino Duemilanove comes preburned with a bootloader that allows you to upload new code to it without the use of an external hardware programmer. It communicates using the original STK500protocol (reference, C header files).You can also bypass the bootloader and program the microcontroller through the ICSP (In-Circuit Serial Programming) header.

Automatic (Software) Reset Rather then requiring a physical press of the reset button before an upload, the Arduino Duemilanove 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 FT232RL is connected to the reset line of the ATmega168 or ATmega328 via a 100 nanofarad capacitor. When this line is asserted (taken low), the reset line drops long enough to reset the chip. The Arduino software uses this capability to allow you to upload code by simply pressing the upload button in the Arduino environment. This means that the bootloader can have a shorter timeout, as the lowering of DTR can be well-coordinated with the start of the upload. This setup has other implications. When the Duemilanove is connected to either 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 Duemilanove. 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. If a sketch running on the board receives one-time configuration or other data when it first starts, make sure that the software with which it communicates waits a second after opening the connection and before sending this data. The Duemilanove contains a trace that can be cut to disable the auto-reset. The pads on either side of the trace can be soldered together to re-enable it. It's labeled "RESET-EN". You may also be able to disable the auto-reset by connecting a 110 ohm resistor from 5V to the reset line; see this forum thread for details.

USB Overcurrent Protection The Arduino Duemilanove has a resettable polyfuse that protects your computer's USB ports from shorts and overcurrent. Although most computers provide their own internal protection, the fuse provides an extra layer of protection. If more than 500 mA is applied to the USB port, the fuse will automatically break the connection until the short or overload is removed. Physical Characteristics The maximum length and width of the Duemilanove PCB are 2.7 and 2.1 inches respectively, with the USB connector and power jack extending beyond the former dimension. Three screw holes allow the board to be attached to a surface or case. Note that the distance between digital pins 7 and 8 is 160 mil (0.16"), not an even multiple of the 100 mil spacing of the other pins.

Page 10: Magnetic door lock

Schematic Design

Page 11: Magnetic door lock

Arduino Varieties:

Arduino shields: Add-on module to extend arduino’s capabilities. Also called Daughterboard or Cape

Communication Shields

Sensors

Applications

Page 12: Magnetic door lock

Design and Development of Magnetic Door Lock The main aim of the work undertaken in this paper is to sense the correctness of a secret code using the Arduino technology. When the correct code is entered through keypad, it lights a green LED in addition to operating a small solenoid which when powered, will strongly attract the metal slug in its center, pulling it into place, when the power is removed, it is free to move. The secret code is stored in EEPROM, so if the power is disconnected, the code will not be lost. When powered, the solenoid will strongly attract the metal slug in its center, pulling it into place. When the power is removed, it is free to move.

COMPONENTS AND EQUIPMENT Arduino Diecimila or Duemilanove board or clone D1 Red 5-mm LED D2 Green 5-mm LED R1-3 270 _ 0.5W metal film resistor K1 4 x 3 keypad 0.1-inch header strip T1 BC548 5V solenoid (< 100 mA) D3 1N4004

Keypads are normally arranged in a grid so that when one of the keys is pressed, it connects a row to a column. Figure beside shows a typical arrangement for a 12-key keyboard with numbers from 0 to 9 and * and # keys. The key switches are arranged at the intersection of row-and-column wires. When a key is pressed, it connects a particular row to a particular column. By arranging the keys in a grid like this, it means that we only need to use 7 (4 rows + 3columns) of our digital pins rather than 12 (one for each key).

Page 13: Magnetic door lock

Figure beside shows how you can solder seven pins from a pin header strip onto the keypad so that you can then connect it to the breadboard. Pin headers are bought in strips and can be easily snapped to provide the number of pins required.

The solenoid is an inductive load and therefore liable to generate a back EMF, which diode D3 protects against. The solenoid is controlled by T1, so be careful to select a solenoid that will not draw more than 100 mA, which is the maximum collector current of the transistor. We are using a very low power solenoid, and this would not keep intruders out. If you are using a more substantial solenoid, a BD139 transistor would be better. If the solenoid can be mounted on the breadboard, this is all well and good. If not, you will need to attach leads to it that connect it to the breadboard.

Hardware The schematic diagram

Page 14: Magnetic door lock

Software : The software for this project

#include <Keypad.h> #include <EEPROM.h> char* secretCode = "1234"; int position = 0; boolean locked = true; const byte rows = 4; const byte cols = 3; char keys[rows][cols] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'*','0','#'}}; byte rowPins[rows] = {2, 7, 6, 4}; byte colPins[cols] = {3, 1, 5}; Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols); int redPin = 9; int greenPin = 8; int solenoidPin = 10; void setup() { pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); loadCode(); flash(); updateOutputs(); } void loop() { char key = keypad.getKey(); if (key == '*' && ! locked) { // unlocked and * pressed so change code position = 0; getNewCode(); updateOutputs(); } if (key == '#') { locked = true; position = 0; updateOutputs(); } if (key == secretCode[position]) { position ++; } if (position == 4) {

locked = false; updateOutputs(); } delay(100); } void updateOutputs() { if (locked) { digitalWrite(redPin, HIGH); digitalWrite(greenPin, LOW); digitalWrite(solenoidPin, HIGH); } else { digitalWrite(redPin, LOW); digitalWrite(greenPin, HIGH); digitalWrite(solenoidPin, LOW); } } void getNewCode() { flash(); for (int i = 0; i < 4; i++ ) { char key; key = keypad.getKey(); while (key == 0) { key = keypad.getKey(); } flash(); secretCode[i] = key; } saveCode(); flash(); flash(); } void loadCode() { if (EEPROM.read(0) == 1) { secretCode[0] = EEPROM.read(1); secretCode[1] = EEPROM.read(2); secretCode[2] = EEPROM.read(3); secretCode[3] = EEPROM.read(4); } }

Page 15: Magnetic door lock

void saveCode() { EEPROM.write(1, secretCode[0]); EEPROM.write(2, secretCode[1]);

EEPROM.write(3, secretCode[2]); EEPROM.write(4, secretCode[3]); EEPROM.write(0, 1); }

void flash() { digitalWrite(redPin, HIGH); digitalWrite(greenPin, HIGH);

delay(500); digitalWrite(redPin, LOW);

digitalWrite(greenPin, LOW); } Since each character is exactly one byte in length, the code can be stored directly in the EEPROM memory. We use the first byte of EEPROM to indicate if the code has been set. If it has not been set, the code will default to 1234. Once the code has been set, the first EEPROM byte will be given a value of 1.

Putting It All Together Load the completed sketch and download it to the board . We can make sure everything is working by powering up our project and entering the code 1234, at which point, the green LED should light and the solenoid release. We can then change the code to something a little less guessable by pressing the * key and then entering four digits for the new code. The lock will stay unlocked until we press the # key. If you forget your secret code, unfortunately, turning the power to the project on

and off will not reset it to 1234. Instead, you will have to comment out the line: loadCode(); in the setup function, so that it appears as shown here: // loadCode();

Conclusion and future scope: A Magnetic Door Lock employing Arduino technology is presented. We have implemented a failsafe maglock, fail secure maglock also can be implemented. Instead of keypad Reader using the variety of sensors and shields various combinations of Magnetic Door Lock can be produced and installed according to the requirements of any Industry.

References: • http://arduino.cc/ • ITP Physical Computing • http://www.ladyada.net • http://www.sparkfun.com • http://seeedstudio.com • http://coopermaa2nd.blogspot.com

By, Sravanthi Rani Sinha S 09BD1A04A0