Design and Construction of Water in Fuel Detector

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 60

ABSTRACT

With water in your fuel tank, initially, for few minutes, the engine won't cause any issue.

However, after a while, the process of fuel combustion would become weak and will start

showing the water in fuel tank symptoms. Additionally, if there is a large amount of water in the

fuel system then, it may stop the engine immediately. Any water in your fuel tank will create

severe problems with fuel injectors and may result in them exploding. Importantly, larger slugs

of water induced into the fuel supply may result in severe damage to an engine as water will not

compress in an engine cylinder. This can also cause an engine to cool too quickly and potentially

crack core components. Bacteria and fungus also breed in water. As these microbes multiply

over time, they produce acids which affect fuel quality, clog filters and cause storage tanks to

corrode. Finally, there is the fundamental loss of power as less fuel is being pumped into the

engine. This project is design so as to detect water in fuel and to immediately cut off the fuel to

avoid any damage to the car engine. The achieved this set goals, a microcontroller 16F877A will

be used with water in fuel sensor.

1
CHAPTER ONE

INTRODUCTION

1.1 BACKGROUND

Water becomes a problem during transport, storage and use. Newly refined fuel is clean and free

of excessive moisture. Refiners and pipeline operators adhere to strict fuel storage tank

maintenance procedures with regular removal of water bottoms and occasional chemical

treatment to assure American Society for Testing and Materials (ASTM) specifications are met.

Unfortunately, after it leaves these facilities water bottoms removal is often neglected. Several

factors contribute to moisture accumulation, including climate, storage tank installation and fuel

handling procedures. Temperature changes can cause suspended water in the fuel to settle out.

For instance, any time warm fuel is placed in a cooler tank, whether for storage or transport,

moisture will drop out of the fuel as it cools. This makes it necessary to periodically drain off the

water, which is a simple task. Water is denser than fuel, so it always settles out to the bottom of

the tanks. Water condensation in fuel storage tanks is a common problem. The longer the fuel is

stored, the more pronounced the problem. If water is allowed to remain in the fuel while it is

stored, microorganisms or bacteria can form that feed on the hydrocarbons in the fuel. This

results in slim, which can clog filters. A Water In Fuel or WIF sensor detects the presence of

water in diesel fuel and gasoline typically using the difference of electric conductivity between

two electrodes through water and fuel. Detection of water in fuel can prevent or at least reduce

any damage water could cause to fuel injectors should water bypass the filter media. Water in the

engine fuel system can cause injection system damage, hard starting, loss of power, misfiring,

surging or stalling WIF sensors are usually placed in the bottom of a fuel filter water separator. A

fuel filter separator provides a space in the bottom of the separators dirty side for collection of

2
water. The signal generated is then sent to the ECU or a dashboard indicator light, alerting the

operator that the filter needs servicing. Water can get carried into fuel tanks from other storage

tanks and can also form in fuel from condensation, alcohol in fuel, high humidity, contaminated

fuel, old fuel, periods of no activity. This project is design to detect water in fuel and when

detected its automatically cut-off the fuel pump so as to avoid any damage to the car engine. The

project will be design using microcontroller PIC16f877A and water in fuel sensor.

1.2 MOTIVATION

At least some of us might be concerned if water seeps into the fuel tank during the rainy season.

Modern cars have good sealing against water. However, there would be chances in which water

does come into your car's fuel tank. So what if water gets in the fuel tank? Water and fuel (petrol

or diesel) have different densities and do not mix with each other. Engine components are

designed to function with a specific type of fuel. Fuel is not only used for combustion but also

acts as a lubricant and coolant in components such as the injectors and fuel pump.

Since water and fuel do not mix with each other and because water is denser than fuel, water

rests at the bottom of the fuel tank. The prolonged presence of water will cause rust there. The

rusting is accelerated if there are ridges and sharp edges in the fuel tank. Rust can also extend to

other parts of the fuel line. Hence, the motive behind this project design is to design a system that

is capable of detecting water in fuel and automatically stop the vehicle fuel pump to avert any

damage to the vehicle engine and other mechanical parts.

1.3 AIM AND OBJECTIVES

The aim of carrying out this project is to design a system that will detect water in fuel and to

automatically stop the fuel pump. The project is design to have the following objectives:

1. To design and construct the system power supply

3
2. To design and construct the water in fuel sensor and the microcontroller PIC16F877A

3. To design and construct the fuel pump switching circuit

4. To develop the system source code

5. To implement the design into a working system that can be marketable.

1.4 METHODOLOGY

In designing this project the following methods were employed the circuit was divided into four

part or sub-circuits namely:

(a) The power supply unit

(b) Water in fuel sensing and microcontroller unit

(c) Fuel pump Switching unit

(d) alarm unit

Each sub-circuit was design separately, and it will depend on the electrical characteristics of

individual components. Each sub-circuit design is compatible with the other sub-circuit and the

power supply.

POWER SUPPLY
CIRCUIT

FUEL PUMP
SWITCHING CIRCUIT

MICROCONTROLLER ALARM UNIT


WATER SENSING 16F877A
CIRCUIT

Fig. 1.1 Block Diagram Of The Project.

4
1.5 REPORT ORGANISATION

This project was arranged into five chapters: with chapter one as an introduction to the general

aim and objective of the project, and the ideas at focus presented. Chapter two deals with

relevant literatures of components used in realising this project, chapter three is design

procedures, chapter four deals with construction procedures, testing and result, while chapter

five gives the conclusion and recommendations for upgrading the project.

1.6 PROJECT SCOPE AND LIMITATION

The project has the limitation of detecting and controlling the vehicle fuel pump using water in

fuel sensor which is placed t the bottom of the fuel tank.

5
CHAPTER TWO

LITERATURE REVIEW

2.1 INTRODUCTION

This chapter, present the review of related literature, that were reviewed before designing and

constructing this project, titled design and construction of water in fuel detection with fuel pump

cut-off.

2.2 RELATED WORK

Several researchers have worked on water or liquid level control systems with different results

and modus operandi. In one of the research works, Ebere and Francisca (2013) designed a

microcontroller based water level control system for the purpose of starting and stopping a

pump, as well as display the level of the water in the tank. The system has the same objective as

this design but differs in the type of sensor and display units. While they used comparators as

sensors and LCD as display units, this design used metallic sensors and seven-segment ICs as

display units. Furthermore, this design used PIC microcontroller embedded with C language

while the other design used ATMEGA microcontroller embedded with assembly language.

In a related development, Jatmiko et al, (2012) developed a prototype module for detecting the

level of water, with wireless system. The module used an ultra sound sensor (ping sensor) to

transmit and receive signal between the position of the sensor and the water (Abdullah et al,

2014; Viswanathet al, 2015). The microcontroller used was ATMEGA and the output device was

