The Big Sailboat Little PIC Project
Level sensor for septic tank
& New Design

 

  Level Sender by 2 line interface by S.Sims
<RIGHT CLICK HERE TO SAVE DIAGRAM>

The level sender is a board that is mounted inside a waterproof housing at the top of a fitting on top of the septic tank. The display board, discussed below, tells the user the level of the tank via 8 LEDs and a button. The power consumption is very low as both chips are mostly is "sleep" mode. This is a mode where the chips retain their memory, but aren't actually executing any program instructions. The chips ( AKA PIC chips ) consume only micro-amps and could run for years off of a 9 volt battery. How's that for power efficient?!
 
   
  Circuit description and theory

Both the sender and display boards use 16C57C PIC chips from MicroChip. I have since graduated to larger, more impressive PIC's but these seemed appropriate for the simple function. 16C55's could also be used as the program memory doesn't go beyond the first page.
In the level tube are placed 8 reed switches, each spaced about 6" apart. These reeds have a board mount attached but any type will do.(Electronic Goldmine, All electronics)
The magnet, a doughnut style in this case, slides up and down the tube activating the reeds in sequence, shorting port B 0 to 7 down to ground. In their normally open state they are pulled up by 47k resistors to 5 volts.
 
 
"Doughnut" style magnet encased in packing foam then coated
 
 
A simple reading of the reeds couldn't be implemented as sometimes no reeds are closed, and other times 2 may be closed at the same time. A memory of last position and direction must be kept. Because of the motion of a boat, water sloshing around in the tank may give a falsely lower reading. To remedy this, the level doesn't drop until 2 reeds in sequence have been activated. This should only occur during a pumpout. ( or knock down God forbid! ) The lowest reed invokes a reset condition only if it has gone down to that level. A beeper will sound on the display to notify user that the tank has been emptied. This could also be tied into the pump-out pump as a shutoff but I don't think we'll bother with that.

The chip sends data to the display board by pulsing the transistor which pulls down the 12 volt line to ground. This 12 volt line is fed from a 470 ohm resistor on the display board.
The power supply is the key to low power consumption required on a sailboat. A smaller cousin of the 7805 is used. The UA7805CDCYR (Digikey) is an smd version that has less power consumption in a no load situation. A capacitor on both input and output pins to ground stops oscillation.( Very necessary!)
A 1000uF electrolytic capacitor holds voltage to the chip while the 12 volt feed is being pulsed with data to the display. The pulses are extremely fast (1 mS) and have no effect on the voltage to the chip.
They are only sent when the chip "wakes up" and takes a reading to update the position of the magnet.
The rectifier is to stop any current feeding back into the line from the 100uF capacitor. The 33 ohm resistor is just a precaution for accidental reverse voltage or whatever! (I have a lot of experience in this!)
During testing, I connected 8 LEDs and 1k resistors to Port C outputs. These don't need to be connected so have been left out of the schematic. If you want an 8 wire indicator without the cost of the display, these can be used but the lines of code rem'ed out in the sender program must be put back in as well as the tris port C changed from 0xff to 0x00 to make port C an output. ( Outputs waste power )
A 4 mhz crystal was used ( XT config bit not HS ) but a TV colorburst crystal 3.1519... would suffice. As long as both crystals on both boards are the same.
The MCLR pin has the standard reset on power-up configuration with a 47k and .1 cap.

Problems:
--2 reeds being active at the same time. This would lock up the original program but was remedied but counting down from the fullest toward the emptiest, taking the fullest reading ( which is more important, right? )
--serial data format. I chose a PWM format. One's are 50% longer than zero's, but each falling edge is the same clock spacing. I did this because the original idea for the display PIC was to have it wake randomly and count 9 bits. If less than 9 bits the data invalid. This turned out to be dodgy because in order to get a sync, minutes could pass. During emptying, minutes are irrelevant. Seconds are relevant. I just kept the PWM because it's one way it works well on a single line (really) communication method.
--No reeds active. The display PIC must be able to remember as well! Button gets pressed to check reading, problem solved.
--Data getting corrupted over long runs of wire. Because this is a non-twisted pair serial connection,(rs-232,nmea) higher data rates cause data to be corrupted by resonance of the wire. ( A common problem, I should know better!) The solution was to slow it down by 3 decimal places. How many thousand times does one really need to update a septic tank reading every second haha!
   

<RIGHT CLICK HERE TO SAVE DIAGRAM>

The Display Board
Normally, the display PIC is also in sleep mode, but no longer that a start bit length sent by the Sender PIC. This way, no errors can happen, and power consumption is kept at a minimum. The "Wake" from sleep is implemented by the watchdog timer, and OPTION register bit status. PoRT A,0 & 1 pins are tested for a possible low from the button or a start bit from the Send PIC. The data received is rolled into a buffer then cascaded to fill any lower LEDs thus creating a bar effect. Once the level is bottomed out during a pump-out an alarm will sound. This is triggered by a special code of all 0's.
During power-up only, all leds are flashed as a test of the LEDs. Any wiring problems will be indicated by a constant beeping (ping sound from my CB roger beep days!) and wiring can be checked for shorts.
The same type of 7805 regulator can be used on this board but I chose a regular 7805 because of the potentially high LED load. The LEDs coming from Port B are each in series with a 330 ohm resistor to ground. Because the signal from the Sender is on a 12 volt line, a resistor voltage divider must be placed between the line and the input pin at Port A,0. A 12k and 4.7k split the voltage to 5.4 volts @ 13.8 Volts input. This is within the PIC's max parameters, but a 14k resistor could be used if the voltage in the boat is high. Another regulator could be used to make 12 volts the supply, but it will consume more power.
A zener diode could be placed across the pins input at the 10k resistor but zeners consume some milliamperage as well, even before their crossover voltage is reached.
The 33 ohm resistor and .1uF capacitor on the 13.8 volts is to remove any rf or DC line noise that may cause false triggering.

