INTELLIGENT AQUARIUM SYSTEM CONTROL AHMAD BUDIMAN BIN OSMAN

INTELLIGENT AQUARIUM SYSTEM CONTROL AHMAD BUDIMAN BIN OSMAN A Dissertation Submitted To the Faculty of Electrical Engineering in Partial Fulfillmen...
Author: Justin Skinner
0 downloads 0 Views 2MB Size
INTELLIGENT AQUARIUM SYSTEM CONTROL

AHMAD BUDIMAN BIN OSMAN

A Dissertation Submitted To the Faculty of Electrical Engineering in Partial Fulfillment of the Requirements for the Award of the Degree of Bachelor of Engineering (Electrical – Electronic)

Faculty of Electrical Engineering Universiti Teknologi Malaysia

APRIL 2010

II

III

“SPECIAL DEDICATION TO MY FATHER, OSMAN BIN YUSOF, MY MOTHER, PARIDAH BINTI SULAIMAN AND ALSO MY SIBLINGS INTAN MUNIRAH, NURAININA, UMI KALSOM, AHMED MULYADI, SITI NASHUHA, NURUL SAKINAH NOT FORGETTING MY SUPERVISOR Mr. HAMID AND ALSO TO ALL MY FRIEND IN UTM”

Thank You.

IV

ACKNOWLEGMENT

This thesis is the result of two semester of work whereby I have been accompanied and supported by many people. It is a pleasant aspect that now I have the opportunity to express my gratitude for all of them. The first Person that I would like to thank is my supervisor Mr. Abd Hamid Ahmad. His guidance throughout a long path of journey while completing this undergraduate project has made a deep impression on me. I owe him lots of gratitude for

given advice about the thesis, besides providing support, guidance and encouragement in developing this project. I am also very grateful to my friends and especially family, who provided an additional and joyful dimension to this project. The chain of my gratitude would be definitely incomplete if I would forget to thank the cause of this chain, ALLAH, The Almighty.

V

ABSTRACT

The aim of this project is to build a prototype of a control system that can control water temperature, water level and lighting of an aquarium environment. Three of these aspects are a very important aspect to maintain a healthy aquarium. This project consists of hardware and software part. The hardware consists of a main board, a display board, a relay board and a power supply board. The software used in this project is MPLAB v 8.10 and MCC18 to write the microC language program. The brain of the system is PIC18F452 microcontroller. The microcontroller will process inputs from sensor system and subsequently controlled appropriate outputs. Initially the project will be implemented on breadboards. After each module is tested to verify its functionality, the whole circuit will be implemented on PCBs. Next the complete board will be assembled to the aquarium and connected to the pump, heater, fan and lamp. At the end of the project, the whole system will be able to functionally properly.

VI

ABSTRAK

Kajian ini pada umumnya bertujuan untuk membina sistem kawalan yang boleh mengawal suhu air, paras air dan cahaya persekiran akuarium. Ketiga-tiga aspek ini adalah penting untuk mengekalkan keadaan akuarium yang baik. Projek ini mengandungi perkakasan dan juga perisian. Bahagian perkakasan terdiri daripada papan utama, papan gambaran, papan relay dan juga papan sumber kuasa. Perisian yang digunakan di dalam projek ini ialah MPLAB v 8.10 dan MCC18, digunakan untuk menulis program didalam bahasa microC. Pengawal mikro PIC18F452 merupakan tunjang kepada sistem ini. Pengawal mikro akan memproses masukan daripada sistem pengesan dan juga menghasilkan keluaran yang dikehendaki. Pada mulanya projek ini dilaksanakan diatas breadboard. Seluruh litar akan dipateri diatas PCB board selepas itu setiap modul diuji untuk memastikan ia berfungsi dengan baik. Selepas itu litar yang telah siap dipateri akan dipasang pada akuarium dan juga disambungkan kepada pam, pemanas, lampu dan kipas. Projek ini boleh berfungsi sepenuhnya untuk mengawal ketiga-tiga aspek di akhir projek ini.

VII

TABLE OF CONTENTS

CHAPTER

1

TITLE

DECLARATION

ii

DEDICATION

iii

ACKNOWLEDGEMENT

iv

ABSTRACT

v

ABSTRAK

vi

TABLE OF CONTENT

vii

LIST OF TABLE

x

LIST OF FIGURE

xi

LIST OF APPENDIX

xiii

INTRODUCTION 1.1 1.2 1.3 1.4

2

PAGE

Objective Problem Statement Scopes of Project Methodology

1 2 2 3

LITERETURE REVIEW 2.1

Overview

5

2.2

Temperature

7

2.3

Lighting

8

VIII

3

2.4

water level

2.5

The component and Devise 2.5.1

Temperature Sensor (LM35)

9

2.5.2

Water Level Sensor (LM324)

11

2.5.3

Lighting sensor (LDR)

12

2.5.4

PIC18F452 Microcontroller

13

HARDWARE IMPLEMENTATION 3.1

Overview

25

3.2

Main board

26

3.2.1

Microcontroller – PIC 18F452

27

3.2.2

Temperature Sensor

29

3.2.3

Water Level Sensor

31

3.2.4

Lighting sensor

33

3.3

4

9

Display board

35

3.3.1

LCD 16x2

35

3.3.2

LED display and Buzzer

36

3.4

Relays board

36

3.5

Power Supply Board

38

SOFTWARE IMPLEMENTATION 4.1

Overview

40

4.2

MPLAB Software

41

IX

5

6

4.3

PICkit 2 v2.55 with USB ICSP PIC

45

4.4

System flowchart

47

4.5

Programming development

49

4.5.1

Initialization part

49

4.5.2

Main programming part

52

4.5.3

Subroutine part

54

RESULT AND DISCUSSION 5.1

Result

55

5.5

Testing process

56

5.6

Discussion

57

CONCLUSION AND RECOMMENDATIONS 6.1

Project Conclusion

59

6.2

Recommendation

60

REFFERENCE

62

APPENDIX Appendix A

64

Appendix B

82

Appendix C

83

X

LIST OF TABLES

TABLE

TITLE

PAGE

2.1

PIC18F452 Specification.

15

2.2

Capacitor Selection for Crystal Oscillator

19

5.1

Circuit voltage analysis

66

XI

LIST OF FIGURES

FIGURE

TITLE

PAGE

1.1

The block diagram of the system

4

2.1

The project design.

7

2.2

The LM35 package.

10

2.3

LM324 pin connection.

11

2.4

Light dependent resistor figure and symbol.

12

2.5

Graph resistance vs. Illumination.

12

2.6

Microcontroller PIC18F452 pin diagram.

14

2.7

PIC18F452 block diagram.

17

2.8

Crystal/Ceramic Resonator Operation

18

2.9

External Power-On reset Circuit

19

2.8

Program Memory Map and Stack for PIC18F452

20

2.9

Data Memory Map for Pic18f252/452

22

3.1

Project board

26

3.2

Main Board

26

3.3

PIC18F452 schematic circuit

28

XII

34

Temperature Sensor Schematic

29

3.5

Water level sensor schematic diagram.

32

3.6 3.7

LM324 pin connection. Lighting sensor circuit schematic.

32 33

3.8

Graph resistance vs. Illumination.

33

3.9

Display Board

35

3.10

3.10: LCD 16x2

35

3.11

LED display and buzzer

36

3.12

Relay board

36

3.13

SPDT relay circuit diagram

37

3.14

Power Supply Board

38

4.1

MPLAB window after done create a project

40

4.2

MPLAB window after add file.