LED and LCD. The technicality behind this module is different from that of this design in the

type of sensor and the output device. However, they produce the same result of detecting water

level. It is generally obvious that microcontroller has got a significant role to play in level control

6
(Patil and Abrar, 2014). It is on this note that Chakraborty et al(2014) also worked on a water

level control system using PIC microcontroller. This design is similar to this work in that it was

meant for a residential building. The design used USART interface to communicate the water

level status to a computer.

The wireless and ATMEGA microcontroller gained popularity in level control system as the

metal strip sensor which operates in the principles of electrical conductor of water was used for

level control using radio frequency via Global System for Mobile (GSM) communication. The

GSM was used in transmitting and receiving signal with an interface to the computer system for

displaying only HIGH or LOW level for the control action to be taken (Mukthaet al, 2013;

Nnadiet al, 2015; Makanjuolaet al, 2015).

This design is similar to this research design work in that it was meant for a residential building

but will incorporate an intelligent device that will give alarm when the water level underground

cannot be reached. Under this condition, the system is shut down after three seconds.

Very recently, Teo and Tiew (2015) embarked on a similar venture where the Water Level

Automated Management System was introduced. The information to top-up water from a

reservoir tank when the water level in the main tank fall s below half of the tank; was sent

through SMS to the user. When it falls below the critical level, the buzzer will be activated to

warn the user of the critical state of the system. Peak microcontroller PIC16F84A was adopted

for this design. The water level sensor here was water conductivity sensor. The ON/OFF sensors

were used to sense the presence of water at a particular level(Umeh et al, 2015). Obikoya (2014)

deviated a little from the water control system into fuel. The researcher designed, constructed,

and implemented a remote fuel-level monitoring system. The system was uniquely configured

such that the remote Aplicom 12 GSM module interfaced the connected sensor. Here the status

7
message from the module was sent back via a Global System for Mobile (GSM)

Communications network (Johari et al, 2011; Abdullah1 and Ali, 2014). The fuel-level sensor

was designed and uses arms and floater, where the displacement of the fluid from the floater was

converted to a readable value. Their work has flaws in that incases of network failure, there

won’t be any other medium of communication thereby bringing the entire system to a halt.

Based on this conceptual principle, this Microcontroller-Based Water in fuel System was

designed. The materials listed below were technically selected for this design and the

experimental approaches form the method suitable for this design piece

2.3 COMPONENTS DESCRIPTION

This part of this project explained and descript each components used in designing this project

2.3.1 THE PIC MICROCONTROLLER PIC16F877

The PIC microcontroller PIC16f877 is one of the most renowned microcontrollers in the

industry. This controller is very convenient to use, the coding or programming of this controller

is also easier. One of the main advantages is that it can be write-erase as many times as possible

because it use FLASH memory technology. It has a total number of 40 pins and there are 33 pins

for input and output. PIC16F877 is used in many pic microcontroller projects. PIC16F877A

also have many applications in digital electronics circuits.

Fig.2.1 the physical structure of microcontroller pic16f877A

8
PIC16f877a finds its applications in a huge number of devices. It is used in remote sensors,

security and safety devices, home automation and in many industrial instruments.

An EEPROM is also featured in it which makes it possible to store some of the information

permanently like transmitter codes and receiver frequencies and some other related data. The

cost of this controller is low and its handling is also easy. Its flexible and can be used in areas

where microcontrollers have never been used before as in coprocessor applications and timer

functions etc.

2.3.1.1 PIN CONFIGURATION AND DESCRIPTION OF PIC16F877A

As it has been mentioned before, there are 40 pins of this microcontroller IC. It consists of two 8

bit and one 16 bit timer. Capture and compare modules, serial ports, parallel ports and five

input/output ports are also present in it.

Fig.2.2 pin configuration of pic16f877A

PIN 1: MCLR

9
The first pin is the master clear pin of this IC. It resets the microcontroller and is active low,

meaning that it should constantly be given a voltage of 5V and if 0 V are given then the

controller is reset. Resetting the controller will bring it back to the first line of the program that

has been burned into the IC.

Fig.2.3 MCLR

A push button and a resistor is connected to the pin. The pin is already being supplied by

constant 5V. When we want to reset the IC we just have to push the button which will bring the

MCLR pin to 0 potential thereby resetting the controller.

PIN 2: RA0/AN0

PORTA consists of 6 pins, from pin 2 to pin 7, all of these are bidirectional input/output pins.

Pin 2 is the first pin of this port. This pin can also be used as an analog pin AN0. It is built

in analog to digital converter.

PIN 3: RA1/AN1

This can be the analog input 1.

PIN 4: RA2/AN2/Vref-

10
It can also act as the analog input2. Or negative analog reference voltage can be given to it.

PIN 5: RA3/AN3/Vref+

It can act as the analog input 3. Or can act as the analog positive reference voltage.

PIN 6: RA0/T0CKI

To timer0 this pin can act as the clock input pin, the type of output is open drain.

PIN 7: RA5/SS/AN4

This can be the analog input 4. There is synchronous serial port in the controller also and this pin

can be used as the slave select for that port.

PIN 8: RE0/RD/AN5

PORTE starts from pin 8 to pin 10 and this is also a bidirectional input output port. It can be the

analog input 5 or for parallel slave port it can act as a ‘read control’ pin which will be active low.

PIN 9: RE1/WR/AN6

It can be the analog input 6. And for the parallel slave port it can act as the ‘write control’ which

will be active low.

PIN 10: RE2/CS/A7

It can be the analog input 7, or for the parallel slave port it can act as the ‘control select’ which

will also be active low just like read and write control pins.

11
PIN 11 and 32: VDD

These two pins are the positive supply for the input/output and logic pins. Both of them should

be connected to 5V.

PIN 12 and 31: VSS

These pins are the ground reference for input/output and logic pins. They should be connected to

0 potential.

PIN 13: OSC1/CLKIN

This is the oscillator input or the external clock input pin.

PIN 14: OSC2/CLKOUT

This is the oscillator output pin. A crystal resonator is connected between pin 13 and 14 to

provide external clock to the microcontroller. ¼ of the frequency of OSC1 is outputted by OSC2

in case of RC mode. This indicates the instruction cycle rate.

Fig.2.4 OSC2/CLKOUT

PIN 15: RC0/T1OCO/T1CKI

12
PORTC consists of 8 pins. It is also a bidirectional input output port. Of them, pin 15 is the first.

It can be the clock input of timer 1 or the oscillator output of timer 2.

PIN 16: RC1/T1OSI/CCP2

It can be the oscillator input of timer 1 or the capture 2 input/compare 2 output/ PWM 2 output.

PIN 17: RC2/CCP1

It can be the capture 1 input/ compare 1 output/ PWM 1 output.

PIN 18: RC3/SCK/SCL

