Building A Capacitive Liquid Sensor

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Home Sign Up!

Browse Community Submit


All Art Craft Food Games Green Home Kids Life Music Offbeat Outdoors Pets Photo Ride Science Tech

Building a Capacitive Liquid Sensor


by VadimS on December 7, 2009

Table of Contents

Building a Capacitive Liquid Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

Intro: Building a Capacitive Liquid Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 1: Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 2: Connecting the LCD and letting your creation talk to the world. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

Step 3: Connecting the LCD Continued. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

Step 4: Data Lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Step 5: Power MaHaHaHa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Step 6: Make Capacitive Sensor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

Step 7: Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

Step 8: Stuff . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

http://www.instructables.com/id/Building-a-Capacitive-Liquid-Sensor/
Intro: Building a Capacitive Liquid Sensor
A capacitive liquid sponsor relies on the fact the the capacitance or charge between 2 metal plates will change (in this case increase) depending on what material is
between them.
This allows us to create a level sensor that is safe for use with any liquid, this one will be used in a buggy with gasoline (petrol).

One plate is hooked to ground. The other connects to pin 23. There is a 820K ohm resistor from pin 22 to 23. The sensor works by charging the capacitor (the water
bottle) and measuring how long it takes to drain through the resistor.

Image Notes
1. A temperature sensor that I salvaged from a projector. It uses the I2C interface so I won't be getting into it in this instructable.
2. That's supposed to be a gas pump, looks better in person.

Step 1: Parts
1. A solder-less bread board is strictly not needed but make it a lot easier, especially if you plan to add other stuff later.
2. Arduino, I'm using an Arduino mega but a standard one should have just enough pins.
3. LCD character display.
4. Some odds and ends including some wire and a 1M? resistor.
5. A computer, you know, that thing your using to read my instructable with.
6. Patience.

Image Notes
1. It's a 820K ohm but you should use 1M ohm.

Step 2: Connecting the LCD and letting your creation talk to the world.
Like every step in this instructable there are many ways to do this. I will show you my favorite.

Your lcd has 16 throe hole solder pads so the first thing is to attach some pins. If your patent then I recommend purchasing a header like this
http://www.sparkfun.com/commerce/product_info.php?products_id=117. But if you want to get done as fast as possible (like me) then you can use wire.
Simple cut 16 pieces of wire at about 1/2" (13mm (longer is okay)). Then solder them to the board.

http://www.instructables.com/id/Building-a-Capacitive-Liquid-Sensor/
Image Notes
1. I soldered from the other side.

Step 3: Connecting the LCD Continued.


Sins I'm using special characters I will be connecting all the wires.

Pin 1 Ground
Pin 2 +5 Volt
Pin 3 Contrast adjust
Pin 4 RS
Pin 5 R/W Goes to Ground
Pin 6-14 Data
Pin 15 Back-light Power
Pin 16 Back-light Ground

Image Notes
1. 16
2. 15
3. 01
4. 02
5. 5
6. Contrast adjust pot.

http://www.instructables.com/id/Building-a-Capacitive-Liquid-Sensor/
Step 4: Data Lines
Now you need to connect the Arduino to the lcd.
It doesn't mater what pins you use, but I recommend following the schematic.

Image Notes
1. Not my image obtained form http://arduino.cc/en/

Image Notes
1. A Bit of a mess.

Step 5: Power MaHaHaHa


The usb port on you computer has enough power to run the Arduino and led back-light so just connect the ground and power rails on you bread board to the power out on
the Arduino board.

Image Notes
1. Ground
2. 5v out
3. 3.3v out

Step 6: Make Capacitive Sensor


For testing i used aluminum foil and a plastic water bottle, It will work with any container so long as it isn't metal.

You can use any type of wire but any non shielded lines will provide poor performance.

You can use any 2 pins, I chose 22 and 23.

Connect one side to ground and the other to a resister and 2 I/O pins.

http://www.instructables.com/id/Building-a-Capacitive-Liquid-Sensor/
Image Notes
1. Soldered on.
Image Notes
1. Ground
2. Receive
3. Send

Step 7: Programming
You need to add 2 library files to make this work
LiquidCrystal.h http://arduino.cc/en/Tutorial/LiquidCrystal
CapSense.h http://www.arduino.cc/playground/Main/CapSense

Copy and past this into Arduino 0017 or newer.

//Capacitive Liquid Sensor


//Vadim December 7th 2009
#include
#include

//This is to set the size of the lcd


const int numRows = f=4;
const int numCols = 20;

//This sets the pins for the lcd (RS, Enable, data 0-7)
LiquidCrystal lcd (53, 52, 51, 50, 49, 48,47,46,45,44);
#define Tempin 0x48
#define Tempout 0x49
CapSense cs_22_23 = CapSense(22,23);

uint8_t block[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};

uint8_t tl[8] = {0x0F,0x08,0x08,0x08,0x08,0x08,0x0F,0x0F};