41

4.3

MPLAB window after write the programming

42

4.4

MPLAB window when programming successfully builds.

43

4.5

MPAB window when programming unsuccessfully builds.

43

4.6

PIC kit2 software window before and after succesful download hex file

44

4.7

USB ICSP PIC programmer diagram

45

4.8

System flow chart

46

XIII

LIST OF APPENDIXES

APPENDIX A

TITLE Program in Microcontroller PIC 118F452 for Intelligent Aquarium System Control

PAGE 62

B

The picture of the LCD display with different output

82

C

The picture of devise used in this project

83

CHAPTER 1

INTRODUCTION

1.1

Objective of Project

The objective of this project is to build a prototype aquarium system that can detect, monitor and control three important aspects to maintaining a healthy aquarium. The prototype system will control water temperature water level and lighting hence the aquarium environment are always at normal condition for the fish in the aquarium.

2

1.2

Problem Statement

There are many important aspects inside the aquarium environment need to be controlled and three of the aspects are lighting, temperature and water level. Problem:  The factor why fish inside the aquarium always die because the fish owners do not care about the quality of aquarium environment.  Fish owners don’t have time to monitor water temperature, water level that is suitable for aquarium environment.  Fish owners don’t know how to control the parameter of aquarium

environment

that

are

suitable

for

aquarium

environment.

1.3

Scopes of Project

The scopes of this project are electronic component, electrical devise, computer software and mechanical design. The electronic components used in this project were PIC18F452 as a microcontroller, LM35 as a temperature sensor, light dependent resistor (LDR) as a lighting sensor, LM324N as a water level sensor, LCD 16x2, 5V relay and basic electronic component such as resistor, capacitor and others.

3

The electrical devices used in this project were pump, 200 watt heater, lamp and fan (12V). This project used microC language to program the microcontroller and MPLAB v8.10 as a compiler to create the source code and hex file for the microcontroller. Besides that Altium 2004 is used to design the circuit layout for the printed circuit board (PCB).

1.4

Methodology

This project can be divided to hardware and software. The hardware parts consist of four systems. The systems are monitoring system, control system, display system and output system. The monitoring system consists of temperature sensor circuit, water level sensor circuit and lighting sensor circuit. Temperature sensor will sense the water temperature inside the aquarium. The function of water sensor is to detect low water level inside main aquarium and reserve tank. Besides that the function of lighting sensor is to detect light intensity outside the aquarium. All sensors will send analog data to microcontroller. The Control System consists of PIC18f452 as a microcontroller, Crystal H49S 20MHz as oscillator, 5V regulator used to regulate high voltage to 5V, reset button and other basic components. The control systems functions to process data analog receive from monitoring system and send digital data to display system and output system.

4

The Display system consists of LCD 16x2, LED, Buzzer and push button. The LCD 16x2 has 2 rows and each row can display 16 characters. First row displays temperature value while second row displays the condition of the output. There are five LEDs used inside the display system. One of the LEDs wills ON if the pump is ON or the heater is ON or the lamp is ON or the fan is ON. Besides that the buzzer and the LED will ON if the water level inside reserve tank is low. There are two push button used to ON the pump and heater manually. The output system consists of relay circuits. There are four relay used to control the pump, the heater, the lamp and the fan. The control system will control the relay by sending 5V output to the relay. UIC00A USB ICSP PIC PROGRAMMER is used to download the hex file to the microcontroller.

Figure 1.1: The block diagram of the system

CHAPTER 2

LITERATURE REVIEW

2.1

Overview

The origins of aquarium keeping have been around for about as long as keeping food fishes, although the methodology and understanding of aquarium filtration has varied considerably. The first known formal study of fish was conducted by the Greek philosopher Aristotle (384-322 B.C.). Studying their structure and other characteristics, he carefully recorded accurate information on 115 species of fish then living in the Aegean Sea. Today, scientists have classified more than 20,000 species of fish around the world. Based on the works of Chemist Priestley and Zoologist Johnson, who realized the plant oxygen relation, Robert Warrington builds the first aquarium. His theory was, by building a glass structure filled with sand on the bottom, snails, and plants that can provide oxygen, fish can live forever. The plants would provide oxygen to the

6

fish, snails eat decaying plants and lay eggs, and the fish feed off of the snail eggs. The perfect contained cycle. From there on, the hobby flourished. Fueled by shorter transportation (air traffic was in its infant years), more and more breeders and the enthusiasts helped make the hobby more popular. The inventions and the understanding of water chemistry and fish within the past 30 years has enabled just about anyone to enjoy fish-keeping with little to no problems. According to book Common Fish Diseases by Lance Jepson and The Tropical Aquarium by Gina Sandford, both of these books discussed about the Aquarium environment. The contents include the aspects in aquarium environment, the importance of water quality and the effects of bad water quality to the fish. Temperature or Heat is important to drive fish metabolic process. If the temperature is too high enzymes will stop working and if too low the enzymes will damage. On average, most tropical aquariums do best with temperatures ranging from 26ºC to 29ºC. Aquarium not only consist fish but it also consists plant. Light is essential to promote healthy plant growth and allow you to see your fish. Fish inhale oxygen and exhale carbon dioxide. Water level also one of the important aspect. Fish inside the aquarium needs wide space to swim. If the space is too small space and many fish inside the aquarium, this situation can make the fishes stress and frightened at last the fish will die.

7

Figure 2.1: The project design.

2.2

Temperature

Fish are ectotherm, which means that they rely upon the heat that they absorb from their environment to drive their metabolic processes. Fish are surrounded by water and as they breathe they are constantly drawing water over their gills. This means that any heat generated by their metabolism is lost very quick to their environment; as a result the body temperature of a fish tends to be nearly the same as that of surrounding water. [1] True tropical fish are the majority of fresh water aquarium fish available in the hobby. Most of these are happy with a temperature range of 78ºF-84ºF (25.5ºC28.8°C). Temperature or heat is important to drive fish metabolic process. If the temperature is too high enzymes will stop working and if too low the enzymes will damage. Besides that in cold water, the tropical fish will lost their appetite and the fish parasites and bacteria tend to become active so it is danger to the fish health. As the

8

temperature increases, the solubility of oxygen in water will reduce and the metabolic rates of fish also increase to get more oxygen, hence the fish can die instantly because of lack of oxygen.

2.3

Lighting

Aquarium not only consists of fish but it also consists of plant. Light is essential to promote healthy plant growth and allow you to see your fish. Fish inhale oxygen and exhale carbon dioxide. Green plants are the only plants that produce oxygen and make food, which is called photosynthesis. Photosynthesis means ''putting together with light.'' This takes place in chloroplasts, which have chlorophyll in them. Chlorophyll absorbs the light. From light, green plants combine carbon dioxide and water to make sugar and oxygen. Green plants use sugar to make starch, fats, and proteins. There are tiny pores called stomata. Carbon dioxide and oxygen enter and leave through the stomata respectively. Plant will produce oxygen so lighting is important aspect that must be control by the user. [2]

9

2.4

Water level

For this project there are two water level been control. First was aquarium water level and second is reserve tank water level. Reserve tank water level contains pump that used to pump water from reserve tank to main aquarium. To prevent the pump from burn out is by create a system trigger alarm if the water inside the reserve water tank is empty and the pump will not turn on even though there are changes in the parameter until the reserve tank is fill by water.

2.5

The component and Devise

There are many component used in this project and each component has its own function. The device function can learn by read through the manual given.

2.5.1

Temperature Sensor (LM35)