It can be the output for SPI or I2C modes and can be the input/output for synchronous serial

clock.

PIN 23: RC4/SDI/SDA

It can be the SPI data in pin. Or in I2C mode it can be data input/output pin.

PIN 24: RC5/SDO

It can be the data out of SPI in the SPI mode.

PIN 25: RC6/TX/CK

It can be the synchronous clock or USART Asynchronous transmit pin.

PIN 26: RC7/RX/DT

13
It can be the synchronous data pin or the USART receive pin.

PIN 19, 20,21,22,27,28,29,30:

All of these pins belong to PORTD which is again a bidirectional input and output port. When

the microprocessor bus is to be interfaced, it can act as the parallel slave port.

PIN 33-40: PORT B

All these pins belong to PORTB. Out of which RB0 can be used as the external interrupt pin and

RB6 and RB7 can be used as in-circuit debugger pins.

2.3.2 POWER SUPPLY

The entire circuit is powered by the car battery, though regulated to 5Vdc by a voltage regulator

7805.

2.3.2 LM7805 IC VOLTAGE REGULATOR

The regulator receives the input of a fairly constant DC voltage and supplies, as output, a

somewhat lower value of DC voltage, which maintains fixed or regulated over a wide range of

load current or input variation. The 7805 regulator maintains a 5V DC supply voltage to the

system. Normally, the input voltage to the regulator should be at least 2volts greater than the

output from the regulator.

Fig.2.5 7805 regulator

14
2.3.3. RESISTOR

Resistors come in a variety of sizes, related to the power they can safely dissipate. Colour-coded

stripes on a real-world resistor specify its resistance and tolerance. Larger resistors have these

specifications printed on them.

Any electrical wire has resistance, depending on its material, diameter and length. Wires that

must conduct very heavy currents (ground wires on lightning rods, for example) have large

diameters to reduce resistance.

The power dissipated by a resistive circuit carrying electric current is in the form of heat.

Circuits dissipating excessive energy will literally burn up. Practical circuits must take power

capacity into account. Ohm's law states that current flow depends on circuit resistance:

I = E/R

Circuit resistance can be calculated from the current flow and the voltage

R = E/I

Connecting resistors in series can increase circuit resistance:

R = R1 + R2 +...+ Rn

Placing one resistor in parallel with another can reduce circuit resistance:

1 1 1
R= + +
R1 R2 R3

Ohm's law states that current flow depends on circuit resistance:

I = E/R

Circuit resistance can be calculated from the current flow and the voltage:

15
R = E/I

Connecting resistors in series can increase circuit resistance:

Fig.2.6 Symbols of resistor (a) fixed (b) variable resistor

2.3.4 DIODE/ LED

Diodes exhibit a number of useful characteristics, such as predictable capacitance (that can be

voltage controlled) and a region of very stable voltage. They can, therefore, be used as switching

devices, voltage-controlled capacitors (varactors) and voltage references (Zener diodes).Because

diodes will conduct current easily in only one direction, they are used extensively as power

rectifiers, converting AC signals to pulsating DC signals, for both power applications and radio

receivers. Diodes behave as voltage-controlled switches, and have replaced mechanical switches

and relays in many applications requiring remote signal switching. Even indicator lamps are now

replaced with diodes (LEDs) that emit light in a variety of colours when conducting. A special

form of diode, called a Zener diode, is useful for voltage regulation.

Fig. 2.7 symbols of diode (a) diode, (b) LED, (c) full-wave Rectifier and (d) regulator diode

2.3.5 RELAY

16
A relay is an electrically operated switch. Many relays use an electromagnet to operate a

switching mechanism, but other digital operating relays are also used. Relays find applications

where it is necessary to control a circuit by a low-power signal, or where several circuits must be

controlled by one signal. The first relays were used in long distance telegraph circuits, repeating

the signal coming in from one circuit and re-transmitting it to another. Relays found extensive

use in telephone exchanges and early computers to perform logical operations. Refer to fig.2.13

below which shows a type of relay that can handle the high power required to directly drive an

electric motor is called a contactor. Solid-state relays control power circuits with no moving

parts, instead using a semiconductor device to perform switching. Relays with calibrated

operating characteristics and sometimes multiple operating coils are used to protect electrical

circuits from overload or faults; in modern electric power systems these functions are performed

by digital instruments still called "protection relays".

BASIC OPERATION OF A RELAY

A simple electromagnetic relay consists of a coil of wire surrounding a soft iron core, an iron

yoke, which provides a low reluctance path for magnetic flux, a movable iron armature, and a

set, or sets, of contacts; two in the relay pictured. The armature is hinged to the yoke and

mechanically linked to a moving contact or contacts. It is held in place by a spring so that when

the relay is de-energized there is an air gap in the magnetic circuit. In this condition, one of the

two sets of contacts in the relay pictured is closed, and the other set is open.

Other relays may have more or fewer sets of contacts depending on their function. The relay in

the picture also has a wire connecting the armature to the yoke. This ensures continuity of the

circuit between the moving contacts on the armature, and the circuit track on the printed circuit

board printed (PCB) via the yoke, which is soldered to the PCB.

17
Contacts

Solenoid magnetic coil

Fig 2.8: A simple Electromagnetic Relay

When an electric current is passed through the coil, the resulting magnetic field attracts the

armature and the consequent movement of the movable contact or contacts either makes or

breaks a connection with a fixed contact. If the set of contacts was closed when the relay was de-

energized, then the movement opens the contacts and breaks the connection, and vice versa if the

contacts were open. When the current to the coil is switched off, the armature is returned by a

force, approximately half as strong as the magnetic force, to its relaxed position. Usually this

force is provided by a spring, but gravity is also used commonly in industrial motor starters.

Most relays are manufactured to operate quickly. In a low voltage application, this is to reduce

noise. In a high voltage or high current application, this is to reduce arcing.When the coil is

energized with direct current, a diode is often placed across the coil to dissipate the energy from

the collapsing magnetic field at deactivation, which would otherwise generate a voltage spike

dangerous to circuit components. Some automotive relays already include a diode inside the

relay case. Alternatively a contact protection network, consisting of a capacitor and resistor in

series, may absorb the surge. If the coil is designed to be energized with alternating current (AC),

a small copper ring can be crimped to the end of the solenoid. This "shading ring" creates a small

out-of-phase current, which increases the minimum pull on the armature during the AC cycle.

The relay's switch connections are usually labeled COM, NC and NO:

COM = Common, always connect to this; it is the moving part of the switch.

18
NC = Normally Closed, COM is connected to this when the relay coil is off.

NO = Normally Open, COM is connected to this when the relay coil is on.

Connect to COM and NO if you want the switched circuit to be on when the relay coil is on.

Connect to COM and NC if you want the switched circuit to be on when the relay coil is off.

2.3.6 TRANSISTOR

