Coffee Machine Water Level Gauge
Specification
This design uses a standard 0->190 ohm fuel/water level
gauge and lights some RGB LEDs in a sequence depending on the level.
The design was fitted to our coffee machine, with the level gauge
in the water tank, and the LEDs mounted underneath. When it starts glowing red, it’s time to top
up. We did this because the machine is
on a timer which comes on every morning.
It takes 15 minutes or so to warm up, so it’s really annoying if it has
run out of water.
Power
|
12V 10W max
|
LEDs
|
1W RGB LEDs, 2 in series
|
LED current
|
0 – 200mA PWM, 100Hz
|
Colours
|
8 bit RGB, gamma corrected
|
Level look up table
|
8 steps (to match the 8 steps of the level gauge)
|
Circuit
Technical Description
LED driver
The LEDs are driven with a simple NPN transistor and 30 ohm
series resistor from 12V. Assuming 3V
LED Vf, this gives around 200mA LED current.
The 30 ohm series resistor was made from 2 off 15 ohm 1W resistors in series, but you can use whatever
you have available with suitable power rating.
This isn’t very efficient but a lot simpler than using a switch-mode LED
controller. If you have suitable LED
controllers available, you can input the PWM signal into them instead.
Level Gauge
The level gauge is based on a sliding magnet in the liquid,
and reed switches within the rod. The
type I used has 8 steps of 0 to 190 ohm.
0 ohm when empty, 190 ohm when full.
This is connected in a potential divider running from 12V to obtain a
range of 0.5 to 2V, which is input to the microcontroller comparator.
There is a microswitch under our water tank, so we made sure
it goes red well before this switch activates.
This was done by checking the gauge reading at the point the switch
activates.
You can order such gauges on Amazon from China in around 30 days..
Level Gauge ADC
The level gauge voltage is input to the positive side of the
comparator of the microcontroller. The
negative side is connected to a DAC. By
adjusting the DAC until the comparator toggles, we form an ADC which can read
the level gauge voltage.
The DAC is formed by low pass filtering a PWM signal from
pin RB5. This runs at 100Hz, using the
same software routines that generate the PWM signals for the LEDs. This PWM DAC has an 8 bit control range.
The software has a loop which increments the PWM DAC when
the comparator is high, and decrements when low. This loop runs every approx. 100ms, so it
takes around 26 seconds for the level gauge ADC to ramp from one end to the
other. This is fast enough for the level
gauge, which only changes slowly.
LED PWM
The LED driver is driven by the RB1, 3 and 4 pins at
100Hz. An interrupt routine runs every
10ms to generate this PWM. The internal
microcontroller PWM generators are not used as they cannot generate the 4
independent PWM signals required by this application. Note an initial design at 50Hz was too flickery.
The level gauge ADC reading is looked up in a table of RGB
values, and applied to the LED PWM settings.
The window for each step is chosen to match the steps of the level gauge
to avoid the design flickering between two colours.
Serial Port
The circuit shows a serial port input. This is not used in this application, but is
there for debug purposes or other applications.
The software would need modifying to use this, as currently the level gauge overrides the serial port values.
Software
Software was written for PIC 16F627 using MPLAB X 5.25. You can use other PICs/microcontrollers and build
tools. I used 16F627 as I had some
spare. Other microcontrollers might make
the implementation easier if they include enough PWM generators and an ADC.
The software can be found
here as a zip file.
It is based on previous software, with code added to implement the
8 colour steps as per below.
The PWM frequency was increased to 100Hz as I found 50Hz far
too flickery.
With the serial port code removed, the memory usage is as
follows.
Memory
Summary:
Program space used
308h ( 776) of 400h words ( 75.8%)
Data space used 23h (
35) of E0h bytes ( 15.6%)
EEPROM space used 0h (
0) of 80h bytes (
0.0%)
Data stack space used
0h ( 0) of 50h bytes (
0.0%)
Configuration bits used
1h ( 1) of 1h word (100.0%)
ID Location space used
0h ( 0) of 4h bytes (
0.0%)
|
The microcontroller is mounted in a socket and removed to
program it. I used a Vellaman K8048
programmer with PicProg2009 running on my PC.
There are more modern programmers available!
Level Gauge Steps
Level gauge configured as potential divider.
Resistance is 0-190 ohms with 8 steps as measured below.
Top resistor 1k2 to 12V.
Bottom resistor 51 ohm to give offset of 0.5V to ensure comparator
works.
Vpwm is 2.5V as I use a potential divider of factor 2 (two
10k resistors) to better match the range of the voltages from the gauge.
Rlevel
|
Rtop
|
Rbot
|
I
|
V
|
PWM
|
PWM decimal
|
PWM low
|
PWM high
|
LED Colour
|
0
|
1200
|
51
|
9.6E-3
|
0.489209
|
19.57%
|
50
|
0
|
73
|
RED
|
51
|
1200
|
51
|
9.2E-3
|
0.940092
|
37.60%
|
96
|
73
|
104
|
RED
|
71
|
1200
|
51
|
9.1E-3
|
1.107413
|
44.30%
|
113
|
104
|
121
|
BLUE
|
90
|
1200
|
51
|
8.9E-3
|
1.261745
|
50.47%
|
129
|
121
|
137
|
GREEN
|
110
|
1200
|
51
|
8.8E-3
|
1.419544
|
56.78%
|
145
|
137
|
153
|
GREEN
|
130
|
1200
|
51
|
8.7E-3
|
1.572773
|
62.91%
|
160
|
153
|
172
|
GREEN
|
160
|
1200
|
51
|
8.5E-3
|
1.794472
|
71.78%
|
183
|
172
|
194
|
WHITE
|
190
|
1200
|
51
|
8.3E-3
|
2.00694
|
80.28%
|
205
|
194
|
255
|
WHITE
|
The PWM high and low values show the window to avoid sitting on a step.
The following table implements the above steps in the
program.
//Table of
colours for each level step. There are
8 steps.
const
unsigned char pwmdac_max[]={73,104,121,137,153,172,194,255};
const
unsigned char led1_steps[]={200,200,0
,0 ,0 ,0
,180,180}; //red
const
unsigned char led2_steps[]={0 ,0 ,0
,200,200,200,180,180}; //green
const
unsigned char led3_steps[]={0 ,0 ,200,0
,0 ,0 ,180,180};
//blue
|
You can change these tables to match different level gauges
with different steps, or to change what colours are used.
Construction
I built this on matrix board and bolted it under the drip
tray of our coffee machine.
The LEDs are mounted on standard metalback PCBs which you
can buy online. These were mounted on
some matrix board. Here’s a couple of
photos of the part finished matrix board:-
Here it is mounted under the drip tray:-
The 12V is provided by an external power adaptor via a 2.1mm
barrel socket. The other wire goes to
the level gauge. LEDs are on the bottom.
It’s a bit messy, but hidden underneath:-
If you want to do a proper job, design a PCB!
The level gauge is mounted by cutting an extra hole in the reservoir:-