Based on the LM35 Precision Centigrade Temperature Sensors manual by National Semiconductor Corporation, the LM35 series are precision integrated-circuit

10

temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in ° Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient centigrade scaling. [9] The LM35 does not require any external calibration or trimming to provide typical accuracies of ±1⁄4°C at room temperature and ±3⁄4°C over a full −55 to +150°C temperature range. The LM35’s low output impedance, linear output, and precise inherent calibration make interfacing to readout or control circuitry especially easy. It can be used with single power supplies, or with plus and minus supplies. As it draws only 60µA from its supply, it has very low self-heating, less than 0.1°C in still air. The LM35 is rated to operate over a −55° to +150°C temperature range, while the LM35C is rated for a −40° to +110°C range (−10° with improved accuracy).

Figure 2.2: The LM35 package.

The LM35 can be applied easily in the same way as other integrated-circuit temperature sensors. It can be glued or cemented to a surface and its temperature will be within about 0.01°C of the surface temperature. This project used plastic package TO-92 with LM35DZ type as a temperature sensor. The storage temperature for TO-92 is between -60ºC to +150ºC but the specified operating temperature range for this project is only for 0ºC to 100ºC. Output

11

range: 0.1V (-40°C) to 2.0V (150°C) but accuracy decreases after 125°C. Power supply: 2.7V to 5.5V only, 0.05 mA current draw. Formula to convert from output voltage to degree Celsius: Temp in °C = (Vout in mV) / 10

2.5.2

Water Level Sensor (LM324)

Based on Low Power Quad Operational Amplifiers STMicroelectronics group of companies, These circuits consist of four independent, high gain, internally frequency compensated operational amplifiers .They operate from a single power supply over a wide range of voltages. Operation from split power supplies is also possible and the low power supply current drain is independent of the magnitude of the power supply voltage. [10]

Figure 2.3: LM324 pin connection.

12

This project only used two from four operational amplifiers because there are only two water level sensors used. The water level sensor used for main aquarium and for reserve tank.

2.5.3

Lighting sensor (LDR – Light dependent resistor)

As its name implies, the Light Dependant Resistor is a resistive light sensor that changes its electrical resistance from several thousand Ohms in the dark to only a few hundred Ohms when light falls upon it. The net effect is a decrease in resistance for an increase in illumination. Materials used as the semiconductor substrate include, Lead Sulphide, (PbS) Lead Selenide, (PbSe) Indium Antimonide, (InSb) which detect light in the INFRARED range and the most commonly used of all is Cadmium Sulphide (Cds), as its spectral response curve closely matches that of the human eye and can even be controlled using a simple torch as a light source. Typically it has a peak sensitivity wavelength (λp) of about 560nm to 600nm in the visible spectral range.

13

Figure 2.4: Light dependent resistor figure and symbol.

Figure 2.5: Graph resistance vs. Illumination. 2.5.4

PIC18F452 Microcontroller

The 'general purpose' attribute of a Microcontroller is very significant, and shouldn't be overlooked. A general purpose Microcontroller is a very powerful tool that allows a designer to create a special purpose design. The design becomes partially hardware and partially software. There is great flexibility in the software end, as the designer can create practically unlimited variations on the design by changing the software. 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, but with a great deal of additional functionality combined onto the same monolithic semiconductor substrate. Microcontrollers, sometimes referred to as one-chip microcomputers, are used to control a wide range of electrical and mechanical appliances. [10] Microcontrollers are independently programmable and can have a great deal of additional functionality combined on the same integrated circuit. A typical microprocessor can access from a megabyte to a gigabyte of memory, and is capable of processing 16, 32, or 64 bits of information or more with a single instruction. In

14

contrast to the microprocessor, a microcontroller includes a central processing unit, memory and other functional elements, all on a single semiconductor substrate, or integrated circuit. A typical microcontroller might have a core microprocessor, a memory controller, an interrupt controller, and both asynchronous and synchronous serial interfaces. The advantage of a microcontroller as compared with a microprocessor is that the microcontroller can be used in an autonomous way. No external circuitry is needed for their operation. This is why their use is very widespread in relatively straightforward applications, such as in small electronic products. Microcontrollers have embedded logic units, memories, power sources, and other circuits. Powers on reset (POR) circuits are typically used in microcontrollers to initialize stable power states, ensuring that booting is accomplished safely. Within a microcontroller a central processing unit (CPU) having an arithmetic logic unit (ALU) and a load and store unit or a combination of both is located. The CPU is coupled through a bus with a memory to provide storage capacity for program instructions and data. Program and data memory can be separate with different bus lines or embodied in a single memory unit. The specific type of microcontroller that used in this project is a microcontroller from the Microchip Technology Incorporated which is PIC18F452. The PIC18F452 is used as controller system that will process data from monitoring system and also to control output to display system and output system. PIC18F452 is chosen because of the high performance and multifunction.

15

Figure 2.6: Microcontroller PIC18F452 pin diagram.

Table 2.1: PIC18F452 Specification. On-Chip Program Memory FLASH (bytes)

# Single Word

On-Chip RAM

Data EEPROM

(bytes)

(bytes)

1536

256

Instructions 32K

16384

Peripheral Features: 1. Three external interrupt pins 2. Timer0 module: 8-bit/16-bit timer/counter with 3. 8-bit programmable prescaler 4. Timer1 module: 16-bit timer/counter 5. Timer2 module: 8-bit timer/counter with 8-bit 8-bit programmable prescaler 6. Timer3 module: 16-bit timer/counter 7. Secondary oscillator clock option - Timer1/Timer3

16

8. Two Capture/Compare/PWM (CCP) modules. 9. CCP pins that can be configured as: 10. Capture input: capture is 16-bit, max. resolution 6.25 ns (TCY/16) 11. Compare is 16-bit, max. resolution 100 ns (TCY) 12. PWM output: PWM resolution is 1- to 10-bit, Max. PWM freq. @: 8-bit resolution = 156 kHz 13. 10-bit resolution = 39 kHz 14. High current sink/source 25 mA/25 mA

Analog Features: 1. Compatible 10-bit Analog-to-Digital Converter module (A/D) with: a.

Fast sampling rate

b.

Conversion available during SLEEP

c. DNL = ±1 LSb, INL = ±1 LSb 2.

Programmable Low Voltage Detection (PLVD) Supports interrupt on-Low Voltage Detection

3.

Programmable Brown-out Reset (BOR)

Special Microcontroller Features: 1. 100,000 erase/write cycle Enhanced FLASH program memory typical 2. 1,000,000 erase/write cycle Data EEPROM memory 3. FLASH/Data EEPROM Retention: > 40 years 4. Self-reprogrammable under software control 5. Power-on Reset (POR), Power-up Timer (PWRT) and Oscillator Start-up Timer (OST) 6. Watchdog Timer (WDT) with its own On-Chip RC Oscillator for reliable operation 7. Programmable code protection 8. Power saving SLEEP mode 9. Selectable oscillator options including: a. 4X Phase Lock Loop (of primary oscillator) b. Secondary Oscillator (32 kHz) clock input

17

10. Single supply 5V In-Circuit Serial Programming™ (ICSP™) via two pins 11. In-Circuit Debug (ICD) via two pins CMOS Technology: 1. Low power, high speed FLASH/EEPROM technology 2. Fully static design 3. Wide operating voltage range (2.0V to 5.5V) 4. Industrial and Extended temperature ranges

Figure 2.7: PIC18F452 block diagram.

18

2.5.4.1 Oscillator