A bipolar junction transistor, or BJT, is a current-based valve used for controlling electronic

current. BJTs are operated in three different modes, depending on which element is common to

input and output common base, common emitter or common collector. The three modes have

different input and output impedance and different current gains, offering individual advantages to a

designer.

A transistor can be operated in its non-linear region as a current/voltage amplifier or as an

electronic switch in cut-off and saturation modes. In its linear region, it must be biased

appropriately (i.e., subjected to external voltages to produce a desired collector current) to establish

a proper DC operating point.[14]

BJTs are commonly used in amplification and switching applications. They come in two versions:

NPN and PNP. The letters refer to the polarities, positive or negative, of the materials that make up

the transistor sandwich. For both NPNs and PNPs, the terminal with the arrowhead represents the

emitter. An NPN transistor has two n-regions (collector and emitter) separated by a p-region (base).

The terminal with the arrowhead is the emitter. A PNP transistor has two p-regions (collector and

emitter) separated by an n-region (base). The terminal with the arrowhead represents the emitter.

19
Fig.2.9 symbols of transistor (a) NPN and (b) PNP

2.4 PERIPHERAL INTERFACE CONTROLLER (PIC) INTRODUCTION TO PIC

167F877

The basic building block of PIC 16F877 is based on Harvard architecture. This microcontroller

also has many advanced features as mentioned in the previous post. Here you can see the basic

internal architecture and memory organization of PIC16F877.

2.4.1 ARCHITECTURE OF PIC16F877

The figure below shows the internal architecture of a PIC16F877A chip.

20
Fig.2.10 Internal Architecture of PIC16F877A Chip

The use of each functional block inside this controller has already been explained in the previous

post. Now let us look in to the detailed explanation about each sections inside the PIC 16F877.

2.4.2 MEMORY ORGANIZATION OF PIC16F877

The memory of a PIC 16F877 chip is divided into 3 sections. They are

1.Program memory

2.Data memory and

3.Data EEPROM

21
1. PROGRAM MEMORY

Program memory contains the programs that are written by the user. The program counter (PC)

executes these stored commands one by one. Usually PIC16F877 devices have a 13 bit wide

program counter that is capable of addressing 8K×14 bit program memory space. This memory

is primarily used for storing the programs that are written (burned) to be used by the PIC. These

devices also have 8K*14 bits of flash memory that can be electrically erasable /reprogrammed.

Each time we write a new program to the controller, we must delete the old one at that time. The

figure below shows the program memory map and stack.

Fig.2.11 PIC16f877 Program Memory

22
Program counters (PC) is used to keep the track of the program execution by holding the address

of the current instruction. The counter is automatically incremented to the next instruction during

the current instruction execution.

The PIC16F87XA family has an 8-level deep x 13-bit wide hardware stack. The stack space is

not a part of either program or data space and the stack pointers are not readable or writable. In

the PIC microcontrollers, this is a special block of RAM memory used only for this purpose.

Each time the main program execution starts at address 0000 – Reset Vector. The address 0004

is “reserved” for the “interrupt service routine” (ISR).

2. PIC16F87XA Data Memory Organization

The data memory of PIC16F877 is separated into multiple banks which contain the general

purpose registers (GPR) and special function registers (SPR). According to the type of the

microcontroller, these banks may vary. The PIC16F877 chip only has four banks (BANK 0,

BANK 1, BANK 2, and BANK4). Each bank holds 128 bytes of addressable memory.

23
Fig.2.12 Data Memory Organization

The banked arrangement is necessary because there are only 7 bits are available in the instruction

word for the addressing of a register, which gives only 128 addresses. The selection of the banks

are determined by control bits RP1, RP0 in the STATUS registers Together the RP1, RP0 and

the specified 7 bits effectively form a 9 bit address. The first 32 locations of Banks 1 and 2, and

the first 16 locations of Banks2 and 3 are reserved for the mapping of the Special Function

Registers (SFR’s).

BANK RP0 RP1

24
0 0 0

1 1 0

2 0 1

3 1 1

A bit of RP1 & RP0 of the STATUS register selects the bank access.

3. Data EEPROM and FLASH

The data EEPROM and Flash program memory is readable and writable during normal operation

(over the full VDD range). This memory is not directly mapped in the register file space. Instead,

it is indirectly addressed through the Special Function Registers. There are six SFRs used to read

and write this memory:

• EECON1

• EECON2

• EEDATA

• EEDATH

• EEADR

• EEADRH

The EEPROM data memory allows single-byte read and writes. The Flash program memory

allows single-word reads and four-word block writes. Program memory write operations

automatically perform an erase-before write on blocks of four words. A byte write in data

25
EEPROM memory automatically erases the location and writes the new data (erase-before-

write). The write time is controlled by an on-chip timer. The write/erase voltages are generated

by an on-chip charge pump, rated to operate over the voltage range of the device for byte or

word operations.

To know about the Register Memory Organization, and more of PIC 16F877 click on the link

below.

2.5 WATER SENSOR

The rain sensor module is an easy tool for rain detection. It can use as a switch when raindrop

falls through the raining board and for measuring rainfall intensity. The module features, a rain

board and the control board that is separate for more convenience, power indicator LED and an

adjustable sensitivity though a potentiometer [25]. The analog output is use in detection and

measurement of raindrops. Connected to 5V power supply, the LED will turn on when induction

board has no raindrop, and DO output is high. When dropping a little amount water, DO output is

low, the switch indicator will turn on. Brush off the water droplets, and when restored to the

initial state, outputs high level.

26
Fig 2.13 water sensor

27
CHAPTER THREE

DESIGN PROCEDURE AND ANALYSIS


3.1 INTRODUCTION

This chapter discusses the design procedure of this project. In designing this project, the circuit

was sub divided into three sub circuits viz:

(a) Power supply unit.

(b) The water in furl sensors circuit

(c) Fuel pump switching unit

(d) Micro-controller indicator and Display LCD circuit

3.2 POWER SUPPLY UNITS.

U1
7805
SW1
1 3
VI VO
GND

BAT1
C1 C2
2

12V

Fig.3.1 power supply circuit

28
The power supply enables a 5dc supply to the circuit for entire circuit operation it is from 12Vdc

battery regulated to 5Vdc by a regulator 7805. Capacitor C1 is 2200µf with main function of

filtering any ripples in the power circuit.

3.3 MICROCONTROLLER INPUT AND INDICATOR CIRCUIT

U1
7805

1 3
VI VO

GND
C1 C2

2
W ATER SENSOR
00
01

X1
10
11