That's pretty much it! The links to the code are below. These are in .zip format and include the .hex file as well as the .lst and .asm source code. I've tried to put pertinent comments in the source, but I, like most, am not very good at organizing code descriptions hehe.
The board layouts aren't crucial, mine were made to fit into a pipe and behind a light switch panel. They could be any shape or size but the circuit should be flowed accurately. I drew these up on cleaned copper board stock with a fine tip Staedtler laundry pen, then soaked them in ferric Chloride for a few minutes. A trick I always use when trying to fit components into a predefined area with through holes is to mark where the pins go and drill them first, then work the traces around, thru or to the holes. Works every time!

  (Left) Just after etching, (bottom left) cleaned off with steel wool.
(Below) Opposite side painted and ready to mount.
  --Display board---


...

 
     



-
If the programs don't make any sense, just do it anyway. It'll work I promise!

 
 
LEVELSENSORDISPL.ZIP    
LEVELSENSORSENDER.ZIP
LEVELSENSORSENDERTEST.ZIP (with test LEDS)
   

Display Board less PIC Chip
   
 
There it is finally in place, mounted behind a standard light switch panel. Before the sleep function was installed, the power consumption on the house batteries was negligible.

Funny enough, our main problem right now is that the solar panels over charge the batteries so we must either shut them off, or purposely run the batteries down. ( It's best to run them down to half their capacity before charging, which is a whopping 500 Amp-hours or so! A job for the inverter and a heater..)

Every little bit counts though. I have yet to coat the board but will do that before the sender gets permanently installed.

*While messing around with the sleep cycles etc, I changed the display from a single LED to a bar ( where ones under it stay illuminated ) This seems to make more sense.

Also, when the tank has been emptied, the LEDs flash quickly for 2 minutes, and decided to forgo the beeper. When Full, the LEDs all flash on for 1 second every 4 seconds. I sped up the sleep cycle to 18ms on the display, and 1.1 seconds on the sender. This brought the consumption up to 9 mA, which is still half that of a single LED.

Updated Dec.2007

   

The New Design

 

 What would life be without a challenge? Or mistakes? To err is human...
After all of the above, the whole thing needed to be redesigned again!  Somehow, the flux gate compass sensors both ended up directly above the tank. I saw Gena mounting them there, but n'er a thought passed me by...that is until we were out in the ocean going in circles trying to figure out why the flux gate compasses weren't calibrating.  Just sitting in the cockpit thinking about it, the cold reality of what was going on slowly sunk in. The giant magnet above was moving around with the tank level and setting the sensitive flux's all over the place. Gena couldn't believe  we had done that! I had to demonstrate to her how sensitive those things are by holding a magnet in my hand 2 feet away, then changing our heading with a flick of my wrist.

Oh well, back to the drawing board.

The whole re-designing, still while in the water, came rather easily though. I went through all sorts of ideas stored in the back of my mind from years of devious thinking, just how, exactly, to sense a water level inside a steel tank without using mechanical levers.

The ideas that came to mind were:
(a) seal the plastic tube and use the pressure of water to change    readings on a barometric pressure sensor
(b) use acoustical differences in ultrasonics inside the tube
(c) use temperature sensors down the inside of the tube
(d) use infra red sensor to take mean average temperature
(e) use inductance of a coil wrapped on the antenna inside the tube to alter the frequency of an oscillator.
(f) float the tube and use a load cell (borders on mechanical)
(g) use similar to (e) but read the SWR on the "antenna"
(h) use capacitance of a wire inside the tube to the "water" outside

Most of these ideas require a lot of work. If you're like me, you'd like to get the job done as easily and cheaply as possible. I tried the idea (e) first, just because I was curious to see if it'd work. I used an inductance meter and was very unhappy with the results. Inductance sucks under water. Idea (h) came to me as a result of hanging over the side testing for idea (e)! The difference in capacitance was small, but nevertheless consistent. 

After some monkeying around, it became apparent that I needed to have a "plate" that hugged the inside of the plastic tube to maximize capacitance variation. A copper pipe (1/2") fit perfectly inside the tubing. Then I set to work designing an oscillator for the new pipe/water capacitor to deviate. I didn't really feel like making a PC board, especially in the water and the boat moving around so much as it was. Then another shot from the blue! There doesn't need to be an oscillator.

A cheap method of reading a potentiometer with a microcontroller if there are no ADCs on it is to use a capacitor, then strobe the cap and pot using the RC time constant to calculate the position of the pot. This is pretty accurate as I used it to read 16 pots at once on a home brew  midi-controller.
The copper pipe and water are the RC, with only a small pull down required. The pull down would vary depending on the capacitance induced but I ended up using a 30k resistor.

The ADC for the tank is on port B.4 as can be seen in the new diagram. The pull ups on port B are still there on my board (except at B1,B2&B4) but are no longer needed.

The display board now has a piezo speaker on Port A,3 and makes a cute little bell sound every so often if the tank is full.

level-by-sds.zip has the new .asm files (right click, save as..) and the diagram. If a password is requested opening the zip, use "bigboat".

The actual tube/depth test from end to end in salt water was from 200pf to 420pf, but that changed in the tank. I had a ground pigtail to hook to the tank (DC isolated with a cap!), but it made no real difference.

Below is a photo of the "shop afloat" being actually used for the first time ever! It was quite comfortable to use. SMDs are excellent in this scenario, my entire collection of pots, resistors, caps, diodes, SMT LEDs, and transistors are in those mounted pill boxes on the door and under shelf. each set has 28 compartments, and there are 4.

 

*done!(Yet Again!) August 2008

 


to Individual projects main page