There are eight different oscillator modes for the PIC18F452. Three configuration bits (FOSC2, FOSC1, and FOSC0) can be program by users. List of eight modes: 1. LP Low Power Crystal 2. XT Crystal/Resonator 3. HS High Speed Crystal/Resonator 4. HS + PLL High Speed Crystal/Resonator with PLL enabled 5. RC External Resistor/Capacitor 6. RCIO External Resistor/Capacitor with I/O pin enabled 7. EC External Clock 8. ECIO External Clock with I/O pinenabled

In XT, LP, HS or HS+PLL oscillator modes, a crystal or ceramic resonator is connected to the OSC1 and OSC2 pins to establish oscillation. Figure 2-1 shows the pin connections. The PIC18FXX2 oscillator design requires the use of a parallel cut crystal.

Figure 2.8: Crystal/Ceramic Resonator Operation

19

Table 2.2: Capacitor Selection for Crystal Oscillator

Ranges Tested: Mode

Freq

C1

C2

LP

32.0 kHz

33 Pf

33 pF

200 kHz

15 pF

15 pF

200 kHz

47-68 pF

47-68 pF

1.0 MHz

15 pF

15 pF

4.0 MHz

15 pF

15 pF

4.0 MHz

15 pF

15 pF

8.0 MHz

15-33 pF

15-33 pF

20.0 MHz

15-33 pF

15-33 pF

25.0 MHz

TBD

TBD

XT

HS

2.5.4.2 RESET

Most registers are unaffected by a RESET. Their status is unknown on POR and unchanged by all other RESETS. The other registers are forced to a “RESET state” on Power-on Reset, MCLR, WDT Reset, Brownout Reset, MCLR’ Reset during SLEEP and by the RESET instruction. The Enhanced MCU devices have a MCLR noise filter in the MCLR Reset path. The filter will detect and ignore small pulses. The MCLR pin is not driven low by any internal RESETS, including the WDT.

Figure 2.9: External Power-On reset Circuit

20

2.5.4.3 MEMORY ORGANIZATION

There are three memory blocks in Enhanced MCU devices. These memory blocks are Program Memory, Data RAM, and Data EEPROM. PIC18F452 have 32 Kbytes of FLASH memory. This means that PIC18F452 devices can store up to 16K of single word instructions, the RESET vector address is at 0000h and the interrupt vector addresses are at 0008h and 0018h. Figure 2.10 shows the Program and Stack for PIC18F452.

Figure 2.10: Program Memory Map and Stack for PIC18F452.

21

The data memory is implemented as static RAM. Each register in the data memory has a 12-bit address, allowing up to 4096 bytes of data memory. The data memory map is divided into as many as 16 banks that contain 256 bytes each. The lower 4 bits of the Bank Select Register (BSR) select which bank will be accessed. The upper 4 bits for the BSR are not implemented. The data memory contains Special Function Registers (SFR) and General Purpose Registers (GPR). The SFRs are used for control and status of the controller and peripheral functions, while GPRs are used for data storage and scratch pad operations in the user’s application. The SFRs start at the last location of Bank 15 (0xFFF) and extend downwards. Any remaining space beyond the SFRs in the Bank may be implemented as GPRs. GPRs start at the first location of Bank 0 and grow upwards. Any read of an unimplemented location will read as ’0’s. The entire data memory may be accessed directly or indirectly. Direct addressing may require the use of the BSR register. Indirect addressing requires the use of a File Select Register (FSRn) and a corresponding Indirect File Operand (INDFn). Each FSR holds a 12-bit address value that can be used to access any location in the Data Memory map without banking. The instruction set and architecture allow operations across all banks. This may be accomplished by indirect addressing or by the use of the MOVFF instruction. The MOVFF instruction is a two-word/two-cycle instruction that moves a value from one register to another.

22

Figure 2.11: Data Memory Map for Pic18f252/452

2.5.4.4 Flash Program Memory

The FLASH Program Memory is readable, writable, and erasable during normal operation over the entire VDD range. A read from program memory is executed on one byte at a time. A write to program memory is executed on blocks of 8 bytes at a time. Program memory is erased in blocks of 64 bytes at a time. A bulk erase operation may not be issued from user code.

23

Writing or erasing program memory will cease instruction fetches until the operation is complete. The program memory cannot be accessed during the write or erase, therefore, code cannot execute. An internal programming timer terminates program memory writes and erases. A value written to program memory does not need to be a valid instruction. Executing a program memory location that forms an invalid instruction results in a NOP.

2.5.4.5 Interrupt

The PIC18F452 devices have multiple interrupt sources and an interrupt priority feature that allows each interrupt source to be assigned a high priority level or a low priority level. The high priority interrupt vector is at 000008h and the low priority interrupt vector is at 000018h. High priority interrupt events will override any low priority interrupts that may be in progress.There are ten registers which are used to control interrupt operation. These registers are: RCON, INTCON, INTCON2, INTCON3, PIR1, PIR2, PIE1, PIE2, IPR1, and IPR2. The interrupt priority feature is enabled by setting the IPEN bit (RCON). When interrupt priority is enabled, there are two bits which enable interrupts globally. Setting the GIEH bit (INTCON) enables all interrupts that have the priority bit set. Setting the GIEL bit (INTCON) enables all interrupts that have the priority bit cleared. When the interrupt flag, enable bit and appropriate global interrupt enable bit are set, the interrupt will vector immediately to address 000008h or 000018h, depending on the priority level. Individual interrupts can be disabled through their corresponding enable bits.

24

When an interrupt is responded to, the Global Interrupt Enable bit is cleared to disable further interrupts. If the IPEN bit is cleared, this is the GIE bit. If interrupt priority levels are used, this will be either the GIEH or GIEL bit. High priority interrupt sources can interrupt a low priority interrupt. The return address is pushed onto the stack and the PC is loaded with the interrupt vector address (000008h or 000018h). Once in the Interrupt Service Routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. The interrupt flag bits must be cleared in software before re-enabling interrupts to avoid recursive interrupts. The “return from interrupt” instruction, RETFIE, exits the interrupt routine and sets the GIE bit (GIEH or GIEL if priority levels are used), which re-enables interrupts. For external interrupt events, such as the INT pins or the PORTB input change interrupt, the interrupt latency will be three to four instruction cycles. The exact latency is the same for one or two-cycle instructions. Individual interrupt flag bits are set, regardless of the status of their corresponding enable bit or the GIE bit.

CHAPTER 3

HARDWARE IMPLEMENTATION

3.1

Overview

This project consists of main board, display board, relay board and power supply board. Each board has their own function and works as one system when all board are combined. Main board consists of microcontroller, temperature sensor, water level sensor and lighting sensor. Display board consists of LCD 16x2, LED and push button. Relay board consists of relay circuit and the last board was power supply board consists of 5V regulator and AC-DC converter.

26

Figure 3.1: Project board

3.2

Main board Main board is the heart of overall project that function as a monitoring

system and control system. The main board will control output interface and display interface and also to process data receive from sensor interface circuit.

Figure 3.2: Main Board

27

The board consists of: 1.

PIC18F452 as a microcontroller

2.

temperature sensor circuit

3.

water level sensor circuit

4. Lighting sensor circuit.

3.2.1

Microcontroller – PIC 18F452