16MHz
U2
13 33
OSC1/CLKIN RB0/INT
14 34
OSC2/CLKOUT RB1
35
RB2
2 36
RA0/AN0 RB3/PGM
3 37
RA1/AN1 RB4
4 38
RA2/AN2/VREF-/CVREF RB5
5 39
RA3/AN3/VREF+ RB6/PGC
6 40
RA4/T0CKI/C1OUT RB7/PGD
7
RA5/AN4/SS/C2OUT
R3 RC0/T1OSO/T1CKI
15
8 16
RE0/AN5/RD RC1/T1OSI/CCP2
9 17
RE1/AN6/WR RC2/CCP1
10 18
RE2/AN7/CS RC3/SCK/SCL
23
RC4/SDI/SDA
1 24
MCLR/Vpp/THV RC5/SDO
25
RC6/TX/CK
26
RC7/RX/DT

LED2 19
RD0/PSP0
LED1 20
RD1/PSP1
21
RD2/PSP2
R2 RD3/PSP3
22
R1 RD4/PSP4
27
28
RD5/PSP5
29
RD6/PSP6
30
RD7/PSP7
PIC16F877A

Fig.3.2 microcontroller input and indicator circuit

MANUFACTURER DATA ELECTRICAL CHARACTERISTICS OF PIC16F877A

Absolute Maximum Ratings

Ambient temperature under bias.............................................................-55 to +125°C

Storage temperature...................................................................... -65°C to +150°C

Voltage on any pin with respect to VSS (except VDD MCLR. and RA4)-0.3V to (VDD+ 0.3V)

Voltage on VDD with respect to VSS.................................................... -0.3 to +7.5V

Voltage on MCLR with respect to VSS...................................................0 to +14V

Voltage on RA4 with respect to Vss ............................................................0 to +8.5V

29
Total power dissipation (Note 1).......................................................................1.0W

Maximum current out of VSS pin ...................................................................300 mA

Maximum current into VDD pin...................................................................... 250 mA

Input clamp current, 1K (VI< 0 or VI> VDD).................................................. ± 20 mA

Output clamp current, 10K (VO< 0 or VO> VDD)............................................. ± 20 mA

Maximum output current sunk by any I/O pin........................................................25 mA

Maximum output current sourced by any I/O pin............................................... 25 mA

Maximum current sunk by PORTA, PORTB and PORTE (combined).................... 200 mA

Maximum current sourced by PORTA, PORTB and PORTE (combined)................. 200 mA

Maximum current sunk by PORTC and PORTD (combined)....................................200 mA

Maximum current sourced by PORTC and PORTD (combined) .............................. 200 mA

Maximum Output high voltage VOH …………………………………………………..4.5V.

Maximum input high voltage VIH ………………………………………………(VDD-0.3)V.

Note:

Power dissipation is calculated as follows: Pdis = VDD x {IDD- ∑IOH} + ∑{(VDD- VOH) x

IOH} + ∑(VOl x IOL)2:Voltage spikes below VSS at the MCLR pin, inducing currents greater

than 80 mA, may cause latch-up.

Thus, a series resistor of 50-100Ω should be used when applying a “low” level to the MCLR pin

rather than pulling this pin directly to VSS.3:

PORTD and PORTE are not implemented on PIC16F873A/876A devices.

30
NOTE: Stresses above those listed under “Absolute Maximum Ratings” may cause permanent

damage to the device. This is a stress rating only and functional operation of the device at those

or any other conditions above those

From manufacturer data of PIC16F877A

Maximum output current sourced by any I/O pin............................................... 25 mA

Maximum input high voltage VIH ………………………………………………(VDD-0.3)V.

That means that VIH= 5-0.3 = 4.7 maximum value

Vcc = V3 + VIH1

Let VIH1 to be 4.5V (chosen value)

5 = V3 + 4.5

V3 = 0.5V

But V3 = I3R3

Also I3 = IIH1 = 25mA maximum value (series current)

From manufacturer data Maximum output current sourced by any I/O pin is 25 mA

I3 = IIH1 = 0.5mA (chosen value)

0.5
R3 =
0.0005

R3 = 1KΩ

For LED1 to light ON


31
Vf2 is the forward voltage of the traffic light LED1 which is approximately 2V

V1 is the voltage drop across resistor R1

VOH9 = V1 +Vf1

4.5 = V1 + 2

V1 = 2.5V

Also IOH9 = I1 = If1 current in series circuit

Hence, IOH9 = I1 = If1

From first principle all LEDs will light on with forward current from 5mA to 15mA

But If1 = I1

Let If1 = 5mA (chosen value)

Note that I1 = 5mA

IOH9 = mA (chosen)

V1 = I1R1

2 .5
R1 =
0 .005

R1 = 500Ω (preferred value is 560Ω) the same apply to LED2,

3.4 FUEL PUMP SWITCHING CIRCUIT

32
U1
7805

1 3
VI VO

GND
C1 C2

2
RL1
12V
U2 D1
13 33
OSC1/CLKIN RB0/INT
14 34
OSC2/CLKOUT RB1
35
RB2
2 36
RA0/AN0 RB3/PGM
3 37
RA1/AN1 RB4
4 38
RA2/AN2/VREF-/CVREF RB5
5 39
RA3/AN3/VREF+ RB6/PGC
6 40
RA4/T0CKI/C1OUT RB7/PGD
7
RA5/AN4/SS/C2OUT BUZ1
15
RC0/T1OSO/T1CKI
8 16
RE0/AN5/RD RC1/T1OSI/CCP2
9 17
RE1/AN6/WR RC2/CCP1
10
RE2/AN7/CS RC3/SCK/SCL
18 FFUEL PUMP
23
RC4/SDI/SDA
1 24
MCLR/Vpp/THV RC5/SDO
RC6/TX/CK
25 R4
26
RC7/RX/DT

RD0/PSP0
19 Q1
20
RD1/PSP1
21
RD2/PSP2
22
RD3/PSP3
27
RD4/PSP4
28
RD5/PSP5
29
RD6/PSP6
30
RD7/PSP7
PIC16F877A

Fig.3.3 Fuel pump switching circuit

Transistor Q1 was chosen to be BC547 it has the below features also transistor Q2 and Q3 are

chosen to be BC557 with characteristic similar to BC547.

Going through data books Q1 was chosen to be BC547, it has the following characteristics.

VCBO = Collector-Base Voltage = 60V

VCEO = Collector-Emitter Voltage = 45V

VEBO = Emitter- Base Voltage = 6V

IC = Collector Current (DC) = 100mA

hfe min = DC Current Gain = 100

Ft(max) = 150MHZ

Ptot(max) = 300mW

33
Vbe = 0.7V.

VBE (ON) = Base Emitter ON voltage = 1V max

At the base circuit of Q1

Let VOH17 be the output high voltage of PIC16f877A

Then VOH17 = V4 +Vbe1

Vbe1 is the base emitter voltage of transistor Q1 which is 0.7V

V4 is the voltage drop across resistor R4

4.5 = V4 + 0.7

V4 = 3.8V

