PSZ 19:16 (Pind.
“I hereby declare that I have read this thesis and in my opinion this thesis is sufficient in terms of scope and quality for the award of the degree of Bachelor of Engineering (Electrical-Power)” Signature : …………………………………… Name of Supervisor : ASSOC. PROF. DR.
COUNTER SYSTEM USING MICROCONTROLLER FOR VISITOR NUR FARAHIN BINTI ASA @ ESA A thesis submitted in partial fulfilment of the requirements for the award of the degree of Bachelor of Engineering (Electrical-Power) Faculty of Electrical Engineering Universiti Teknologi Malaysia JULY 2012
“I declare that this thesis entitled “Counter System Using Microcontroller for Visitor” is the result of my own research except as cited in the references. The thesis has not been accepted for any degree and is not concurrently submitted in candidature of any other degree.
ii This thesis is dedicated to my loving parents, always be my inspiration. You are the reason I step forward to this stage. To teammate, my beloved friends, I will never forget your support. And to those who helped me a lot, thank you very much. You are always in my minds. Special thanks to Prof. Dr. Nik Rumzi Nik Idris. Your valuable help and suggestions makes my special word for you.. “Thank You..
iii ACKNOWLEDGEMENTS Alhamdulillah. In the name of Allah, the Most Compassionate, the Most Merciful. Praise be to Him, the Lord of the universe. Blessing and solution of peace to Holy Prophet Muhammad (peace be upon him) and his companion and those who follow him as upholding the cause of the right religion. First of all I wish to express my appreciation and gratitude to my supervisor, Dr.
v ABSTRACT Nowadays, people often waste energy without realizing it. Home automation concept had been introduced to save power consumption. A counter system circuit was designed and set up to turn on or off the lights. This system is useful when someone in a room forgot to turn off the light when they leave only when nobody left in the room. Moreover, this device can be used to measure the number and direction of people traversing a certain passage or entrance.
vi ABSTRAK Pada masa kini, manusia sering membazirkan tenaga tanpa disedari. Sistem automatik telah diperkenalkan untuk menjimatkan penggunaan kuasa. Litar sistem mengira telah direka bentuk untuk menghidupkan dan mematikan lampu. Sistem ini amat berguna apabila seseorang di dalam bilik lupa untuk mematikan lampu apabila mereka keluar dan apabila tiada siapa yang ada di dalam bilik.
vii TABLE OF CONTENTS CHAPTER 1 2 TITLE PAGE DECLARATION ii DEDICATION iii ACKNOWLEDGEMENTS iv ABSTRACT v ABSTRAK vi TABLE OF CONTENTS vii LIST OF TABLES x LIST OF FIGURES xi LIST OF ABBREVIATIONS xiv LIST OF SYMBOLS xvi LIST OF APPENDICES xvii CHAPTER 1 : INTRODUCTION 1 1.1 PROJECT BACKGROUND 1 1.2 PROBLEM STATEMENT 2 1.3 OBJECTIVES 3 1.4 SCOPE 4 1.5 THESIS OUTLINE 5 CHAPTER 2 : LITERATURE REVIEW 6 2.1 INTRODUCTION 6 2.
viii 2.3 3 2.2.1 COUNTER 6 2.2.2 MICRCONROLLER 8 2.2.3 SK40C 9 2.2.4 PIC 18F452 13 2.2.5 PIC PROGRAMMER 15 2.2.6 MICROC PRO 17 2.2.7 PICKIT 2 18 RELATED WORK 20 CHAPTER 3 : METHODOLOGY 22 3.1 INTRODUCTION 22 3.2 SOFTWARE IMPLEMENTATION 22 3.2.1 DEFINING THE TASK AND PROBLEM 23 3.2.2 DESIGNING THE SYSTEM 23 3.2.3 WRITING THE CONTROL PROGRAM 26 3.2.4 TESTING AND DEBUGGING 32 HARDWARE IMPLEMENTATION 33 3.3.1 PART I (USING SK40C) 33 3.3.2 PART II (COMPLETE PROJECT) 34 3.
ix 4.3.1 POSSIBILITIES THAT NEED TO BE 50 CONSIDERED 4.3.2 PROBLEM OF THE OVERALL SYSTEM 5 52 CONCLUSION AND RECOMMENDATION 55 5.1 INTRODUCTION 55 5.2 CONCLUSION 55 5.
x LIST OF TABLES TABLE NO. 2.
xi LIST OF FIGURES FIGURE NO. TITLE PAGE 2.1 Counter 7 2.2 Microcontroller 9 2.3 Component connection to SK40C 10 2.4 Wire connection to SK40C 10 2.5 SK40C connection to breadboard 11 2.6 SK40 labeling 11 2.7 Circuit diagram of SK40C 12 2.8 PIC 18F452 pin diagram 14 2.9 PIC 18F452 14 2.10 UIC00B with USB and rainbow cable 16 2.
xii 2.12 PICkit 2 software 19 3.1 Block diagram of overall system 23 3.2 Overall flowchart design 25 3.3 Microc PRO Start Page 28 3.4 First page to create new project 28 3.5 Selecting the device 29 3.6 Choose suitable device clock 29 3.7 Select the path to save project 30 3.8 PICkit 2 Programmer detect PIC 18F452 device 31 3.9 The hex file is successfully imported to PIC 32 3.10 Relay circuit diagram 35 3.11 Sensor connection to SK40C 35 3.
xiii 3.16 Call function to display the welcome and greeting 38 3.17 PIC 18F452 type 39 3.18 SK40C board 39 3.19 Distance sensor block diagram 40 3.20 a) Output distance sensor characteristic 41 b) Distance sensor (IR proximity sensor) 3.21 Relay schematic diagram 42 3.22 Relay circuit used in project 43 3.23 a) LCD 16x2 43 b) LCD shows occupant in 4.1 Programming successfully compiled 45 4.
xiv 4.6 a) Fluorescent lamp turn off 49 b) Total occupant equal zero 4.
xv LIST OF ABBREVIATIONS ADC - Analog Digital Converter A/D - Analog to Digital FKE - Fakulti Kejuruteraan Elektrik UART - Universal Asynchronous Receiver/Transmitter EEPROM - Electronically Erasable Programmable Read Only Memory AUSART - Addressable Universal Asynchronous Receiver Transmitter SFR - Special Faction Register GPR - General Purpose Register CMOS - Complementary metal–oxide–semiconductor ICD - Implantable Cardioverter-Defibrillator PWM - Pulse-width modulation
xvi PC - Personal Computer MCU - Multipoint Control Unit IR - Infrared I/O - Input / Output LED - Light Emitting Diode PIC - Peripheral Interface Controller RAM - Random Access Memory COFF - Common Object File Format IDE - Integrated Development Environment ANSI - American National Standards Institute ROM - Read Only Memory LDR - Light Dependent Resistor CPU - Central Processor Unit PDIP - Programmed Dialogue with Interactive Programs LCD - Liquid Crystal Display
xvii NO - Normally Open NC - Normally Close
xviii LIST OF SYMBOLS cm - Centimeter Hz - Hertz MHz - Mega Hertz uF - Mikro Farad V - Volt KB - Kilo Byte
xix LIST OF APPENDICES APPENDIX A TITLE PIC MICROCONTROLLER CODE OF COUNTER PAGE 61 SYSTEM USING MICROCONTROLLER FOR VISITOR (SK40C) B PIC MICROCONTROLLER CODE OF COUNTER SYSTEM USING MICROCONTROLLER FOR VISITOR (FULL SYSTEM)) 66
CHAPTER 1 INTRODUCTION 1.1 PROJECT BACKGROUND In a public place such as shopping malls and cinemas, data on the number of visitor is frequently needed for marketing research or statistic purposes. Usually the counting process is done manually by the officers who guard the entrance. If this process is done for a long period of time, it will be prone to human errors. Same goes to a room such as laboratory, main hall, mosque or bedroom. A counter can be implemented to save energy by a specific system.
2 integration of power electronics components, such as circuits and sensors; and using the integrated components for standardized methods of assembling power converters, which are still custom-designed [23]. As human keep wasting energy, these problems will never solved only if a new system designed to overcome this problem. In the aspect of energy conversion thinking, a basic start such as lighting system which people consume the most can be reduces by a few ideas.
3 lighting system in laboratory at Faculty Kejuruteraan Elektrik (FKE) , Universiti Teknologi Malaysia always been detected did not turn off most of the night and caused the increase in electricity bill and energy wasting. So, one of the method can be use to solve this problem is to apply the counter system for visitor using microcontroller. A counter system can be design in many ways such as combination of gate logic and microcontroller.
4 iv. To develop a programming for microcontroller to count up and down visitor traversing a certain passage or entrance which in this case is the FKE laboratory v. This system can calculate height of the visitor 1.4 SCOPE This project is mainly concerned to design a counter that will count visitor and control the lighting system of a room or hall. Consequently, this system will avoid people wasting energy when they forgot to turn off the light. However, there are a few limitations on this project.
5 1.5 THESIS OUTLINE This thesis consists of five chapters. In first chapter, it gives an overview with commence on introduction and background of the project, problem statement, and objectives. Chapter Two discusses on the literature review of the system which includes the overall device used in this project. For this part, it gives the idea on counter, microcontroller and briefing about tool. In addition, the related work from previous project which is similar also included.
CHAPTER 2 LITERATURE REVIEW 2.1 INTRODUCTION This chapter brief in detail about the tools used and rough overview about this project. From this chapter, the features of the all the device and software include in this system are covered. There will be two parts; part 1 is about the background of this project, while part 2 is about previous study that related to the proposed topic. 2.2 BACKGROUND 2.2.
7 in up and down modes depending upon the state of the selector. It can be used to count the number of persons entering a hall in the up mode at entrance gate. In the down mode, it can count the number of persons leaving the room by decrementing the count at exit gate. It can also be used at gates of parking areas and other public places. This circuit divided in three parts: sensor, microcontroller and counter display.
8 2.2.2 MICRCONTROLLER A microcontroller is a highly integrated chip which performs controlling functions. A microcontroller, or embedded controller, is similar to a microprocessor as used in a personal computer. PIC microcontroller is a processor with built in memory and RAM and can be use to control the input and output of the project. Microcontrollers are microprocessors integrated with peripherals on a single integrated circuit.
9 Figure 2.2 : Microcontroller [15] 2.2.3 SK40C SK40C is a start up kit for beginner to design and test a system. In this project, SK40C suitable to fulfil this project as the circuit compatible with various input and output. SK40C is another enhanced version of 40 pins PIC microcontroller start up kit. It is designed to offer an easy to start board for PIC MCU user. However, all interface and program should be developed by user.
10 8. USB on board for certain PIC18F. 9. Users are able to utilize the function of PIC by directly plugging in the I/O components in whatever way that is convenient to user. Bootloader can still be applied in loading program. 10. Without PIC microcontroller to provide the freedom to choose PIC type. The accessible of SK40C: 1. Components that needed connected onto the I/O port. Figure 2.3 : Component connection to SK40C [16] 2. The I/O port can be extended to another board using jumper wire. Figure 2.
11 3. I/O pins of the SK40C plugged onto a breadboard. Then, I/O pin can be access through the breadboard. Figure 2.5 : SK40C connection to breadboard [16] 4. I/O pins of the Start-up Kit plugged onto a donut board. So user can solder the pins onto the board to access the connection of input and output. Figure 2.
12 Label Function Label Function A DC power adaptor socket I Programmable Push Button B USB Connector J Reset button C Toggle Switch for power K LCD contrast supply D Power indicator LED E Connector for L UIC00A M JP8 for LCD Backlight JP9 for USB Programmer F LED Indicator N 40 pin IC socket for PIC MCU G Header pin and turn pin O Turn pin for crystal H UART Connector P LCD Display Table 1.1 : Lable of function Figure 2.
13 2.2.4 PIC 18F452 This powerful 100 nanosecond instruction execution are easy-to-program with which have 77 single word instructions with CMOS FLASH-based 8-bit microcontroller packs Microchip's powerful PIC architecture into a 40-pin package. It is upwards compatible with the many PIC devices and thus providing a seamless migration path of software code to higher levels of hardware integration.
14 Figure 2.8 : PIC 18F452 pin diagram [18] Figure 2.9 : PIC 18F452 [19] The basic features of PIC 18F452 are: 1. Consist of 40-pin Programmed Dialogue with Interactive Programs (PDIP) 2. 32KB flash program memory 3. It can attain 40MHz max crystal speed: 4. The RAM Bytes is 1,536 and contain 256 EEPROM Bytes 5. PIC 18F452 provide timers which is 1 x 8 bit and 3 x 16-bit 6. Analog-to-digital converter (ADC) consist of 8channel and 10-bit 7.
15 PIC divided into 3 types of memories: i. Program Memory - A memory that contains the program after the program had been burned. As a reminder the program counter executes commands that stored in the program memory one after the other [24]. ii. Data Memory - This is RAM memory type. It contains a special registers such as SFR (Special Faction Register) and GPR (General Purpose Register).
16 family including PIC 18F452. Besides 8bit,16bit and 32bit PIC MCU also can be programmed using this programmer. On board In Circuit Serial Programming (ICSP) connector offers flexible methods to load such this program. USB port is commonly available and widely used on Laptop and Desktop PC, thus they are very convenient to use UIC00B.Program most of the +3.3V or +5V PIC.
17 2.2.6 MicroC PRO The mikroC PRO for PIC is a powerful, feature-rich development tool for PIC microcontrollers. It is designed to provide the programmer with the easiest possible solution to developing applications for embedded systems, without compromising performance or control. PIC and C fit together well where nowadays PIC is the most popular 8-bit chip in the world, used in a wide variety of applications, and C, prized for its efficiency is the natural choice for developing embedded systems.
18 a) b) Figure 2.11 : a) microC PRO icon b) microC PRO start page software 2.2.7 PICkit 2 The Microchip PICkit 2 device programmer and in-circuit debugger consists of software which runs on a PC and hardware. Programmer-only software comes with the PICkit 2. MPLAB includes both programming and in-circuit debugging software. With the PICkit 2, user can step through assembly source code on-screen while observing what the hardware is doing.
19 by the PICkit 2 is also programmed into program memory locations reserved for the purpose. The PICkit 2 can operate in two hardware configurations: i. Device programmer for programming flash devices. ii. Debugger/programmer for working with flash devices with in-circuit debugging capability. Figure 2.
20 2.3 Related Work i. Street Light Switch the lights on and off automatically during night and day time respectively. This system used Light Dependent Resistor (LDR). The resistance changes according to the amount of light falling on it. The system is said to reduce energy consumption and CO2 emissions by up to 80 percent, plus it lowers maintenance costs and reduces light pollution [11]. ii. Motion Detector Lighting Control System This system use motion detection to control lighting system.
21 iv. Occupancy Detection Count the number of people that enter and exit each room (counter). If the counter is more than zero, light will turn on. On the other hand, if the counter is equal to zero, light turn off.
CHAPTER 3 METHODOLOGY 3.1 INTRODUCTION The software implementation and hardware implementation are explained in detail through this chapter. Software implementation discussed on the designing the program by flowchart, writing and testing the program. The hardware methodology is divided into two parts. First part discussed the method by using the microcontroller independently. The second part is the implementation by combined sensor and relay simultaneously.
23 3.2.1 Defining the task and problem Figure 3.1 : Block diagram of overall system The user accesses the abilities of the microcontroller by writing a program that performs the desired functions. The main function of this project is to count visitor but there are other aspect that must be consider. This system must differentiate when a visitor enter or leave the room. Sensor only sense the present of a person but it is microcontroller task to define either a person is enter or leaving the laboratory.
24 devices for a specific project. Within each device family, we usually find a selection of family members, each with different combinations of options. In this project, a IC PIC 18F452A chosen because it is suitable for multitasking programs and serial communication [1]. As a starting, SK40C is a start-up kit used to test this project with variable input and output.
25 Figure 3.
26 First of all, sensor 1 will detect any presence of object. If there are object detected, the microcontroller will proceed to detect sensor 2, and in 0.5 second range, there are object detected, the counter will counting up and relay will turned on. This counting is represent a visitor is entering the laboratory. Henceforth, it is similar for visitor that leaving the room. If sensor 2 detect the object first and a sensor 1 trace 0.
27 The system model designed is the key element used in this study. Without proper design and correct model, this study will not be successful. For this stage, a necessary tool is needed to be used as a medium for carrying out the simulation. After the control program is done without any error, hardware implementation is proceeding. There are several parts in programming which is: i.
28 New project Figure 3.3 : MicroC PRO start page Click „Next‟ to skip the introduction. Figure 3.4 : First page to create new project For the first step, choose device name. In this project, PIC 18F452 choose as mentioned before.
29 Figure 3.5 : Selecting the device Next, clock of the device must be setup. For counter system, the suitable device clock is 20 MHz. Figure 3.6 : Choose suitable device clock Then, select the path to save the project that had been created. So, next time if the projects need to be open, this folder will show the counter program.
30 Figure 3.7 : Select the path to save project Click next to proceed until step 5/6 and lastly click finish for the last step. At this moment, the programming can be design and then build the program to check the error. A Program with no error will be executed in hex file. iii. Programming with PICkit 2 In the previous section, a hex file is created and it is ready to be loaded into the microcontroller. The procedures to load the hex file into the microcontroller are given in this section.
31 After connecting the PIC programmer and the microcontroller, the PICkit 2 programmer is launched in PC. By using PICkit 2, the programming will be loaded to the microcontroller. By clicking on the “auto import hex + write device”, select the project that had been saved and the program should be imported to the microcontroller automatically. Figure 3.
32 Figure 3.9 : The hex file is successfully imported to PIC 3.2.3 Testing and debugging This is the most important part. After a program is written, or a section of one, it needs to be tested and as necessary and any mistakes found need to be correct to get it working properly. As the control program is done, the next phase, the project is proceed to the next. The process of ferreting out and correcting mistakes is called debugging.
33 After the PIC 18F452 had been programmed, it placed to the SK40C and connected to input and output to run the system. This chip had been programmed several times before desired output is obtained. By using microcontroller, the program can be easily change for convenience or depend on requirement of the project. The input and output must be taken into consideration with a suitable range of current to avoid damage on PIC 18F452. The complete coding can be referring to Appendix B. 3.
34 buttons is pressed for a long period (more than 0.5 second), so it means the buzzer will sound on and at the same time RB7 LED will remain lit. For the first demo, the program is limit to 5 persons as maximum. When the counter hit 5, the LCD will display “FULL COUNT” and the program will not count if the number exceeds 5. This program is design for testing purpose and to observe the reliability of the microcontroller. The full coding for this part can be referred to Appendix A. 3.3.
35 Figure 3.10 : Relay circuit diagram Figure 3.
36 3.3.3 Type of Call Function Function of analog-to-digital converter to detect presence of object: void readSensor(void) { int j; for(j = 0 ; j < 10 ; j++) // take analog result for 10 times { s1_value = s1_value + ADC_Read(1); s2_value = s2_value + ADC_Read(2); } s1_value = s1_value/10; //get average s2_value = s2_value/10; if (s1_value>95) sensor1=0; //detect object else sensor1=1; //no object if (s2_value>95) sensor2=0; //detect object else sensor2=1; //no object } Figure 3.
37 The coding above shows that ADC for the sensor that needed to make sure the output of sensor converted to digital before microprocessor can understand the data. This call function used for sensor 1 and sensor 2. Function to calculate height of visitor: void calculateHight(void) { Vout=(s3_value*500000)/1024; if ((Vout > 43945)&&(Vout < 279785)) to 2.8V = 8cm { Range_an=(Vout-19000)/2099; Range=1000/Range_an; Hight=210-Range; } } // read only from 0.4V = 80cm Figure 3.
38 Function to display the introduction for the beginning of the system: void introduction(void) { unsigned char i; Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1," WELCOME "); Lcd_Out(2,1," SELAMAT DATANG "); delay_ms(2000); // Move text to the left 16 times for(i=0; i<16; i++) { Lcd_Cmd(_LCD_SHIFT_LEFT); delay_ms(250); } Lcd_Cmd(_LCD_CLEAR); Lcd_cmd(_LCD_CURSOR_OFF); } Figure 3.
39 Figure 3.17 : PIC 18F452 type ii. SK40C It is easy to use this hardware where the input and output can be any device. No circuit designation required by using SK40C. Thus, this can ease the project flow and reduce the error caused by failure during circuit designation. Figure 3.
40 iii. Sharp GP2YOA21 This type of sensor is widely used; popular choice for application and development that require accurate distance measurements and inexpensive proximity sensor. Connect +5v to power and ground and the output signal is an analog voltage that varies from +3.5v to 0v, which is a proportional to the distance between the sensor and the object. This IR proximity sensor is more economical than sonar range finders. It provides much better performance than other IR sensor alternatives.
41 output terminal which can then be used to activate any number of devices. For the purpose of this exercise, a small green LED will turn on when the sensor becomes active [9]. a) b) Figure 3.20 : a) Output distance sensor characteristic [10] b) Distance sensor (IR proximity sensor) [22] iv. Relay A relay is an electrically operated switch, simplest, easiest and useful device. Most of relays use an electromagnet to operate a switching mechanism mechanically.
42 and much more in the market. All these relay have same function but different in specification [6]. Figure 3.21 : Relay schematic diagram As known, relay consists of two separate and completely independent circuits. One is at the bottom and drives the electromagnet. A switch is controlling power to the electromagnet in this circuit. When the switch is turn on, the electromagnet will produce flux, and it attracts the armature while armature is acting as a switch in the second circuit.
43 Figure 3.22 : Relay Circuit used in Project v. Liquid Crystal Display (LCD) A 16x2 liquid crystal display is used to display the total occupant inside the laboratory. This LCD also display either a visitor is enter or exit the room. It can be observed when occupant is entering; an output shows “In” and along with the increment of counter. Same goes if when occupant is leaving, LCD will display “Out” in a line with the decrement of the counter.
CHAPTER 4 RESULT AND DISCUSSION 4.1 INTRODUCTION There are two parts discussed in this chapter which is divided to microcontroller independently and completed circuit. The performance and the ability of this project to function are mentioned on result. The microcontroller functionality is explained and complete result after the whole circuit is combined is observed. The system works as proposed and the desired output is obtained after a few re-tested and re-calibrated is done.
45 4.2 RESULT Figure 4.1 : Programming successfully compiled The C++ programming is compiled successfully with no error. The full coding can be referring to Appendix. i. Part I For microcontroller part, the programming was tested using the SK40C hardware before the project is combined together. RB0 button define sensor 1 while RB1 indicate sensor 2. Imagine a person pass through sensor 1 and 0.5 second after that, he should be pass through sensor 2, RB1 must be pressed 0.
46 RB6 initially off condition a) RB6 turn on Full count =5 b) c) Figure 4.2 : a) System in off condition b) RB6 LED turn on when count greater than 0 c) LCD display “Full Count” for count equal to five RB6 LED indicates the relay that is connected to lighting system. Relay is on if RB6 LED is turned on. RB7 LED indicates error. LED wills on if error occur. RB0 and RB1 define sensor 1 and sensor 2 respectively. There is another situation where error occurs.
47 RB7 turn on a) b) Figure 4.3 : a) RB7 LED turn on shows error when RB1 pressed more than 0.5 second b) RB7 LED turn on shows error when RB0 and RB1 pressed more than 0.5 second If the counter count to zero, RB6 is turn off. RB6 turn off Figure 4.
48 ii. Part II This is the result when the completed circuit is implemented on the laboratory door. The first test when an occupant is entering, the counter counts up. The total occupant is one and fluorescent lamp is turn on. The system also calculates the height of the occupant as they enter or leave the laboratory. Light turn on a) Height of occupant b) Figure 4.
49 When the last occupant inside the laboratory is leaving, which means there is nobody inside the laboratory, counter count to zero and fluorescent lamp is turn off. Light turn off a) b) Figure 4.
50 4.2 DISCUSSION 4.2.1 Possibilities that need to be considered During this project, there are many possibilities need to be considered. There are a few conditions that take to consideration: 1. Someone swings their arms as they walk in. Since the sensors are mounted at the around 140cm above the floor, it eliminates most of the problems that would occur from this.
51 3. If someone walks in right behind the other person. Unless both of the occupants are literally holding on to each other with no space between them torsos, the beams will be restored as soon as the first person passes. Before the next person can walk in order to prevent baggy clothing from setting off the sensor, a very small time threshold must be met for both beams to be clear. A microcontroller takes a few second to run the program before it executes to the next stage. 4.
52 7. Function of reset button. A reset button on SK40C can be reset only if the system is unreliable. There are a few possibilities such as the counter did not detect a person when they go in but when they went out, there are one person left inside the room, so the counter will be negative count. This is where reset button used to reset the total data of occupant. Distance sensor had been used in this project.
53 It will lead to error such that, the counter will be negative value or the counter will never decrease to zero. Counter will be negative due to failure of detecting an occupant entering the door. In this case, lighting is turned off even there is an occupant left inside the laboratory. While the other side, counter will never decrease to zero once the system failed to detect a visitor that leaving the room.
54 detection range affect the accuracy of the sensor. To overcome this problem, a bright LED can be placed near to the sensor to give extra light at surrounding of the sensor. In other hand, the error might due to the sensor fail to detect actual position of occupant. For instance, sensor calculates the height of visitor‟s shoulder or their hands from above.
CHAPTER 5 CONCLUSION AND RECOMMENDATION 5.1 INTRODUCTION In this chapter, the entire objective achieved is explained in brief. A few suggestions to improve the project is discussed in term of accuracy, stability and extra function in for future development related to this project. 5.2 CONCLUSION This project was successfully achieved its objective. Counter System using Microcontroller for Visitor was successfully designed and implemented using SK40C and PIC 18F452 as the main controller.
56 programming to count up and down visitor traversing a certain passage or entrance is operating successfully. 5.3 RECOMMENDATIONS FOR FUTURE IMPROVEMENT For further study about counter system, the system can be improved by solving the problem occurred by distance sensor. Calibration for sensor and bright LED can be used to increase the accuracy of the distance sensor. In addition, the study on programming to make the system more flexible is required.
57 REFERENCES 1. Jan Axelson Published, The Microcontroller Idea Book, Circuits, Programs, & Applications featuring the 8052-BASIC Microcontroller (Lakeview Research), 1994. 2. Akshay Mathur, Kuldeep and Singh Nagla, Microcontroller-based Bidirectional Visitor Counter. article, 2007. 3. Tai Wee Ming, Motion Detector Lighting Control System. Universiti Teknologi Malaysia: Thesis B. Electrical Engineering (Telecommunication), 2011. 4.
58 8. Engineer Garage, Automatic bidirectional visitor counter using 8051 microcontroller (AT89C51). June 2012. http://www.engineersgarage.com/microcontroller/8051projects/Bidirectionalvisitor-counter-AT89C51-circuit 9 “IR Proximity Sensor”, Last access: June 2012. http://www.g9toengineering.com/AllSaints/infraredproximity.htm 10 Cytron Technologies, Project 7, Analog sensor: range using analog distance sensor. June 2012. http://tutorial.cytron.com.my/wp-content/uploads/2011/08/P7-User-Manual.
59 17 “SK40C schematic diagram”, Last access: June 2012. http://www.cytron.com.my/usr_attachment/SK40C.Rev2.0.0%20Schematic.pdf 18 “18FXX2 datasheet”, Last access: June 2012. http://ww1.microchip.com/ 19 AstanaDigital, PIC MICROCONTROLLER (PIC18F452. June 2012. http://www.astanadigital.com/product.php?id_product=141 20 Eshore technologies, USB ICSP PIC PROGRAMMER V2010 (UIC00B). June 2012. http://www.e-shore.com.
60 26 Scribd, Introduction to mikroBasic PRO for PIC. June 2012. http://www.scribd.com/ 27 R4R, C Programming. June 2012. r4r.co.
61 APPENDIX A PIC MICROCONTROLLER CODE OF COUNTER SYSTEM USING MICROCONTROLLER FOR VISITOR (SK40C) //Define port #define sensor1 portb.f0 #define sensor2 portb.f1 #define error portb.f7 #define relay portb.
62 sbit LCD_RS_Direction at TRISB4_bit; sbit LCD_EN_Direction at TRISB5_bit; sbit LCD_D0_Direction at TRISD0_bit; sbit LCD_D1_Direction at TRISD1_bit; sbit LCD_D2_Direction at TRISD2_bit; sbit LCD_D3_Direction at TRISD3_bit; sbit LCD_D4_Direction at TRISD4_bit; sbit LCD_D5_Direction at TRISD5_bit; sbit LCD_D6_Direction at TRISD6_bit; sbit LCD_D7_Direction at TRISD7_bit; void introduction(void); void displayLCD(int y); void main() { int count=0,count1=0,txt[7]; trisb=0b00000011; trisd=0; portb=0; adcon1=0;
63 if((sensor1==0)&&(sensor2==0)) continue; count1++; displayLCD(count1); } else{ delay_ms(50);count++; } } while((count==10)&&(sensor1==0)) {error=1;} if(sensor1==1){error=0;} } error=0; while (sensor2==0){ if((sensor1==0)&&(sensor2==0)){error=1;} while (count<10){ if(sensor1==0){ count=13;delay_ms(500); if((sensor1==0)&&(sensor2==0)) continue; count1--; displayLCD(count1); } else{ delay_ms(50);count++; } } while((count==10)&&(sensor2==0)) {error=1;} if(sensor2==1){error=0;}
64 } error=0; if(count1>0){relay=1;} if(count1==0){ relay=0; } count=0; if(count1>=5){ Lcd_Cmd(_LCD_CLEAR); Lcd_Cmd(_LCD_CURSOR_OFF); Lcd_Out(1,1," Full "); Lcd_Out(1,11,"Count:"); IntToStr(5,txt); Lcd_Out(2,5,txt); delay_ms(90); count1=5; } else if(count1<0){count1=0;} } } void introduction(void) { unsigned char i; Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1," WELCOME "); Lcd_Out(2,1," SELAMAT DATANG "); delay_ms(2000);
65 for(i=0; i<16; i++) { // Move text to the left 16 times Lcd_Cmd(_LCD_SHIFT_LEFT); delay_ms(80); } Lcd_Cmd(_LCD_CLEAR); } void displayLCD(int y) { char txt[7]; IntToStr(y,txt); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1,"Count:"); Lcd_Out(1,11,txt); Lcd_Out(2,11,"per 30"); }
66 APPENDIX B PIC MICROCONTROLLER CODE OF COUNTER SYSTEM USING MICROCONTROLLER FOR VISITOR (FULL SYSTEM) //Define port #define error portb.f7 #define relay portb.
67 sbit LCD_D1_Direction at TRISD1_bit; sbit LCD_D2_Direction at TRISD2_bit; sbit LCD_D3_Direction at TRISD3_bit; sbit LCD_D4_Direction at TRISD4_bit; sbit LCD_D5_Direction at TRISD5_bit; sbit LCD_D6_Direction at TRISD6_bit; sbit LCD_D7_Direction at TRISD7_bit; unsigned long s1_value=0,s2_value=0,s3_value=0; unsigned long Vout, Range,Range_an,Hight; int count=0,count1=0,txt[12],txt2[12]; int sensor1=1,sensor2=1; void readSensor(void); void readSensor3(void); void calculateHight(void); void introduction(vo
68 while(1) { readSensor3(); calculateHight(); //display hight LongToStr(Hight,txt2); Lcd_Out(2,15, "cm"); Lcd_Out(2,4,txt2); Lcd_Out(2,1, "Ur Height:"); readSensor(); while (sensor1==0) { readSensor(); while (count<20) { readSensor(); if(sensor2==0) { count=23; delay_ms(1000); readSensor(); if((sensor1==0)&&(sensor2==0)){error=1; count1--; if ((sensor1==1)&&(sensor2==1))continue; } count1++; displayLCD(count1); //display "Out" Lcd_Out(1,14,"In"); delay_ms(500); Lcd_Out(1,14," "); } else
69 { delay_ms(50); count++; } } readSensor(); while((count==20)&&(sensor1==0)) { error=1; readSensor(); } readSensor(); if(sensor1==1) {error=0;} } error=0; readSensor(); while (sensor2==0) { readSensor(); while (count<20) { readSensor(); if(sensor1==0) { count=23;delay_ms(1000); readSensor(); if((sensor1==0)&&(sensor2==0)){error=1;count1++; if ((sensor1==1)&&(sensor2==1))continue; } count1--; displayLCD(count1);
70 //display "Out" Lcd_Out(1,14,"Out"); delay_ms(500); Lcd_Out(1,14," "); } else { delay_ms(50); count++; } } readSensor(); while((count==20)&&(sensor2==0)) { error=1; readSensor(); } if(sensor2==1) {error=0;} } error=0; count=0; // on/off lamp if(count1>0) relay=1; else relay=0; if(count1>=200) { delay_ms(1000); displayLCD(count1);
71 Lcd_Out(2,1," Full "); } if(count1<0) continue; }//while(1) }//main void introduction(void) { unsigned char i; Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,1," WELCOME "); Lcd_Out(2,1," SELAMAT DATANG "); delay_ms(2000); // Move text to the left 16 times for(i=0; i<16; i++) { Lcd_Cmd(_LCD_SHIFT_LEFT); delay_ms(250); } Lcd_Cmd(_LCD_CLEAR); Lcd_cmd(_LCD_CURSOR_OFF); } void displayLCD(int y) { char txt[7]; IntToStr(y,txt); Lcd_Cmd(_LCD_CLEAR); Lcd_Out(1,7,txt); Lcd_Out(1,1,"Occupant: ");
72 } void readSensor(void) { int j; for(j = 0 ; j < 10 ; j++) // take analog result for 10 times { s1_value = s1_value + ADC_Read(1); s2_value = s2_value + ADC_Read(2); } s1_value = s1_value/10; //get average s2_value = s2_value/10; if (s1_value>95) sensor1=0; //detect object else sensor1=1; //no object if (s2_value>95) sensor2=0; //detect object else sensor2=1; //no object } void readSensor3(void) { int j; for(j = 0 ; j < 10 ; j++) // take analog result for 10 times { s3_value = s3_value + AD
73 void calculateHight(void) { Vout=(s3_value*500000)/1024; if ((Vout > 43945)&&(Vout < 279785)) 2.8V = 8cm { Range_an=(Vout-19000)/2099; Range=1000/Range_an; Hight=210-Range; } } // read only from 0.