uint8_t tr[8] = {0x16,0x11,0x11,0x11,0x11,0x11,0x1D,0x15};
uint8_t bl[8] = {0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x1F};
uint8_t br[8] = {0x15,0x15,0x15,0x15,0x15,0x15,0x12,0x18};
void setup() {
lcd.begin(numRows, numCols);
lcd.createChar(4, tl);
lcd.createChar(5, tr);
lcd.createChar(6, bl);
lcd.createChar(7, br);

lcd.setCursor(18,0);
lcd.print(4, BYTE);
lcd.setCursor(19,0);
lcd.print(5, BYTE);
lcd.setCursor(18,1);
lcd.print(6, BYTE);
lcd.setCursor(19,1);
lcd.print(7, BYTE);

lcd.setCursor(0,2);
lcd.print("Fuel ");
http://www.instructables.com/id/Building-a-Capacitive-Liquid-Sensor/
lcd.setCursor(0,3);
lcd.print("E");
}

void loop() {
long fuel;
lcd.createChar(2, block);

long start = millis();


fuel = cs_22_23.capSenseRaw(200);

//Temratue makes a bit of a difrence so let it run for 5 min before tuning.
//Adjust this number so that the output is as close to zero as posible.
fuel = fuel - 7200;
//Then fill up the conataner
//Un-comment and adjust this so that the output, when the container is full,
//is as close to 100 as possible.
//fuel = fuel / 93;

lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print(fuel);

if (fuel >= 6) {
lcd.setCursor(1,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(1,3);
lcd.print(" ");
}
if (fuel >= 12) {
lcd.setCursor(2,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(2,3);
lcd.print(" ");
}
if (fuel >= 17) {
lcd.setCursor(3,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(3,3);
lcd.print(" ");
}
if (fuel >= 23) {
lcd.setCursor(4,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(4,3);
lcd.print(" ");
}
if (fuel >= 28) {
lcd.setCursor(5,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(5,3);
lcd.print(" ");
}
if (fuel >= 34) {
lcd.setCursor(6,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(6,3);
lcd.print(" ");
}
if (fuel >= 39) {
lcd.setCursor(7,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(7,3);
lcd.print(" ");
}
if (fuel >= 44) {
lcd.setCursor(8,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(8,3);
lcd.print(" ");
}
if (fuel >= 50) {
lcd.setCursor(9,3);
http://www.instructables.com/id/Building-a-Capacitive-Liquid-Sensor/
lcd.print(2, BYTE);
} else {
lcd.setCursor(9,3);
lcd.print(" ");
}
if (fuel >= 55) {
lcd.setCursor(10,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(10,3);
lcd.print(" ");
}
if (fuel >= 60) {
lcd.setCursor(11,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(11,3);
lcd.print(" ");
}
if (fuel >= 64) {
lcd.setCursor(12,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(12,3);
lcd.print(" ");
}
if (fuel >= 69) {
lcd.setCursor(13,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(13,3);
lcd.print(" ");
}
if (fuel >= 74) {
lcd.setCursor(14,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(14,3);
lcd.print(" ");
}
if (fuel >= 78) {
lcd.setCursor(15,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(15,3);
lcd.print(" ");
}
if (fuel >= 83) {
lcd.setCursor(16,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(16,3);
lcd.print(" ");
}
if (fuel >= 87) {
lcd.setCursor(17,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(17,3);
lcd.print(" ");
}
if (fuel >= 92) {
lcd.setCursor(18,3);
lcd.print(2, BYTE);
} else {
lcd.setCursor(18,3);
lcd.print(" ");
}
if (fuel >= 96) {
lcd.setCursor(19,3);
lcd.print("F");
} else {
lcd.setCursor(19,3);
lcd.print(" ");
}

delay (50);
}

http://www.instructables.com/id/Building-a-Capacitive-Liquid-Sensor/
Image Notes
1. Apple uses automated schnapps IVs.

Step 8: Stuff
This is perfect for measuring volatile liquids, even works inside a propane tank.
Have fun.

Any and all information is for educational purposes only and I can not be held responsible if you blow yourself up.

Related Instructables

Powering the Arduino


The Arduino Arduino Mega Controlled Capacitive
Weather Station with a Lithium Motion Sensor touch
/ Thermostat by Question Box Mood/Ambilight Belvedere - A
Battery by by LemonSlice
sspence Puzzle by by lunar Butler Robot by
inthebitz
davewking wolffan

Comments
25 comments Add Comment

29guitarman says: Mar 31, 2011. 4:40 AM REPLY


hey yeah, how did you connect the wires aswell? can you explain further on how you set the bottle out?
Cheers

VadimS says: Mar 31, 2011. 12:49 PM REPLY


2 pieces of aluminum foil on aether side. One wire soldered to each.

One acts as a ground, the other sens.


doesn't matter witch way around you set it up.

The sheets should go from the bottom to top of the container.

It's a bit of a pain to solder aluminum foil but can be done. otherwise anything conductive.

lw119 says: Nov 29, 2010. 5:55 PM REPLY


This is pretty clever. I think I am going to try something similar.

I have pet cockatiels that love to backwash in their water dish. It doesn't take long for the water to get kinda nasty. I wonder if something like this could be
used to alert me when their water needs a change out.

Have you ever noticed a significant reaction to the electrolyte getting contaminated? Any tips you can offer would be much appreciated.

http://www.instructables.com/id/Building-a-Capacitive-Liquid-Sensor/
Thanks for the inspiration.

VadimS says: Nov 29, 2010. 6:21 PM REPLY


Hmm, never tried. I don't think it would be able to tell the difference between a change in water lvl and stuff in the water.

Using an infrared led on one side and a receiver on the other could be used to detect when impuritys where in the water.

lw119 says: Nov 29, 2010. 6:55 PM REPLY


I have a float that maintains the water level so I don't think that would be an issue.

I considered the infrared idea but they like to bathe in the water too, so that might trip it. Plus, they like to break things, so I was hoping some
submerged concentric metals tubes would be beak proof.

I guess it's a trivial problem but a fun challenge.

Thanks for the reply.

Hunter601 says: Oct 14, 2010. 3:18 AM REPLY


Hmm.. I'm trying to figure out if this would be the right way to measure the qty of Heating oil left in a 1000 Liter plastic tank, which is about 160 cm high and
the other dimensions about 80 cm each.
I haven't noticed (or have overlooked) any max practical size for your setup but I assume it might not work out for my requirements, right?

Could anyone point me in the right direction? Maybe sink a pressure sensor to the bottom of the tank and read out the static pressure, using an Arduino?

VadimS says: Oct 14, 2010. 6:46 AM REPLY


The accuracy decreases when you move the plates away from each-other.

Your best bet would be to use a couple metal pipes. one inside the other making shire they don't touch.

Then use this setup to measure the capacitance between them.

Another option is a simple float inside a tube, with a small magnet attached to it. Then put some read switches along the length of the pipe.

Hunter601 says: Oct 14, 2010. 7:23 AM REPLY


Ok, concentric tubes makes good sense. Thanks for the tip.

TheBestJohn says: May 25, 2010. 11:11 AM REPLY


2 questions and a comment.

1: so the two aluminum sheets sit outside the container? one on either side of it?

2: would there not be a risk of the capacitor discharging and creating a spark?

Comment: NO METAL CONTAINERS!? I guess a keg level sensor is out of the picture lol.

VadimS says: Jul 16, 2010. 8:43 AM REPLY


Kind of lait, but anyway. The plates only run at 5v so a spark is extremely unlikely. You can build one to go in a keg using a metal rod and a metal pipe
but you would have to modify the keg and re-weld it when you're done (not so easy on aluminum. Yes the sheets sit on the outside. Thay can be put on
the inside but need to be electrically isolated from the licqwid.

linkthewise says: May 7, 2010. 12:56 AM REPLY


Hey I one question did you cut the aTinFoil in two pieces and you put them in the sides of the conteiner?.

zoltzerino says: Apr 9, 2010. 4:49 PM REPLY


Good Instructable, nice XKCD reference...it's so true ;-)

MomentumV says: Feb 2, 2010. 8:09 AM REPLY


how well did this work with petrol instead of water?

VadimS says: Feb 17, 2010. 12:42 PM REPLY


We broke a few things on the buggy so it hasn't bean installed yet. But I did test it with gasoline (petrol) and it works, it's accuracy is down a bit at about
10%, with water it was within 5%.

http://www.instructables.com/id/Building-a-Capacitive-Liquid-Sensor/
makkan says: Jan 28, 2010. 11:44 PM REPLY
Just what I have been looking for to measure the coffee level in the office coffee machine.

bullzebub says: Dec 9, 2009. 3:16 AM REPLY


how are you going to handle the odd shapes of a gas tank?
it would be nice to have someting that shows a realistic approximation on whats left in the tank.... not like most car systems

VadimS says: Dec 9, 2009. 1:36 PM REPLY


It was built for a specific tank from a 10 hp brigs attached to a buggy.

lemonie says: Dec 8, 2009. 12:20 PM REPLY


The permittivity of water is about 80x that of air, the permittivity of gasoline is about 2x. Are you confident this will be sensitive enough on a gas-tank?

VadimS says: Dec 8, 2009. 1:35 PM REPLY


I originally thought that gasoline would be smiler to water.
But I'll find out for sure Thursday night.

I might just use the howl tank as in plate, plastic tank, plate.

lemonie says: Dec 8, 2009. 1:38 PM REPLY


No, it's much more similar to air, water is more polarised / ionic. But do let us know how it works out.

pelrun says: Dec 7, 2009. 8:08 PM REPLY


Sweet 'ible, but can you elaborate more on exactly how the bottle is wired up? It's rather brief and ambiguous at the moment...

VadimS says: Dec 7, 2009. 10:17 PM REPLY


I just got lazy. I intend to add more after I test it on a real gas tank (Tonight or Thursday night).

VadimS says: Dec 7, 2009. 10:25 PM REPLY


I answered your specific question, hope it helps.

jam BD says: Dec 7, 2009. 7:51 PM REPLY


nicely done =D

Erik Lindemann says: Dec 7, 2009. 7:34 PM REPLY


Favoriting this. I love the logic that went into this homebrew liquid level sensor.

http://www.instructables.com/id/Building-a-Capacitive-Liquid-Sensor/

You might also like