Also IOH = I4 = Ib1 current in series circuit

Hence, IOH = I4 = Ib1

Let IOH = 3.8mA (chosen)

V4 = I4R4

3.8
R4 =
0.0038

R4 = 1KΩ

At the collector circuit of Q1 when Q1 is biased

Vcc = IL1Rr1 + Vce1

34
1
Vce3 = of Vcc
3

Vcc = 5V

Vce1 = 1.67V

Where:

Vce1 = is collector emitter voltage of transistor Q1

Rr = Relay resistance

IL1 = collector current = inductor current

5 = IL1Rr1 + 1.67

3.3V = IL1Rr1

IL1 = 0.01A this is the maximum collector current Q1

Rr1 = 3.3/0.01

Rr1 = 330Ω (preferred value is 400Ω)

Hence, the Relay JZC-20F with 6V DC, 10A-and 400Ω characteristic was chosen.

35
U1
7805
SW1
1 3
VI VO

GND
BAT1
C1 C2

2
12V
2200u 100u

WATER SENSOR RL1


00
01

X1
10
11

12V
16MHz
U2 D1
13 33
OSC1/CLKIN RB0/INT
14 34
OSC2/CLKOUT RB1
35
RB2
2 36
RA0/AN0 RB3/PGM
3 37
RA1/AN1 RB4
4 38
RA2/AN2/VREF-/CVREF RB5
5 39
RA3/AN3/VREF+ RB6/PGC
6 40
RA4/T0CKI/C1OUT RB7/PGD
7
RA5/AN4/SS/C2OUT BUZ1
R3 RC0/T1OSO/T1CKI
15
560 8 16
RE0/AN5/RD RC1/T1OSI/CCP2
9 17
RE1/AN6/WR RC2/CCP1
10
RE2/AN7/CS RC3/SCK/SCL
18 FFUEL PUMP
23
RC4/SDI/SDA
1 24
MCLR/Vpp/THV RC5/SDO
RC6/TX/CK
25 R4
26 1K
RC7/RX/DT

LED2 RD0/PSP0
19 Q1
LED1 20 BC547
RD1/PSP1
21
RD2/PSP2
R2 RD3/PSP3
22
560 R1 RD4/PSP4
27
560 28
RD5/PSP5
29
RD6/PSP6
30
RD7/PSP7
PIC16F877A

Fig.3.4 complete circuit of the project.

3.5 SOFTWARE IMPLEMENTATION

Software Implementation can be divided into four parts: Power supply circuit, Microcontroller

Input and indicator circuit and Wiper motor circuit the PIC16F877A is chosen to perform the

functions needed for the system.

3.6 FLOW CHART ALGORITHM

The flow chart algorithm was drawn that is the way the program will run, with the flow chart, the

program will run step by step according to how the program developed.

36
Start

Shift all register Port pins

Shift registers Program variables

Turn on power LED

Check if water is in fuel

Is water in fuel?

NO

YES

Check statues if water in fuel


than turn on LED2, switch on Switch off LED2, buzzer and
buzzer and switch off fuel pump switch on fuel pump

End

Fig.3.5 system flow chart of the project

37
3.7 SYSTEM SOFTWARE

The program was written in the MPLAB integrated development environment and debugged from

a assembly-language into machine code (hex- file)

3.7.1 PROCEDURE

1. The program was written in the MPLAB integrated development environment and debugged

from a assembly-language into machine code (hex- file)

2. The software is used to show the results and characteristics of the output result when the

digital time base is switch on or off

38
CHAPTER FOUR:

CONSTRUCTION, PACKAGING, AND TESTING

4.1 INTRODUCTIONS

The material for the construction includes all components as shown in fig.3.5, vero board and

lead. The components were soldered on the vero board according to the sub-circuit arrangement

as shown in fig.3.4; caution was must be taken to avoid open or short circuit between component

terminal and also between sub-circuit connections.

4.2 CONSTRUCTION

The materials used while constructing this project include, bread board, vero board, soldering

iron, soldering lead wire, sucker and flexible wires i.e. jumpers.

Vero board – is made up of a thin sheet limited insulating material manufactured with regular

spaced holes permit mounting of electronics used as a permanent board on which the circuit was

constructed.

Bread board – is a special board made for testing the circuit before mounting the component onto

a vero board for construction and soldering. The components were not soldered on the test board

but rather tighten holes conductors are used to provide easiness of connection.

Soldering iron – is the material used to heat the lead wire between the conductors and connecting

point on the vero board.

Soldering lead wire – this is the material used as means of connection between conductor and the

board by applying heated soldering iron.

39
Sucker – is a material used to removed excess lead wire at the soldered joint or when removing

component i.e. to suck out the lead wire away from the terminal.

Jumpers – these wires that are used when connecting two or more terminals of the component

together.

The components used while constructing this project are as follows:

1. Pic16F877A microcontroller

2. Buzzer

3. Crystal oscillator 16MHz

4. 20 x 20 IC socket

5. LED red

6. 7805 Regulator

7. Power switch

10. Resistor 1KΩ, 10KΩ, 560Ω and 47Ω

11. Capacitor 2200µf

13. Water in fuel sensor

14 IN4148

15 Transistors BC547

4.3 SAFETY PRECAUTIONS

Safety precaution is very important in all electronics circuit construction, hence, below are the

safety precaution taken:

40
1. Try to avoid open circuit were they are not needed

2. Also, try to avoid short circuit by taking time to carry out all soldering

3. Soldering must be done with care so as to avoid dry joint which might cause open circuit

4. IEEE recommended soldering iron and soldering lead should be used

5. Copper made jumpers may be used to connect distance components

6. Wearing of goggles is very important to safe the eyes from soldering smoke

4.3 PACKAGING

The casing of the project was purchase in the market as ready made (adoptable box), though the

dimensions were calculated before it was purchased.

H
L
W

Fig. 4.1 casing of the project

Where H = 7 cm = height

W = 15 cm = width

L = 15cm = Length

The cuboid was used to determined surface area and volume

Surface Area (A) =2(LW +LH +HW)


41
=2{(15 x 15) + (15 x7) + (7 x 15)}

= 2{225 + 105 +105}

=870cm square.

Total Volume (V) = LWH

=15 x 15 x7

= 1575cm cubed

Where H = 10 cm = height

W = 15 cm = width

L = 22cm = Length

The cuboids was used to determined surface area and volume

Surface Area (A) =2(LW +LH +HW)

=2{(22 x 15) + (22 x10) + (10 x 15)}

= 2{330 + 220 +150}

=1400cm2

Total Volume (V) = LWH

=22 x 15 x10

= 3300cm3

42
4.3.1 PICTORIAL VIEW

4.4 TESTING

The complete circuit was build and tested for a period of six hours and it worked according to

specifications, pulling a current of 7.5mA, 5V from the power supply. It was assembled on a

