There are fewer instructions in this PIC as
compared to the 18 series, but the only ones I
really missed were the conditional branches. It was
sometimes confusing using the skip operations, but
as long as I documented the code properly I
In looking over the code, I still sometimes do a
double-take when I see a skip instruction followed
by one or two GOTO statements. Also, even
though the clock frequency is 31 kHz, the
instruction execution time is about 8 kHz. If you
want to do some debugging, be aware that single
stepping takes about 20 seconds per step.
I gave a lot of thought to finding the most cost-effective method of detecting the water level. I
probably spent more time on this effort than any
other phase of the project. At first, I was gong to
use a commercial water level sensor; however, the
units I found turned out to be too expensive for
my purpose. The sensor I decided upon is simply
two parallel wires terminated with gold plated
contact pins (see Figure 1).
I initially used the wire ends stripped back
about 1/2”. However, after about a month, there
was enough oxidation on them that they stopped
working. The gold plated pins will last a lot longer.
I used some gold plated “D” connector pins which
I happened to have in my stock of parts. If you
want to get a little more robust, you can use
stainless steel bolts instead.
These two pins and the water between them
form a switch which is “closed” when the pins are
submerged. As you can see from the schematic, the
circuit is very simple and has very few components, with a
total cost of under $10. The printed circuit board (PCB) is
approximately 1” x 1.35” and fits easily into a low cost
“potting” box (see Figure 2).
I purchase most of my parts from Digi-Key since they
have free shipping if a check is included with the order. If
you use this service, be sure to include whatever sales
taxes are applicable.
The operation of the system is quite simple. When the
unit is first powered up, it goes through a calibration cycle
requiring you to flush the toilet once. It measures the
amount of time between when the water drops below the
level of the sensors to when the sensors are submerged
again. This time — plus a 25% pad — is used as the basis
for determining whether or not future flushes finish on
If the system detects that too long a time has
occurred before the tank becomes full again, a warning
signal is sounded via an audio transducer (buzzer).
October 2016 31
■ FIGURE 1. Two views of the sensor showing the pill
container as cut with a Dremel tool. The top photo shows a
small lip which allows it to hang quite nicely on the back of
■ FIGURE 2. As you can see, the circuit board is quite
small. The battery mounts on the bottom side and is
kept in place by the battery holder.