Magnetic door lock


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Magnetic door lock

  1. 1. Magnetic Door Lock employing Arduino Technology
  2. 2. Abstract The Magnetic Door lock is a simple locking device that consists of a magnetic lock and armature platewith no moving parts and it purely works due to the magnetic field. Therefore the magnetic lock is trulyfail-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 thispaper is to design Magnetic Door Lock employing Arduino Technology. Magnetic lock or mag lock usesan 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.
  3. 3. I.INTRODUCTION II.DESCRIPTION ABOUT THETHIS section gives a brief introduction about the work, MICROCONTROLLERwhich describes all the components namely Magnetic This section gives a brief idea about theDoor Lock, Arudino platform, Atmeg168. Followed bydesign of Magnetic Door Lock by Arudino ATMEGA168 microcontroller its core features,Technology. block diagram, pin diagram and its description.Door locks are certainly considered to be the basic A. INTRODUCTIONmodes of the everyday household door and Circumstances that we find ourselves today in thekeeping this fact in mind, door locks hold an field of microcontrollers had their beginnings inimmense importance for the protection of doors. the development of technology of integratedWhile the magnetic door lock might be quite a circuits. This development had made it possible tosimplistic locking device, but the efficiency of the store hundreds of thousands of transistors into onelocking gadget can certainly not be denied. chip. That was a prerequisite for production ofMagnetic Door Lock employing Arduino microcontrollers, and adding external peripheralsTechnology. The main aim of the work such as memory, input-output lines, timers andundertaken in this paper is to sense the correctness other made the first computers. Further increasingof a secret code using the Arduino technology. of the volume of the package resulted in creationWhen the correct code is entered through keypad, of integrated circuits. These integrated circuitsit lights a green LED in addition to operating a contained both processor and peripherals. That issmall solenoid which when powered, will strongly how the first chip containing a microcomputer, orattract the metal slug in its center, pulling it into what would later be known as a microcontrollerplace, when the power is removed, it is free to came out .move. B. MICROCONTROLLER VERSUSArduino is an open-source electronics prototyping MICROPROCESSORSplatform based on flexible, easy-to-use hardware Microcontroller differs from a microprocessor in manyand software. Arduino can sense the environment ways. First and the most important is itsby receiving input from a variety of sensors and functionality. In order for a microprocessor to becan affect its surroundings by controlling lights, used, other components such as memory, ormotors, and other actuators. The microcontroller components for receiving and sending data muston the board is programmed using the Arduino be added to it. In sort that means thatprogramming language (based on Wiring) and the microprocessor is the very heart of the computer.Arduino development environment (based On the other and , microcontroller is designed toon Processing). Arduino projects can be stand- be all of that in one. No other externalalone or they can communicate with software components are needed for its application becauserunning on a computer (e.g. Flash, all necessary peripherals are already built in to it.Processing, MaxMSP). Thus, we save the time and space needed toArduino is a small microcontroller board with a construct devices.USB plug to connect to your computer and anumber of connection sockets that can be wired C. ATMEL ATMEGA168up to external electronics, such as motors, relays, MICROCONTROLLERlight sensors, laser diodes, loudspeakers, Overview:ATmega168 is widely used because itmicrophones, etc. They can either be powered supports wide range of system development toolsthrough the USB connection from the computer or such as C Compliers, Macro assemblers, Programfrom a 9V battery. They can be controlled from Debugger/Simulators, In-circuit Emulators andthe computer or programmed by the computer and Evaluation Kits . Its features includes: 23 generalthen disconnected and allowed to work purpose I/O lines, 32 general purpose workingindependently. Since the Arduino is an open- registers, three flexible timer/counters withsource hardware design,anyone is free to take the compare/capture/PWM mode, a SPI serial port,designs and create their own clones of the 16K bytes of in-system programmable Flash withArduino and sell them, so the market for the Read-while-Write capabilities. 512 bytes ofboards is competitive. EEPROM and 1K bytes SRAM. In Idle mode
  4. 4. CPU stops working while allowing the SRAM, channel 10-bit ADC, a programmable watchdogtimers/counters, USART, SPI port and interrupt timer with internal oscillator .system to continue functioning. It also has 6Description: The device is manufactured using through an SPI serial interface, by a conventionalAtmel’s high-density non-volatile memory non-volatile memory programmer, or by an ontechnology.“The on-chip ISP flash allows the chip boot program running the AVR core”.program memory to be reprogrammed in-system 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 .PIN Description: AVCC AVCC is the supply pin for the A/DVCC Convertor, PC[5:0]. It should be externally Digital supply voltage. connected to VCC, even if the ADC is not used. IfGND the ADC is used it should be connected to VCC Ground voltage for the microcontroller through low pass filterchip. AREF PORT B (PB7:0) AREF is an analog reference pin for the Port B is an 8-bit bi-directional I/O Port A/D convertor. XTAL1It is an input to thewith internal pull-up resistors. As Inputs, Port B inverting oscillator amplifier and the internalpins that are externally pulled low will source clock circuit [2]. XTAL2It is an output pin fromcurrent if the pull-up resistors are activated . the inverting oscillator amplifier.
  5. 5. Oscillator Characteristics: As shown in Figure , XTAL1 is input andXTAL2 is output of an inverting amplifier thatcan be configured for use as an on-chip oscillator.To use external oscillator as clock source, XTAL2should be left unconnected while XTAL1 isdriven.Quartz crystal or ceramic resonator can be used asoscillator.Block Diagram ATmega168 CCP ModulesFigure below shows the block diagram of the Each CCP (Capture/Compare/PWM) moduleATMEL ATmega168 microcontroller. The AVR contains a 16-bit register which can be operate ascore has 32 general-purpose registers. All these 16-bit capture register, as a 16-bit compareregisters are directly connected to the Arithmetic register or as a 16-bit PWM master/slave dutyLogic Unit (ALU), allowing two independent cycle register. The CCP modules are identical inregisters to be accessed in 20 one single operation, with the exception of the operation ofinstruction executed in one clock cycle. The the special event trigger .Most registers and bitresulting architecture is code efficient. The device references for this IC are written in general manufactured using Atmel’s high-density non- For example, a lower case “n” replaces thevolatile memory technology. 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
  6. 6. • Arduino can be used to develop interactive objects, taking inputs from a variety ofRegisters switches or sensors, and controlling a • TCCR1A – Timer/Counter1 Control Register variety of lights, motors, and other A 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 similarBit [7:6] – COM1A1:0 Compare Output Mode for physical computing platform, which isChannel A based on the Processing multimediaBit [5:4] - COM1B1:0 Compare Output Mode for programming environment.Channel B Advantages• TCCR1B – Timer/Counter1 Control Register A • 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. • Inexpensive - Arduino boards are relatively inexpensive compared to otherBit [0:2] – CS[10:12] Clock Select Bits microcontroller platforms.Bit [4:3] – WGM[13:12] Waveform Generation • Cross-platform - The Arduino softwareModeThese bits are used in conjunction with TCCR1A runs on Windows, Macintosh OSX, andControl Register bits Linux operating systems.WGM[11:10] to set the timer/counter mode as 8- • Simple, clear programming environment -bit Fast PWM. The Arduino programming environment is easy-to-use for beginners, yet flexible Arduino enough for advanced users to take advantage of as well.Introduction • Open source and extensible software- The • Arduino is a tool for making computers Arduino software is published as open that can sense and control more of the source tools, available for extension by physical world than your desktop experienced programmers. computer. • The language can be expanded through • Its an open-source physical computing C++ libraries, and people wanting to platform based on a simple microcontroller understand the technical details can make board, and a development environment for the leap from Arduino to the AVR C writing software for the board. programming language on which its based.
  7. 7. Introduction to Arduino Duemilanove 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 boards 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 toOverview 12 volts.The Arduino Duemilanove ("2009") is amicrocontroller board based on the ATmega168 The power pins are as follows:or ATmega328. It has 14 digital input/output pins (of VIN. The input voltage to the Arduino boardwhich 6 can be used as PWM outputs), 6 analog when its using an external power source (asinputs, a 16 MHz crystal oscillator, a USB connection, opposed to 5 volts from the USB connection ora power jack, an ICSP header, and a reset button. It other regulated power source). You can supplycontains everything needed to support the voltage through this pin, or, if supplying voltagemicrocontroller; simply connect it to a computer with a via the power jack, access it through this pin.USB cable or power it with a AC-to-DC adapter or 5V. The regulated power supply used to power thebattery to get started. microcontroller and other components on the board. This can come either from VIN via an on-Summary board regulator, or be supplied by USB or anotherMicrocontroller ATmega168 regulated 5V supply.Operating Voltage 5V 3V3. A 3.3 volt supply generated by the on-boardInput Voltage FTDI chip. Maximum current draw is 50 mA. 7-12V GND. Ground pins.(recommended)Input Voltage (limits) 6-20V 14 (of which 6 provide MemoryDigital I/O Pins PWM output) The ATmega168 has 16 KB of flash memory forAnalog Input Pins 6 storing code (of which 2 KB is used for theDC Current per I/O bootloader); the ATmega328has 32 KB, (also with 40 mAPin 2 KB used for the bootloader).DC Current for 3.3V The ATmega168 has 1 KB of SRAM and 512 50 mA bytes of EEPROM (which can be read and writtenPin 16 KB (ATmega168) or with the EEPROM library. the ATmega328 has 2 32 KB (ATmega328) of KB of SRAM and 1 KB of EEPROM.Flash Memory which 2 KB used by bootloader 1 KB (ATmega168) or 2SRAM KB (ATmega328) 512 bytes (ATmega168)EEPROM or 1 KB (ATmega328)Clock Speed 16 MHz
  8. 8. Input and OutputEach of the 14 digital pins on the Duemilanove can be The mapping between Arduino pins andused as an input or output, ATmega168 portsusing pinMode(), digitalWrite(),anddigitalRead() functions. They operate at 5volts. Each pin can provide or receive a maximumof 40 mA and has an internal pull-up resistor(disconnected by default) of 20-50 kOhms. Inaddition, some pins have specialized functions:Serial: 0 (RX) and 1 (TX). Used to receive (RX)and transmit (TX) TTL serial data. These pins areconnected to the corresponding pins of the FTDIUSB-to-TTL Serial chip.External Interrupts: 2 and 3. These pins can beconfigured to trigger an interrupt on a low value, arising or falling edge, or a change in value. Seethe attachInterrupt() function for details.PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWMoutput with the analogWrite() function.SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13(SCK). These pins support SPI communicationusing the SPI library. CommunicationLED: 13. There is a built-in LED connected todigital pin 13. When the pin is HIGH value, the The Arduino Duemilanove has a number ofLED is on, when the pin is LOW, its off. facilities for communicating with a computer,The Duemilanove has 6 analog inputs, each of another Arduino, or other microcontrollers.which provide 10 bits of resolution (i.e. 1024 The ATmega168 and ATmega328 provide UARTdifferent values). By default they measure from TTL (5V) serial communication, which isground to 5 volts, though is it possible to change available on digital pins 0 (RX) and 1 (TX). Anthe upper end of their range using the AREF pin FTDI FT232RL on the board channels this serialand the analogReference() function. communication over USB and the FTDI Additionally, some pins have specialized drivers (included with Windows version of thefunctionality: Arduino software) provide a virtual com port toI2C: analog input pins A4 (SDA) and A5 software on the computer.(SCL). Support I2C (TWI) communication using The Arduino software includes a serial monitorthe Wire library. which allows simple textual data to be sent to and from the Arduino board. The RX andThere are a couple of other pins on the board: TX LEDs on the board will flash when data is being transmitted via the FTDI chip and USBAREF. Reference voltage for the analog inputs. connection to the computer (but not for serial communication on pins 0 and 1).A SoftwareSerialReset. Bring this line LOW to reset the library allows for serial communication on any ofmicrocontroller. Typically used to add a reset the Duemilanoves digital pins.button to shields which block the one on the The ATmega168 and ATmega328 alsoboard. support I2C (TWI) and SPI communication. The Arduino software includes a Wire library to simplify use of the I2C bus.
  9. 9. Programming USB Overcurrent ProtectionThe Arduino Duemilanove can be programmed The Arduino Duemilanove has a resettablewith the Arduino software. polyfuse that protects your computers USB portsThe ATmega168 or ATmega328 on the Arduino from shorts and overcurrent. Although mostDuemilanove comes preburned with computers provide their own internal protection,a bootloader that allows you to upload new code the fuse provides an extra layer of protection. Ifto it without the use of an external hardware more than 500 mA is applied to the USB port, theprogrammer. It communicates using the fuse will automatically break the connection untiloriginal STK500protocol (reference, C header the short or overload is removed.files).You can also bypass the bootloader andprogram the microcontroller through the ICSP (In- Physical CharacteristicsCircuit Serial Programming) header. The maximum length and width of theAutomatic (Software) Reset Duemilanove PCB are 2.7 and 2.1 inches respectively, with the USB connector and powerRather then requiring a physical press of the reset jack extending beyond the former dimension.button before an upload, the Arduino Three screw holes allow the board to be attachedDuemilanove is designed in a way that allows it to to a surface or case. Note that the distancebe reset by software running on a connected between digital pins 7 and 8 is 160 mil (0.16"),computer. One of the hardware flow control lines not an even multiple of the 100 mil spacing of the(DTR) of the FT232RL is connected to the reset other pins.line of the ATmega168 or ATmega328 via a 100nanofarad capacitor. When this line is asserted(taken low), the reset line drops long enough toreset the chip. The Arduino software uses thiscapability to allow you to upload code by simplypressing the upload button in the Arduinoenvironment. This means that the bootloader canhave a shorter timeout, as the lowering of DTRcan be well-coordinated with the start of theupload. This setup has other implications. Whenthe Duemilanove is connected to either acomputer running Mac OS X or Linux, it resetseach 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), itwill intercept the first few bytes of data sent to theboard after a connection is opened. If a sketchrunning on the board receives one-timeconfiguration or other data when it first starts,make sure that the software with which itcommunicates waits a second after opening theconnection and before sending this data.The Duemilanove contains a trace that can be cutto disable the auto-reset. The pads on either sideof the trace can be soldered together to re-enableit. Its labeled "RESET-EN". You may also beable to disable the auto-reset by connecting a 110ohm resistor from 5V to the reset line; see thisforum thread for details.
  10. 10. Schematic Design
  11. 11. Arduino Varieties: ApplicationsArduino shields:Add-on module to extend arduino’s capabilities.Also called Daughterboard or Cape Communication Shields Sensors
  12. 12. Design and Development ofMagnetic Door LockThe main aim of the work undertaken in this paperis to sense the correctness of a secret code using COMPONENTS AND EQUIPMENTthe Arduino technology. When the correct code isentered through keypad, it lights a green LED in Arduino Diecimila or Duemilanove board or cloneaddition to operating a small solenoid which D1 Red 5-mm LEDwhen powered, will strongly attract the metal slug D2 Green 5-mm LEDin its center, pulling it into place, when the power R1-3 270 _ 0.5W metal film resistoris removed, it is free to move. The secret code is K1 4 x 3 keypadstored in EEPROM, so if the power is 0.1-inch header stripdisconnected, the code will not be lost. When T1 BC548powered, the solenoid will strongly attract the 5V solenoid (< 100 mA)metal slug in its center, pulling it into place. When D3 1N4004the power is removed, it is free to move.Keypads are normally arranged in a grid so thatwhen one of the keys is pressed, it connects a rowto a column. Figure beside shows a typicalarrangement for a 12-key keyboard with numbersfrom 0 to 9 and * and # keys. The key switches are arranged at the intersectionof 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, itmeans that we only need to use 7 (4 rows +3columns) of our digital pins rather than 12 (onefor each key).
  13. 13. 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.HardwareThe schematic diagram
  14. 14. Software : The software for this project#include <Keypad.h> locked = false;#include <EEPROM.h> updateOutputs(); }char* secretCode = "1234"; delay(100);int position = 0; }boolean locked = true;const byte rows = 4; void updateOutputs()const byte cols = 3; {char keys[rows][cols] = { if (locked){1,2,3}, {{4,5,6}, digitalWrite(redPin, HIGH);{7,8,9}, digitalWrite(greenPin, LOW);{*,0,#}}; digitalWrite(solenoidPin, HIGH);byte rowPins[rows] = {2, 7, 6, 4}; }byte colPins[cols] = {3, 1, 5}; else {Keypad keypad = Keypad(makeKeymap(keys), digitalWrite(redPin, LOW);rowPins, colPins, rows, cols); digitalWrite(greenPin, HIGH);int redPin = 9; digitalWrite(solenoidPin, LOW);int greenPin = 8; }int solenoidPin = 10; }void setup() void getNewCode(){ {pinMode(redPin, OUTPUT); flash();pinMode(greenPin, OUTPUT); for (int i = 0; i < 4; i++ )loadCode(); {flash(); char key;updateOutputs(); key = keypad.getKey();} while (key == 0) {void loop() key = keypad.getKey();{ }char key = keypad.getKey(); flash();if (key == * && ! locked) secretCode[i] = key;{ }// unlocked and * pressed so change code saveCode();position = 0; flash();getNewCode(); flash();updateOutputs(); }}if (key == #) void loadCode(){ {locked = true; if ( == 1)position = 0; {updateOutputs(); secretCode[0] =;} secretCode[1] =;if (key == secretCode[position]) secretCode[2] =;{ secretCode[3] =;position ++; }} }if (position == 4){
  15. 15. void saveCode() EEPROM.write(3, secretCode[2]);{ EEPROM.write(4, secretCode[3]);EEPROM.write(1, secretCode[0]); EEPROM.write(0, 1);EEPROM.write(2, secretCode[1]); }void flash() delay(500);{ digitalWrite(redPin, LOW);digitalWrite(redPin, HIGH);digitalWrite(greenPin, HIGH);digitalWrite(greenPin, LOW);}Since each character is exactly one byte in length, and off will not reset it to 1234. Instead, you willthe code can be stored directly in the EEPROM have to comment out the line:memory. We use the first byte of EEPROM to loadCode(); in the setup function, so that itindicate if the code has been set. If it has not been appears as shown here:set, the code will default to 1234. Once the code // loadCode();has been set, the first EEPROM byte will be givena value of 1. Conclusion and future scope:Putting It All Together A Magnetic Door Lock employing Arduino Load the completed sketch and download it to the technology is presented. We have implemented aboard . We can make sure everything is working failsafe maglock, fail secure maglock also can beby powering up our project and entering the code implemented. Instead of keypad Reader using the1234, at which point, the green LED should light variety of sensors and shields variousand the solenoid release. We can then change the combinations of Magnetic Door Lock can becode to something a little less guessable by produced and installed according to thepressing the * key and then entering four digits for requirements of any Industry.the new code. The lock will stay unlocked untilwe press the # key. If you forget your secret code, References:unfortunately, turning the power to the project on • • ITP Physical Computing • • • • http://coopermaa2nd.blogspot.comBy,Sravanthi Rani Sinha S09BD1A04A0