Microcontroller is the controlling system that will control the whole operation. The data received from monitoring system like voltage from temperature sensor, water level sensor and lighting sensor will be connected to the microcontroller input. Relay for the pump, the heater, the lamp and the fan also will be connected to the microcontroller output. Besides that LCD 16x2, LED and push button also connected to the microcontroller output. Figure 3.1 shows the connection of input and output into the microcontroller. The basic circuits for the microcontroller are crystal oscillator and reset switch. This project used 20MHz crystal oscillator to produce high frequency and give the best performance. There are 4MHz internal crystal oscillator built inside the microcontroller; hence the total crystal oscillation is 80MHz. The push button reset switch is used to reset the whole system with the latest memory are stored at the RAM.

28

Figure 3.3: PIC18F452 schematic circuit

Based on figure 3.1, the water temperature sensor, aquarium water level sensor, extra tank water level sensor and lighting sensor are connected to PORTA (RA0, RA1, RA2 and RA5) as an input to the microcontroller. PORTA function as an analog-digital converter that will convert the analogue to digital signal before it can be processed by the microcontroller. RA3 is used as a voltage reference for analogue to digital converter which is used to get full scale value for the input. LCD 16x2 pins (DB0, DB1, DB2, DB3, DB4, DB5, DB6, DB7, E and RS) are connected to PORTC (RC0, RC1, RC2, RC3, RC4, RC5, RC6, RC7) and PORTD (RD0 and RD1). Besides that PORTB (RB0, RB1, RB2, and RB3) are connected to LED pump, LED heater, LED lamp and LED light. While, PORTB (RB4, RB5, RB6, and RB7) are connected to relay pump, relay heater, relay lamp and relay fan. Buzzer, LED heater, push button heater and push button pump manually are connected to PORTD (RB4, RB5, RB6, and RB7).

29

3.2.2

Temperature Sensor