testing board and tested later constructed, permanently on copper stripped vero board and it was

found to be working, the test was repeated several times and the project was working perfectly.

4.3 TESTING PROCEDURES

After successful construction of the project, each unit was tested using appropriate tools and

equipments, the following procedures were used:

1 The circuit was then constructed on a testing board

2 The circuit was observed to identify any open or short circuit and partial contact.

3 The power supply was powered on by switching the switch on

4 The circuit was tested and working satisfactory, then it was finally and permanently

constructed on the copper stripped board for final testing.

5 Procedures 3, 4 and 5 was repeated again

6 The permanent constructed circuit was tested and it was working according the circuit

specifications.

43
4.5 RESULTS

After the testing of the system it was found to be working satisfactorily with a minimum or no

error with very high reliability. This means that, the project meets its objectives and requirements.

The Result of Construction Project

Table 4.1 Result of the Project

S/n Power Water sensor LED2 Buzzer


supply
1 Off No water in fuel Off off
2 On No water in fuel Off Off
3 On Water in fuel On On

44
CHAPTER FIVE

CONCLUSION AND RECOMMENDATIONS

5.1 INTRODUCTION

In this chapter, the summary and achievement of the constructed project were explained inform

of conclusion and recommendation.

CONCLUSION

the causes of water in fuel are listed below:

● The chances of water entering the fuel tank increases if the tank has a bad top fuel pump.

● Condensation of atmospheric moisture leads to accumulation of water vapor into the petrol

tank.

● Another cause can be the poorly sealed cap on top of the tank. Therefore, rains or a regular car

wash can prove to be a big disaster to the tank.

● It can also happen when ground water seeps into the storage tank at the filling station, thereby

making the fuel pump to circulate water all across the fuel lines and the fuel injectors.

Symptoms and Effects of water in fuel tank are as follows:

●Hydrolock An hydrolocked engine has water inside the combustion chamber that prevents

combustion and compression. The engine will be unable to start and possible unable to crank.

●Engine Stalls The engine may be able to start and maintain itself for a while. However, the

combustion will be weaker than normal and may lead to stalling.

●Engine Will Not Start .The engine may turn over while the ignition is engaged, but the lack

45
ofthe proper amount of fuel will prevent normal operation.

●Poor Fuel Economy The water will reduce engine power, but allow the same amount of fuel to

be burned. The result being the same fuel burned for reduced mileage.

● As petrol is lighter than water, when water enters the tank, it settles at the bottom of the tank.

Eventually, the tank begins to rust. ● The watered-down fuel in a car can make it sputter and

behave as if it has lost power.● Water in a gas tank can lead to bio-degradation of the fuel.

● It can also cause microbial growth in the fuel, which will damage the entire fuel system and

induce filter plugging. ● Certain other likely effects of this problem are holes in the fuel tank and

failure of the fuel injector.

RECOMMENDATION

1. Very high profile fuel filter can be to filter any impurities especially water molecules.

2. Future development in technology can be develop to notify can user of water in fuel before

stating the car,

3. GSM sms can be incorporate to send sms to owner when water is detected.

46
REFERENCES

[1].Abang, J. O. (2013). Construction of Automatic Water Level Controller for Both Overhead

andUnderground Tanks. Journal of Chemical Information and Modeling, 53(1), 1689–1699.

[2].Abdullah,U. & Ali, A. (2014). GSM Based Water level and Temperature Monitoring S

ystem. International Journal of Recent Development in Engineering and Technology, 3(2), 1–7.

[3].Abdullah,A.M.; Ahmed, N.;Ahmed, N. U.;Matiur-Rahman, S.A.M; Ahmed, B. & Sundara,

K. (2014). Use of Wireless Sensor and

Microcontroller to Develop Water-level Monitoring System Use of Wireless Sensor and

Microcontroller to Develop Water-level Monitoring System. Indian Journal of Science and

Technology, 7(9), 1325–1330.

[4].Chakraborty, T.; Alam, K.; Mal, S. & Biswas, U. (2014). Automatic Electronic Water Level

ManagementSystem using PIC Microcontroller. International Journal of Emerging Technology

and Advanced Engineering, 4(7), 30–33.

[5].Ebere, E. V. & Francisca, O. O. (2013). Microcontroller based Automatic Water level

Control System. International Journal of Innovative Research in Computer and Communication

Engineering, 1(6), 1390–1396.

[6].Fisher, D. K. & Sui, R. (2013). An inexpensive open-source ultrasonic sensing system for

monitoring liquid levels. Agricultural Engineering International: CIGR Journal, 15(4), 328–334.

[7].Jack, K. E. and Etu, I. (2015). Applied Electrical Electronics Measurement Principles

&Instrumentation Systems with Laboraory Experiments. Kingdom Age Publications, Enugu,

Nigeria

[8].Jagadal, S. B. & Halse, S. V. (2013). 8051 Microcontroller Based Multiple Water Tank

Control System. Journal of Computer & Mathematical Sciences, 4(5), 382–401.

47
[9].Jatmiko, S.; Mutiara, A B. & Indriati, M. (2012). Prototype of Water Level Detection

System. Theoretical and Applied Information Technology, 37(1), 52–59.

[10].Johari, A.; Helmy, M.; Wahab, A.; Suryani, N.; Latif, A.; Ayob, M. E.& Ayob, M. A.

(2011). Tank Water Level Monitoring System using GSM Network. International Journal of

Computer Science and Information Technologies, 2(3), 1114–1120.

[11].Makanjuola, N.T; Shoewu, O.O; Akinyemi, D. & Ajasa, A. (2015). Design and

Development of Microcontroller Based Liquid Level Detector with. The Pacific Journal of

Science and Technology, 16(1), 173–181.

[12].Muktha, S. K; Jyothi, K.; Manu, E. O.; Naveen, I. P. & Herle, H. (2013). Wireless Autom

atic Water Level Control using Radio Frequency Communication . International Journal of

Advanced Rresearch in Electrical, Electronics and Instrumentation Engineering, 2(4), 1320–

1324.

[13].Nnadi, D.B.N;Oti, S.E & Ezika, P. C. (2015). Radio Frequency Based Water Level Monitor

and Controller for Residential Applications. Nigerian Journal of Technology, 34(3), 573–581.

[14].Obikoya, G. (2014). Design, construction, and implementation of a remote fuel-level

monitoring system. EURASIP Journal on Wireless Communications and Networking, 2014(1),

76.

[15].Parade, D.& Group, B. & Dublin, C. (2015). Low-Power Wireless Liquid Monitoring

System Using Ultrasonic Sensors. International Journal on Smart Sensing and Intelligent System,

8(1), 26–44.

[16].Patil,R. R.&Abrar, M. M. (2014). Logic gate based automatic water level controller.

