Design and development of ES to control switching of any appliance using PIC 16F877A Abstract: It is experienced that many electrical devices like Television, computer, printer etc. needs to be protected from its misuse by unauthorised persons. In the present paper an Embedded System (ES) is designed and constructed to protect any electrical device from its misuse by any unauthorised person. This ES is based on microcontroller(μC) PIC 16F877A of microchip. The PIC 16F877A microcontroller of microchip is used as a brain in this ES. This μC receives password from keyboard and compares with true password. If both are same then it will switch on the relay and the connected device will be on. If password is incorrect then the μC will keep relay off and the device will remain off. The password is changeable i.e. the user can change the password whenever it is required. Introduction: The control system to on-off any appliance can be designed by various logical concepts. Few designs are based on two way switches. In this type of design few switches of the key board needs to be put in on state to energise the relay. The main disadvantage of this design is that if someone applies all possible combinations then it can be unlocked for any one combination. [1,2] The another solution is design by pushbutton switches. The user has to keep pressed all switches together. If somehow, the wrongly pressed switches are ignored by ES then it is quite difficult to break the password. This type of design is better than previous design using two way switches. [3] One another type of solution is to reset the password by pressing wrong switch will make the password stronger than the previous designs. To reset password by wrong key is a new logic and make open the lock for some predetermined time.[4] The time restriction during password entering process will make the system easy for fast users, but creates problem for slow users. In the present paper this limited time span restriction is avoided. The user can take unlimited time to enter password. Here the advance PIC microcontroller PIC 16F877A is used to design and construct the ES to control the switching of any appliance through relay. Microcontroller(PIC 16F877A): A microcontroller (sometimes abbreviated μC, uC or MCU) is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically small amount of RAM. Microcontrollers are designed for embedded applications. 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, and other systems.[5] Microcontroller used here is PIC16F877A. The PIC 16F877A is enhanced flash microcontrollers. It is high performance RISC type 40 pin DIP type CPU. It can work from D.C. to 20MHz frequency. It has 8K x 14 words of flash program memory, 368 bytes of Data memory (RAM) and 256 bytes of EEPROM data memory, 33 I/O pins, 8-channal 10-bit ADC, Two 8-bit and one 16-bit timers and two comparators. Its operating voltage range is very wide from 2.0V to 5.5V.[6] The pin diagram of PIC 16F877A is shown in Fig.-1. 1 Fig.-1: Pin diagram of 16F877A List of the components 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 1. 2. 3. 4. 7805 (+5 volt regulator) (1) Programmed MCU PIC 16F877a with 40-pin DIP socket (1) LT542 common Anode Seven Segment Displays (8) Micro switches (24) 12MHz Crystal (1) BC557 PNP Transistors (8) 0-9V, 500mA Transformer (1) Four Diodes 1N4001(D1 to D4) (4) 470µF Electrolytic Capacitor (1) 0.1µF Box type Capacitor (1) 1KΩ Carbon Resistors (1) 10KΩ Carbon Resistors (8) 100Ω Carbon Resistors (9) AN33 Opto coupler (1) Relay(1) Note: The figure in the parenthesis indicates the number of required components. Circuit Description The circuit can be explained by explaining the below given blocks of the ES. Power Supply unit Display unit Keyboard unit Switching unit The Rr is connected between +5V and MCLR (Master Clear (Reset) input) and the 12MHz crystal is connected between pins OSC1 and OSC2 of PIC 16F877A(U2). 2 Fig.-2 : Schematic diagram of ES 1. POWER SUPPY UNIT Initial stage of every electronic circuit is power supply system which provides required power to drive the whole system. The specification of power supply depends on 3 RB7 C 8 4 0 50 Hz 230 V A.C. R10 T 0-9V RB6 R1 to R8 = 10K R9 to R16 = 100E P2.7 R9 Bridge - _ P2.0 SSD7 RB1 RB0 RE2 RB2 gfa b h cde RB3 7805 U1 RE1 Cin 1000micro RB4 + In RB5 2 6 A E 3 7 B F N H P 1 5 9 D R12 R11 R14 R13 R16 R15 R Enter L Chng Out SSD6 Rr 1K Co 0.1micro U2 SSD5 SSD4 baf g e dch 19 RD0/PSP0 20 RD1/PSP1 RC2/CCP1 18 RC3/SCK/SCL 17 15 RC0/T1OSO/T1CKI 16 RC1/T1OSI/CCP2 13 OSC1/CLKI 14 OSC2/CLKO 11 VDD 12 VSS RE2/CS/AN7 SSD3 gfa b h cde Q3 Q4 21 22 23 24 25 26 27 28 29 30 31 32 33 SSD2 SSD1 gfa b h cde R4 Q2 R3 35 Q5 SSD0 baf g e dch R8 R7 R6 R5 R2 36 34 R1 Q1 OC1 37 Rs 38 39 40 baf g e dch RD2/PSP2 RD3/PSP3 RC4/SDI/SDA RC5/SDO RC6/TX/CK RC7/RX/DT RD4/PSP4 RD5/PSP5 RD6/PSP6 RD7/PSP7 VSS VDD 9 RE1/WR/AN6 10 RB0/INT RB1 RB2 RB3/PGM RB4 RB5 RB6/PGC RB7/PGD 8 RE0/RD/AN5 5 RA3/AN3/VREF+ 6 RA4/T0CKI/C1OUT 7 RA5/AN4/SS/C2OUT 3 RA1/AN1 4 RA2/AN2/VREF-/CVREF MCLR/VPP 2 RA0/AN0 1 gfa b h cde X1 12MHz baf g e dch Gnd Q6 Q7 Q8 RLY LAMP the power requirement and this requirement is determined by its rating. The main components used in supply system are: (IC 7805(U1)) The output of this regulated +5V power supply is connected with PIC. This Power supply can be easily converted into +5V Uninterruptible Power Supply (UPS) by adding 12V/4.5Ah battery. This battery is useless in this application because any connected electrical appliance needs high power and this battery can’t supply required power.[7,8] To solve the power failure problem the high power UPS can be used with A.C. mains supply. The Designed ES have used 9V/500mA Transformer. It means the maximum power delivering capacity for this transformer is 9V x 500mA=4500mVA=4.5 Watt. While the ES needs approximately 1W. This power requirement is negligible in comparison with any electrical appliance. 2. Display unit The microcontroller PIC 16F877A (U2) is used as a brain of this circuit in this project. The PIC 16F877A has five ports. Here Port-C and Port-D are used to scan 8-FNDs (8- seven segment LEDs). Common anode type LT542 FNDs are used. The digit can be displayed on single FND by providing low logic on its corresponding Port pin of Port-D and its corresponding special code on Port-C. The 8FNDs can be seen illuminated by scanning technique. When low logic is given at the base of PNP transistor BC557 through 10KΩ resistor, then the transistor comes into saturation. The saturated transistor provides +5 volt at the anode of its corresponding FND. The scanning rate is set by internal Timer-1 of microcontroller PIC 16F877A. The scanning of the eight FNDs is most important to understand. The eight PNP transistors BC 557 (T1 to T8) are doing switching during scanning process in all the eight FNDs. Each segment of FND is connected with current limiting resistor. Eight current limiting resistors R9 to R16 of 100Ω are used. Fig.-3: bottom layer tracks for FNDs Fig.-3 shows that the same track is not connected with the same segments in two consecutive FNDs. The segments are the same for the same track in FND-0, FND-2, FND-4 and FND-6. Similarly, the segments are the same for the same track in FND-1, FND-3, FND-5 and FND-7. By this logic in P.C.B. drawing, the single sided P.C.B. is developed with novel queer multiplexing technique. But this simplicity in P.C.B. drawing is making scanning software difficult. The Port-C needs to send different data to display the same on two consecutive FNDs.[9,10] The Port pins of Port-C are connected with the FND segments through eight 100Ω current limiting resistors R9 to R16. The Port pins PC.7, PC.6, PC.5, PC.4, PC.3, PC.2, PC.1 and PC.0 are connected with FND segments g, f, a, b, h, c, d and e respectively in FND-1, FND-3, FND-5 and FND-7. 4 Similarly, The Port pins PC.7, PC.6, PC.5, PC.4, PC.3, PC.2, PC.1 and PC.0 are connected with FND segments b, a, f, g, e, d, c and h respectively in FND-0, FND-2, FND-4 and FND-6.[10] The special codes to see the digit on FNDs are different for FND-0 and FND-1. The codes remain same for FND-0, FND-2, FND-4 and FND-6. Similarly special codes remain same for FND-1, FND-3, FND-5 and FND-7. These special codes are shown in Table-1.[10] TABLE-1 : FND code for display To see on FND 0 1 2 3 4 5 6 7 8 9 A B C D E F Blank T R N -(desh) Special codes for FND-1,FND-3,FND-5 & FND7 88H EBH 4CH 49H 2BH 19H 18H CBH 08H 09H 0AH 38H 9CH 68H 1CH 1EH FFH 3CH 7EH 7AH EFH Special codes for FND-0,FND-2,FND-4 & FND6 11H 7DH 23H 29H DH 89H 81H 3DH 01H 09H 05H C1H 93H 61H 83H 87H FFH C3H E7H E5H 7FH 3. Keyboard unit The all eight pins of port-B and two pins of port-E are used for scanning of Key Board (KB). The pin connections between the matrix KB and the MCU with key labels are shown in Table-2. TABLE-2 : Port Pin connections of KB matrix with key functions Port Pins RB7 RB6 RB5 RB4 RB3 RB2 C D E F P Chng RB1 8 9 A B H L RB0 4 5 6 7 N R RE2 0 1 2 3 Enter RE1 Table -2 shows that 24 keys are arranged in (4 x 6) matrix. In this matrix four rows and six columns are arranged with scanning technique. This technique is very simple and easily understood. The Timer-1 is also used to scan this keyboard. 4. Switching unit This switching unit is most important and it is responsible to on and off the connected appliance. The appliance will be switched on if correct password is entered. The connected appliance can be switched off by switching off the ES. The port pin PE0 is 5 connected to relay through opto coupler(AN33). The relay is basically an electromechanical switch which can turn on or turn off any connected electrical appliance. The 100Ω Resistor (Rs) is current limiting resistor for opto coupler input. Working of the device: The display will show “dArsHAn” as we switch on the power. The connected electrical appliance is remained switch off. The “Enter” key is used to enter the password after pressing all keys combination (password). The ES is continuously ready to accept the password. The manufacturer password is “01234567”. If we enter any other password except “01234567” then display will show “PASS OFF” and the connected device (electric bulb) will remain off. If we apply “01234567” as a password than the display will show “PASS On” and the connected device will be switched on. The “chng” key is used to change the password. The Password can be change by below given procedure. Step-1: Press “Chng” key to change the password. The display will show “OLD PASS”, i.e. the ES demanding old password. Step-2: Enter old password. If old password is correct than it will demand new password otherwise it will not do any change. Ster-3: Enter new password if entered old password is correct. Step-4: the ES demands new password second time. Note: The display is not showing any character but it shows ‘-‘. To overcome possibilities of wrong key depression the ES demanding new password twice. Step-5: Enter second time new password. If both passwords are same then it will change the password. The display will show ‘changed’. Suppose both new passwords are different then the password will remain unchanged and display will show ‘nochange’. The display is not showing any characters but only displaying desh(‘-‘). This logic allows keyboard of this ES to label in any language. The other people can’t recognize the password. Software The program is written in ‘C’ language and compiled using MPLAB IDE V7.60 compiler. MPLAB IDE is freely available on https://www.microchip.com. The header file htc.h is included to use the inbuilt functions of the software. Only Timer1 is used for display multiplexing and keyboard scanning. The ‘Reset’ key is not put in the present hardware. All other keys are scanned by the source program. The main task in this software development is the time division multiplexing for displaying a particular number on the seven segment display unit. The keyboard scanning is comparatively easy. Applications : This designed ES can be used for various applications. It can be used to turn on bulb by password. It can be used to switched on Television, Room heater, Computer, Printer/Scanner, Air conditioner, Microwave/Electrical oven etc. using password. This password is easily changeable. 6 [1] [2] [3] [4] [5] [7] [8] [9] [10] Acknowledgement I acknowledge a sincere thanks to shri. Pareshbhai Patel ( Lab. Assistant, Physics Department, Hemchandracharya North Gujarat University, Patan ( Gujarat)) for his help during this work. Any type of feedback from the reader will be accepted. Referance: S.C.Dwivedi,”Transistorised code lock with torch”, EFY, Vol.-43, No.-3, March-2011 PP135. http://electronicsforu.com/electronicsforu/circuitarchives/ view_article.asp?sno=1197&article_type=1&id=1029&tt=unhot dated Electronics Projects Vol.-21, Published by EFY, PP-169. A.Jeyabal,”simple Low-Cost Digital code lock”, Vol-31,No.-6, July-99 Shruti shrivastava, Jageshwar Rawat and Amit Agrawal,” Controlling DC Motor using Microcontroller (PIC16F72) with PWM”, International Journal of Engineering Research, Volume No.1, Issue No.2, pp : 45-47. [6] http://ww1.microchip.com/downloads/en/DeviceDoc/39582C.pdf dated 21st March,2014 Inderpreet Kaur, “Microcontroller Based Home Automation System With Security”, International Journal of Advanced Computer Science and Applications, Vol. 1, No. 6, December 2010,pp-60 to 65 D.G.Vyas, Design and Construction of Power Supply for Embedded System, Asian Journal of Science and Applied Technology, Volume 1 Number 2, July – December 2012,pp-24 to 27. D.G.Vyas,”Stop Clock using Microcontroller AT89C52”, J. of Lab Experiments, Volume- 7, No.-3,September-2007, pp- 211 to 219 D.G.Vyas,” An Unconventional queer multiplexing technique for SSDs”, J. of Education, IETE, Vol.- 49, No.-3, sept.-Dec-2008, pp-115-120 7