The LM35 series are precision integrated-circuit integrated circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigra (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in ° Celsius. The circuit for temperature sensor circuit consist LM35DZ and 0.1uF capacitor. The function of capacitor is to reduce the ripple voltage so the voltage will be stable. Microcontroller need stable voltage to convert voltage to digital value for system operation. Unstable voltage value can decrease efficiency of analog-digital analog converter.

RA0

Figure 3.4: Temperature Sensor Schematic Based on the Figure F 3.2; simply connect the left pin to power (2.7-5.5V) (2.7 and the right pin to the ground. Then the middle pin will have an analog voltage that is directly proportional (linear) to the temperature. The analog voltage is independent of the power supply. LM35 LM35 will send data to the PIC microcontroller in voltage then the PIC will convert to degree Celsius using below formula. Temp in °C = (Vout in mV) / 10

30

Testing these sensors is pretty easy but you'll need a battery pack or power supply. Connect a 2.7-5.5V power supply (2-4 AA batteries work fantastic) so that ground is connected to pin 3 (right pin), and power is connected to pin 1 (left pin) Then connect your multimeter in DC voltage mode to ground and the remaining pin 2 (middle). If you've got a TMP35 and it’s about room temperature (25°C), the voltage should be about 0.25V. You can change the voltage range by pressing the plastic case of the sensor with your fingers; you will see the temperature/voltage rise. Or you can touch the sensor with an ice cube, preferably in a plastic bag so it doesn't get water on your circuit, and see the temperature/voltage drop. The microcontroller was programmed based on this analysis. Temperature sensor will give different value data to the microcontroller depends on environment temperature. The formula will be set to the programming; hence the data received from temperature will be processed by the microcontroller and then the temperature value displayed at LCD 16x2. Microcontroller will set the normal temperature ranges that are suitable to tropical fish. The temperature range is between 25ºC to 29ºC. Hence if the temperature sensed from the temperature sensor is greater than 29ºC the microcontroller output that control the fan the and pump relay will trigger, hence fan and pump will ON to cool down the water temperature until the temperature are between the normal range. Beside that if the temperature sensed from temperature sensor is less than 25ºC the microcontroller output that control heater relay will trigger, hence heater will turn ON to heat up the water temperature until the water temperature are between the normal ranges.

31

3.2.3

Water Level Sensor

For this project there are two water levels. First was aquarium water level and second is reserve tank water level. Reserve tank water level contains pump that used to pump water from reserve tank to main aquarium. To prevent the pump from burn out the system will trigger alarm if the water inside the reserve water tank is empty and the pump will not turn on even though there are changes in the parameter until the reserve tank is filling by water. Figure 3.3 show water level sensor schematic circuit. Water level sensor used comparator LM324 (low power quad operational amplifiers). If water sensor probe detect water then the voltage output from LM324 to the PIC is 0V. While, if water sensor probe do not detect water then the voltage from LM324 to the PIC is about 3.8V. From the analysis there are two different voltages, 3.8V (sensor probe do not sense water) and 0V (sensor probe sense water). [4] The microcontroller was programmed based on this analysis. When microcontroller sense 0V (sensor probe sense water) from water level sensor output, the microcontroller output that control relay pump will not trigger hence the pump will OFF. Besides that when microcontroller sense value other then 0V (sensor probe do not sense water) from water level sensor output, the microcontroller output that control relay lamp will trigger hence the pump will ON.

32

Figure 3.5: Water level sensor schematic diagram.

Figure 3.6: LM324 pin connection.

33

3.2.4

Lighting sensor

The operation of lighting sensor is based on LDR (Light Dependent Resistor). Light Dependant Resistor is a resistive light sensor that changes its electrical resistance from several thousand Ohms in the dark to only a few hundred Ohms when light falls upon it.

Figure 3.7: Lighting sensor circuit schematic.

Figure 3.8: Graph resistance vs. Illumination.

34

Figure 3.5 shows the lighting sensor schematic diagram which consists of LDR and 100K ohm resistor. Vout can be calculated using below formula:

Based on the formula Rbottom are equal to 100K ohm and Rtop are to LDR resistance and Vin is equal to 5V. Figure 3.6 show the Graph resistance vs. Illumination, Illumination mean light brightness. Base on the graph the resistance of LDR becomes higher when the Illumination low or the environment becomes dark. Hence Rtop value will approximately to infinity when the environment becomes dark, so the value of Vout becomes 0V. When the environment are bright the value of Rtop are equal to 10 ohm to 100K ohm depends on the illumination value, hence the value of Vout equal to 2.5V to 5V. The microcontroller was programmed based on this analysis. When microcontroller sense 0V (environment are dark) from lighting sensor output, the microcontroller output that control relay lamp will trigger hence the lamp will ON. Beside that when microcontroller sense value other then 0V (environment are bright) from lighting sensor output, the microcontroller output that control the relay lamp will not trigger hence the lamp will be OFF.

35

3.3

Display board

Display board consists of LCD 16x2, LED and push button. The functions of display board are to display the value of water temperature and the relay condition either the devise ON or OFF. Beside that the display board also consist LEDs that will ON if the devise in ON. The function of push button is to ON heater and pump manually.

Figure 3.9: Display Board

3.3.1

LCD 16x2

36

Figure 3.10: LCD 16x2

This project used LCD 16x2 as a display system. The LCD 16x2 has two rows and each row can display 16 characters. First row will display temperature value sensed by temperature sensor while second row will display the condition of the output, for example if the pump is ON the display on 2nd row is pump ON, if heater and light is ON then the 2nd row will display heater and light ON.

3.3.2

LED display and Buzzer

Figure 3.11: LED display and buzzer

37

There are 5 LEDs used in this project as a LED display and one buzzer. Red LED and buzzer will turn ON when the microcontroller sense low water level inside the extra tank. These results as a warning to users that the system will not precede until the extra tank filled with water. Four more LED used to show the users that which devices are turned ON, either pump, heater, lamp or fan.

3.4

Relays board

Figure3.12: Relay board This project used 5V single pole double throw (SPDT) relay to interface between microcontroller and pump, heater, lamp and fan. Pump, heater and lamp used 240V supply. Based on figure3.12 relay is a device consisting of a coil of wire wrapped around an iron core. When electricity is applied to the coil of wire it becomes magnetic, hence the term electromagnet applied. The pin1, 2 and 3 are an SPDT switch controlled by the electromagnet. When electricity is applied to pin4 and pin5, the electromagnet acts upon the SPDT switch so that the pin3 and pin1 are connected. When the electricity is disconnected, then the pin2 and pin1 are connected. It is important to note that the electromagnet is magnetically linked to the switch but the two are NOT linked electrically, hence this can avoid any harm to the microcontroller.

38

Figure 3.13: SPDT relay circuit diagram Figure 3.12 shows the schematic diagram for SPDT relay. Based on the figure pin no.4 connect to 5V Vcc, pin no 5 connect to transistor 2N4401, pin no. 1 and 3 connect to device circuit such as pump, heater, lamp and fan. Relay circuit used the transistor because the current from microcontroller is not enough to trigger on the relay, hence the transistor act as current amplifier that will gain the current from microcontroller.

3.5

Power Supply Board

39

Figure 3.14: Power Supply Board

This project used 5v and 12V regulator to regulate 5V and 12V voltage from AC-DC converter that supply 15V. 5V power supply connected to main board, display board and relay board. 12V power supply was connected to fan.

CHAPTER4

SOFTWARE IMPLEMENTATION

4.1

Overview

Software implementation is the important part of this project and takes the longest period of analysis and research. The software used in this project is MPLAB v 8.10 with MCC18 to write microC language program. The software will convert the microC language to HEX file that can be read by the microcontroller. This project used PIC 18F452 as a microcontroller, hence the configuration are different from other PIC. The system program divided to configuration, main program and subroutine program. The configuration consists of include, define, configure and function prototype. The Main program consists of system function, while subroutine program consists of subroutine LCD setting, subroutine ADC and subroutine DELAY.

41

4.2

MPLAB Software

This project used MPLAB version 8.10 to compile MicroC language to hex file. Besides that, this software also needs to be installed with C18 because MPLAB alone cannot create PIC18F452 program using MicroC language. First, create project using project wizard. After that choose the type of PIC to be program, this project used PIC18F452. Then save the project at any directory place. Figure 4.1 show the MPLAB window after done setting the project.

Figure 4.1: MPLAB window after done create a project

42

Add linker file and library file from folder MCC18 to linker script and library file at MPLAB lab. After that, add Header file from MPLAB libraries to header files. All this files are compulsory because the programming need those files to complete build the project programming. Figure 4.2 shows the MPLAB window after add require file.

Figure 4.2: MPLAB window after add file.

After done setting and add compulsory files, write the project programming in MicroC language and save the file as source file. Figure 4.3 shows the MPLAB window after write the project programming.

43

Figure 4.3: MPLAB window after write the programming

Build the project to see either the programming successful or unsuccessful. The output window will display at output window ‘build succeeded’ if there are no error and the display ‘build failed’ if there are error. Figure 4.4 shows the MPLAB window if the programming successfully programmed and figure 4.5 shows the MPLAB window if the programming unsuccessfully programmed.

44

Figure 4.4: MPLAB window when programming successfully builds.

Figure 4.5: MPAB window when programming unsuccessfully builds.

45

The MPLAB will automatically create a hex file after the programming successfully builds. The hex file then downloaded into the PIC18F452 using PICkit 2 v2.55 software.

4.3

PICkit 2 v2.55 software with USB ICSP PIC Programmer

This project used PICkit 2 v2.55 software to download the hex file project into the PIC18F452. The USB ICSP PIC programmer used to interface between PIC18F452 with the software PICkit 2 v2.55. Figure 4.6 show the PICkit2 Programmer window before and after succesful download hex file.

Figure 4.6: PIC kit2 software window before and after succesful download hex file

46

Figure 4.7: USB ICSP PIC programmer diagram

Figure 4.7 shows the USB ICSP PIC programmer diagram. The function of this USB ICSP PIC programmer is to download hex file from computer to the microcontroller.

47

4.4

System flowchart

Figure 4.8: System flow chart

48

Figure 4.6 shows the Intelligent Aquarium System control flow chart. From the figure the system starts when the power is turned ON. After the system starts, the system will read the data received from the temperature sensor, the water level sensor and the lighting sensor. First the system will check if the manually push button pump has been triggered or not. If the push button was trigger the pump will on but if not the pump will OFF. After that the system check if the manually push button heater is trigger or not. If the push button was trigger the heater will ON but if not the heater will OFF. Next the system will process the data send from lighting sensor. If the environment is dark the system will turn ON lamp but if the environment is bright the system will turn off the lamp. After that, the system process data from ETWL or extra tank water level sensor. If the system detects no water then the system will turn on alarm and the system will not proceed to next function until the ETWL sensor sense water inside extra tank. As a protection system, this function will avoid pump inside extra tank from burn off. The pump will burn off if the pump is turn ON without water. If the water inside the extra tank is still at required level, the system will proceed to next function. The next function is the system will process data from AWL sensor or aquarium water level sensor. If the AWL is low, the system will turn on pump to pump water from extra tank to main aquarium but if the AWL is normal the system proceed to next function. Next the system will process data from temperature sensor. If the temperature is greater than 29ºC the system will turn ON the pump and the fan but if the temperature is less than 29ºC the system will proceed to next function. The next function is if the temperature is less than 26ºC the system will turn ON heater but if the temperature is greater than 26ºC the system will turn OFF pump and heater. Next the system will back to the initial system.

49

4.5

Programming development

The programming development process is divided into 3 parts, first is Initialization part second is the main part and last is subroutine part. The whole part is connected with each other to become one successful system that can automatically maintain the environment as required.

4.5.1

Initialization part

Initialization part is to declare all function and port for the microcontroller. Initialization part can be divided into 4 parts. First part is ‘include’, the function of this part is to include others file. This project used pic18f452 header file.

//==================include================================= #include //========================================================

Second part is ‘configuration’; the function of configuration is to declare four configuration of PIC18452. The first configuration is OCS or Oscillator Selection. This project used HS or High Speed Oscillator.

50 Oscillator Selection: OSC = LP

LP

OSC = XT

XT

OSC = HS

HS

OSC = RC

RC

OSC = EC

EC-OSC2 as Clock Out

OSC = ECIO

EC-OSC2 as RA6

OSC = HSPLL

HS-PLL Enabled

OSC = RCIO

RC-OSC2 as RA6

Second configuration is WDT or watch dog timer. This project does not use WDT, hence the configuration is OFF. Third configuration is LVP or low voltage programming. This project does not use LVP, hence the configuration is OFF. The fourth configuration is BOR or brown out reset. This project does not used BOR, hence the configuration is OFF.

//===============configuration============================== #pragma config OSC = HS #pragma config WDT = OFF #pragma config LVP = OFF #pragma config BOR = OFF //========================================================

The third part is ‘define IO port’; the function of this part is to declare the input and the output used for this project. It is important to make sure all port comment with the function of the port to make sure no error be done.

51

//===============define IO port============================= #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define

lcd RS E CHANNEL0 CHANNEL1 CHANNEL2 CHANNEL4 ledA ledB ledL ledF pump heater lighting fan pinA pinB ledW buzzer

PORTC LATDbits.LATD0 LATDbits.LATD1 0b10000001 // AN0 0b10001001 // AN1 0b10010001 // AN2 0b10100001 // LATBbits.LATB7 // pump LATBbits.LATB6 // LED heater LATBbits.LATB5 //LEDLighting LATBbits.LATB4 //LEDfan LATBbits.LATB3 //PUMP RELAY LATBbits.LATB2 //HEATER RELAY LATBbits.LATB1 //LIGHTING REALY LATBbits.LATB0 // FAN RELAY PORTDbits.RD7 //on pump manual PORTDbits.RD6 //on heater manual LATDbits.LATD5 //buzzer LATDbits.LATD4 //LED warning

AN4

//========================================================

The forth part is ‘functions prototype’; the function of this part is to allows better control over argument number and type checking, and type conversions. A given function can be defined only once in a program, but can be declared several times, provided the declarations are compatible. If you write a no defining declaration of a function, i.e. without the function body, you do not have to specify the formal arguments. //==============FUNCTION PTOTOTYPE========================= void e_pulse(void); void delay(unsigned short i); void send_char(unsigned char data); void send_config(unsigned char data); void lcd_goto(unsigned char data); void lcd_clr(void); void dis_num(unsigned long data); void increment(unsigned long data); void read_adc(void); void read_adc2(void);

52

void read_adc3(void); unsigned short read_temp(void); unsigned short read_level(void); unsigned short read_level2(void); unsigned short read_light(void); void beep(void); void alarm(void); unsigned short result; unsigned short temp,tempA,level,level2,levelA, levelB,light; //========================================================

4.5.2

Main programming part The function of this part is to write the system function based on flow chart.

Below is a part of the main program. Full program can be seen at appendix. From the below programming each microcontroller port must be declared either as an input or output. All detail has been discussed in chapter 2.5.3 about PIC microcontroller.

//====================MAIN================================ unsigned short result; unsigned short temp,tempA,level,level2,levelA,levelB,light; void main(void) { ADRESH=0; //clear A/D result ADRESL=0; //clear A/D result //setting ADCON1 Register ADCON1=0b11000011; // configure port TRISA=0b11111111; //configure PORTA I/O direction TRISB=0b00000000; //configure PORTB as output TRISC=0b00000000; //configure PORTC as output TRISD=0b11000000; TRISE=0b00000000; PORTA=0;

53

PORTB=0; PORTC=0; PORTD=0; PORTE=0; while(1)

//infinity loop

{ //sensor temperature ADCON0=CHANNEL0; //CHANNEL0=0b10000001 lcd_goto(8); read_adc(); temp=read_temp(); dis_num(temp/10); send_char('.'); dis_num(temp%10); send_char(0b11011111); send_char('C'); tempA=temp; //sensor water level ADCON0=CHANNEL1;

//CHANNEL1=0b10001001

read_adc2(); level=read_level(); levelA=level; //sensor water level extra aquarium ADCON0=CHANNEL2; //CHANNEL2=0b10010001 read_adc3(); level2=read_level2(); levelB=level2; //lighting sensor ADCON0=CHANNEL4; //CHANNEL2=0b10010001 read_adc(); light=read_light(); //========================================================

54

4.5.3 Subroutine part

Subroutine means a set of instructions that performs a specific task for a main routine, requiring direction back to the proper place in the main routine on completion of the task and is relatively independent of the remaining code. There are three part of subroutine. The first part is subroutine for ‘LCD setting’. This part is the subroutine place where the LCD data is processed and the result will be sent back to the main routine. Second part is the subroutine for ‘ADC’ or analog digital converter. The function of this part is to convert the analog data received from the temperature sensor, the water level sensor and the lighting sensor to digital data that can be processed by microcontroller. The third part of the subroutine is ‘delay’. The whole programming shown at appendix A.

CHAPTER 5

RESULT AND DISCUSSION

5.1

Result

The prototype of Intelligent Aquarium System Control has been able successfuling detect, monitor and control water temperature, water level and environment lighting to maintain a healthy aquarium. There are three sensor used in this project, temperature sensor, water level sensor and lighting sensor. All sensors are running properly. The controller system for this project was PIC18F452. This project successfully program the microcontroller that can control all sensors as an input and also control the output such as LCD 16x2, LED, buzzer, pump, heater, lamp and fan. This project also successfully displays the environment temperature value at first row and also displays the output condition at second row. The output conditions

56

that have been displayed are HEATER ON, PUMP ON and FAN ON. If there are two devices ON then the LCD will display both devise, for example PUMP & FAN ON.

5.2

Testing process There are several method used in this project. One of the methods is by using

multi meter to check the value of voltage and resistance. The entire sensors used in this project are mostly controlled by the voltage output. The output voltage for temperature sensor is linearly proportional to the Celsius (Centigrade) temperature. Hence the environment temperature can be analyzed by using multi meter. The voltage output for water level sensor and lighting sensor is analyzed by using multi meter. Others method is using the proto board to testing and analyzed all the circuit one by one before the circuit had been soldered on stripe board and PCB board. The method for testing programming development is by using MPLAB project that can locate the program error.

Circuit

Output (dc-voltage)

Temperature sensor (LM35) •

Ice (0ºC)

0V



Boil water (100ºC)

1V

Water Sensor •

Sense water



Sense no water

0V 3.8V

Lighting Sensor •

Dark environment

0V



Bright environment

2V-4V

57

Push button •

Closed circuit (PUSH)

0V



Open circuit (normal)

5V

Microcontroller output •

Data logic 1

4.7V



Data logic 0

0V Table 5.1: Circuit voltage analysis

5.3

Discussion The first stage of this project is to analyze all the sensor circuit to get the

sensor characteristic using proto board and multi meter. After the entire sensor analyzed, the project proceed to next stage. The next stage is software development; based on the analysis the project programming can be designed. After designed the project programming, the programming was tested by using MPLAB software. This one of the method used to testing either the program is successful or not. If there are errors in the programming the MPLAB software will locate the errors, then the error can be fixed either directly or by checking the problem using help library. After successfully build and compile the project programming, the project proceed to next stage which the programming was tested on the microcontroller PIC18F452. The hex file created by MPLAB downloaded into the PIC18F452 using PIC kit2 v2.55 software. The USB ICSP PIC programmer used to interface between PIC18F452 with the software PIC kit2 v2.55. The PIC18F452 that already downloaded with the hex file, was tested using proto board and multi meter. The microcontroller will interface with all sensors, LCD and the relay circuit to test either the project programming practically successful or not.

58

After the microcontroller circuit on proto board successfully process the data from sensor circuit and control the output, the circuits are ready to be soldered at stripe board and PCB board. After done solder all the circuit, once again all the circuit will be tested. If there are problem, the circuit will be troubleshoot by using multi meter. The project is successfully done when all the sensor work properly based on characteristic.

CHAPTER 6

CONCLUSION AND RECOMMENDATIONS

6.1

Project Conclusion

Based on chapter 1, the objective of this project was to build a prototype aquarium system that can detect, monitor and control three important aspects to maintaining a healthy aquarium. The prototype system will control water temperature; water level and lighting hence the aquarium environment are always at normal condition for the fish in the aquarium. This project has successfully accomplished the objective. The complete prototype successfully detects the environment temperature, detect water level and also detect the environment lighting. Besides that the complete prototype successfully displays the environment temperature value using the LCD 16x2. The project also successfully control the aquarium environment, if the temperature is greater than 29ºC, the system will turn ON fan and pump to cool down the aquarium water temperature until the temperature back to normal. Besides that if the temperature lowers than 26 ºC the system will turn ON heater to heat the aquarium

60

water until the temperature back to normal. The system also will turn ON pump if the water level inside the aquarium is low. The project also successfully protects the pump from any harm because if the water inside the extra tank water level is low, the system will display warning on the LCD and alarm turned ON. The system will not proceed any function until the extra tank filled back with water. The project also successfully on the lamp if the aquarium environment become dark. The successful environment controlled by this prototype will help users to take care about the aquarium environment and indirectly help to maintain the aquarium health. Besides that this project also helps users that do not have time to take care their aquarium. This project is quite tough for me because most of the works done are new for me. Most of the time spent to read, understand and make a research about the sensor and the microcontroller. Nearly one semester was taken to design the project structure and make an analysis about the required system. After understand the project system, the next adventure is to implement the hardware development. Moreover, most of the components used to build this project are costly.

6.2

Recommendation

Even though this project is successfully built, many improvement can be done in order to maximize the aquarium usage so many problem face by user can be solve. There are many aspects to maintain healthy aquarium. This project only can control three aspects there are water temperature, water level and lighting. Others important aspect that should be control is water pH dissolve oxygen, ammonia concentration and nitrate concentration. Beside that more gadgets should build to

61

easier the aquarium users such as automatic fish feeder, automatic aquarium cleaner and many more.

62

REFERENCES

1.

Lance Jepson. Common Fish Diseases. Neptune City: T.F.H Publications INC, 2004. 23-27.

2. Gina sandford. The tropical Aquarium. Surrey London: Interpet Publishing, 2004. 29-36

3. Shahrul Bahrin Bin Mohd Yassin. Smart Aquarium. Using PIC. Degree. Thesis. Universiti Teknologi Malaysia; MEI 2006.

4. Izatu Tumiran. Environment Control for an Aquarium. Degree. Thesis. Universiti Teknologi Malaysia; MEI 2006.

5. Siti, H.R., Puspa, I.K., Ismawati, A.G.. Electronik 2. 3rd. ed. Johor Malaysia: Muapakat Jaya Percitakan. 2003.

6. Rubita, S., Puspa, I.K, Siti, H.R., Peranti Elektronik. Selangor Malaysia: Prentice Hall. 2007.

7. Johari, K., Abdul, H.A., camallil, O., Sistem Elektronik. Johor Malaysia: Muapakat Jaya Percitakan. 2006.

63

8. Microchip Technology Inc. “PIC18F452 Data Sheet” Americas: Data Sheet. 2001.

9. National Semiconductor Corporation LM35 Precision Centigrade Temperature Sensors. Americas: Data Sheet. November 2000.

10. STMicroelectronics LM324 Low power quad Operational amplifiers. Italy: Data Sheet. June 1999.

64

APPENDIX A

//=====================include================================= #include //===================configuration============================== #pragma config OSC = HS #pragma config WDT = OFF #pragma config LVP = OFF #pragma config BOR = OFF //===============define IO port============================= #define lcd PORTC #define RS LATDbits.LATD0 #define E LATDbits.LATD1 #define CHANNEL0 0b10000001 // AN0 #define CHANNEL1 0b10001001 // AN1 #define CHANNEL2 0b10010001 // AN2 #define CHANNEL4 0b10100001 // AN4 #define ledA LATBbits.LATB7 // pump #define ledB LATBbits.LATB6 // LED heater #define ledL LATBbits.LATB5 // LED Lighting #define ledF LATBbits.LATB4 // LED fan #define pump LATBbits.LATB3 //PUMP RELAY #define heater LATBbits.LATB2 //HEATER RELAY #define lighting LATBbits.LATB1 // LIGHTING REALY #define fan LATBbits.LATB0 // FAN RELAY #define pinA PORTDbits.RD7 //on pump manual #define pinB PORTDbits.RD6 //on heater manual #define ledW LATDbits.LATD5 //buzzer #define buzzer LATDbits.LATD4 //LED warning //==============FUNCTION PTOTOTYPE========================= void e_pulse(void); void delay(unsigned short i); void send_char(unsigned char data); void send_config(unsigned char data); void lcd_goto(unsigned char data); void lcd_clr(void); void dis_num(unsigned long data); void increment(unsigned long data); void read_adc(void); void read_adc2(void); void read_adc3(void);

65

unsigned short read_temp(void); unsigned short read_level(void); unsigned short read_level2(void); unsigned short read_light(void); void beep(void); void alarm(void); //====================MAIN================================ unsigned short result; unsigned short temp,tempA,level,level2,levelA, levelB,light; void main(void) { ADRESH=0; ADRESL=0; ADCON1=0b11000011; TRISA=0b11111111; TRISB=0b00000000; TRISC=0b00000000; TRISD=0b11000000; TRISE=0b00000000; PORTA=0; PORTB=0; PORTC=0; PORTD=0; PORTE=0;

//clear A/D result //clear A/D result //setting ADCON1 Register //configure PORTA I/O direction //configure PORTB as output //configure PORTC as output

while(1) { send_config(0b00000001); //clear display at lcd send_config(0b00000010); //Lcd Return to home send_config(0b00000110); //entry mode-cursor increase 1 send_config(0b00001100); //diplay on, cursor off and cursor blink off send_config(0b00111000); //function set while(1)

//infinity loop

{ //sensor temperature ADCON0=CHANNEL0; lcd_goto(8); read_adc(); temp=read_temp();

//CHANNEL0=0b10000001

66

dis_num(temp/10); send_char('.'); dis_num(temp%10); send_char(0b11011111); send_char('C'); tempA=temp; //sensor water level ADCON0=CHANNEL1; //CHANNEL1=0b10001001 read_adc2(); level=read_level(); levelA=level; //sensor water level extra aquarium ADCON0=CHANNEL2; //CHANNEL2=0b10010001 read_adc3(); level2=read_level2(); levelB=level2;

//lighting sensor ADCON0=CHANNEL4; //CHANNEL2=0b10010001 read_adc(); light=read_light(); if((pinA==0)) { lcd_goto(20); send_char(' '); send_char('P'); send_char('U'); send_char('M'); send_char('P'); send_char(' '); send_char('O'); send_char('N'); ledA=1; ledB=0; ledL=0;

67

ledF=0; pump=1; heater=0; lighting=0; fan=0; buzzer=0; ledW=0; } else if((pinA==1)) { if((pinB==0)) { lcd_goto(20); send_char(' '); send_char('H'); send_char('E'); send_char('A'); send_char('T'); send_char('E'); send_char('R'); send_char(' ');\ send_char('O'); send_char('N'); ledA=0; ledB=1; ledL=0; ledF=0; pump=0; heater=1; lighting=0; fan=0; buzzer=0; ledW=0; } else if((pinB==1)) { if((light0) { send_char(tenth + 0x30); //0x30 added to become ASCII code send_char(data + 0x30);} else send_char(data + 0x30); //0x30 added to become ASCII code }

void increment(unsigned long data) { unsigned short j; for(j=10;j>0;j--) { lcd_goto(32); data=data+1; dis_num(data); delay(10000); } } //==================subroutine ADC========================= void read_adc(void)

79

{ unsigned short i; unsigned long result_temp=0; for(i=2000;i>0;i-=1) //looping 2000 times for getting average value { ADCON0bits.GO = 1; //ADGO is the bit 2 of the ADCON0 register while(ADCON0bits.GO==1); //ADC start, ADGO=0 after finish ADC progress result=ADRESH; result=result

Suggest Documents