International Journal of Research in Engineering and Technology, 3(4), 477–482.

48
[17].Reza, S. M. K.; Tariq,S. M.; Reza, S. M. M.; Douglas, C.; Grundfest, W. S. & Burgstone, J.

(2010). Microcontroller Based Automated Water Level Sensing and Controlling: Design and

Implementation Issue. World Congress on Engineering and Computer Science, Vols 1 and 2,

I(2010), 220–224.

[18].Teo, P. & Tiew, C. D. (2015). Automated Water Level Management System. International

Journal of Computer & Electronics Research, 4(1), 11–16.

[19].Uddin, M.S.M; Alam, R.M; Bansal, M; Akhter, P; Baidya, R & Kabeer, R. (2013). Design

and Implementation of Microcontroller Based Process Line. International Conference on

Mechanical Engineering and Renewable Energy, 2013 (December), 24–27.

[20].Umeh,M.N; Mbeledogu, N. N; Okafor, S. O. & Agba, F. C. (2015). Intelligent

microcontroller-based irrigation system with sensors. American Journal of Computer Science

and Engineering, 2(1), 1–4.

49
APPENDIX

;using PIC IC, PIC16F877A

;April-2018

;crystal oscillator - 16mhz

LIST P=PIC16F877A

include "p16f877a.inc"

__config 0x0842

Zs macro

btfss STATUS,Z

endm

Zc macro

btfsc STATUS,Z

ENDM

Cs macro

btfss STATUS,C

endm

Cc macro

btfsc STATUS,C

endm

bank0 macro

50
bcf STATUS,RP0

bcf STATUS,RP1

endm

bank1 macro

bsf STATUS,RP0

bcf STATUS,RP1

endm

bank2 macro

bcf STATUS,RP0

bsf STATUS,RP1

endm

bank3 macro

bsf STATUS,RP0

bsf STATUS,RP1

endm

#define sensor_in PORTA,0 ;pin2

#define lo_led subPORTA,1 ;pin 3

#define mid_led subPORTA,2 ;pin 4

#define hi_led subPORTA,3 ;pin 5

#define pwm_out PORTC,2 ;pin17

#define power_led subPORTE,1 ;pin9

#define flash genreg,0

#define ADC_read_flag genreg,1

51
#define ADC_done_flag genreg,2

#define flash2 genreg,3

#define hi_speed_flag genreg,4

#define mid_speed_flag genreg,5

#define lo_speed_flag genreg,6

PORTC equ 0x07

PORTD equ 0x08

PORTE equ 0x09

w_temp equ 0x70

STATUS_temp equ 0x71

cblock 0x20

genreg

genreg2

delay1

delay2

delay3

debouncetimer

subPORTA

subPORTB

subPORTC

subPORTD

subPORTE

countA

52
ADCresultL

ADCresultH

ADC_count

pulsewidthH

pulsewidthL

temp2

temp3

ADC_timer

ADC_acc

hi_count

mid_count

lo_count

none_count

endc

org 0h

goto start

org 4h

countA += 1

if countA >= 10 then

countA = 0

ADC_timer += 1

if ADC_timer >= 20 then

ADC_timer = 0

53
ADC_read_flag = 1

endif

endif

retfie

start bank0

clrf PORTA

clrf PORTB

clrf PORTC

clrf PORTD

clrf PORTE

bank1

movlw b'11110001'

movwf TRISA

movlw b'11111111'

movwf TRISB

movlw b'11111011'

movwf TRISC

movlw b'11111111'

movwf TRISD

movlw b'00001100'

movwf TRISE

bank0

subPORTA = 0

54
PORTA = 0

subPORTB = 0

PORTB = 0

subPORTC = 0

PORTC = 0

subPORTD = 0

PORTD = 0

subPORTE = 0

PORTE = 0

clrf genreg

genreg2 = 0

clrf debouncetimer

ADCresultL = 0

ADCresultH = 0

power_led = 1

call del1sec

power_led = 0

call del1sec

power_led = 1

main

if ADC_done_flag = 1 then

ADC_done_flag = 0

if ADCresultH = 0 and ADCresultL < 205 then

55
hi_led = 1

lo_led = 1

mid_led = 1

hi_count += 1

elseif ADCresultH = 1 and ADCresultL < 154 or ADCresultH < 1 then

mid_led = 1

lo_led = 1

hi_led = 0

mid_count += 1

elseif ADCresultH = 3 and ADCresultL < 51 or ADCresultH < 3 then

lo_led = 1

mid_led = 0

hi_led = 0

lo_count += 1

else

lo_led = 0

mid_led = 0

hi_led = 0

none_count += 1

endif

ADC_acc += 1

if ADC_acc >= 20 then

ADC_acc = 0

56
if hi_count >= 15 then

hi_speed_flag = 1

lo_speed_flag = 0

mid_speed_flag = 0

elseif mid_count >= 15 then

mid_speed_flag = 1

hi_speed_flag = 0

lo_speed_flag = 0

elseif lo_count >= 15 then

lo_speed_flag = 1

hi_speed_flag = 0

mid_speed_flag = 0

elseif none_count >= 15 then

hi_speed_flag = 0

mid_speed_flag = 0

lo_speed_flag = 0

endif

hi_count = 0

mid_count = 0

lo_count = 0

none_count = 0

endif

endif

57
if hi_speed_flag = 1 then

pulsewidthH = 3

pulsewidthL = b'11101000'

elseif mid_speed_flag = 1 then

pulsewidthH = 2

pulsewidthL = b'10111100'

elseif lo_speed_flag = 1 then

pulsewidthH = 1

pulsewidthL = b'11000010'

else

pulsewidthH = 0

pulsewidthL = 0

endif

call load_pulsewidth

if ADC_read_flag = 1 then

ADC_read_flag = 0

call ADC_read

ADC_done_flag = 1

endif

goto main

58
ADC_read

bsf ADCON0,2

AD1 btfsc ADCON0,2

goto AD1

bank1

movf ADRESL,w

bank0

movwf ADCresultL

movf ADRESH,w

movwf ADCresultH

return

load_pulsewidth

temp3 = pulsewidthH

temp2 = pulsewidthL

bcf STATUS,C

rrf temp3,f

rrf temp2,f

Cs

goto calc5

bsf CCP1CON,4

goto calc6

calc5 bcf CCP1CON,4

calc6 bcf STATUS,C

59
rrf temp3,f

rrf temp2,f

Cs

goto calc7

bsf CCP1CON,5

goto calc8

calc7 bcf CCP1CON,5

calc8 movf temp2,w

movwf CCPR1L

return

del1sec

clrf delay2

movlw .19

movwf delay3

del1sec1 decfsz delay1,f

goto del1sec1

decfsz delay2,f

goto del1sec1

decfsz delay3,f

goto del1sec1

return

end

60

You might also like