Building a Capacitive Liquid Sensor

197,430

166

56

Posted

Introduction: 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.

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.

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.

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

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.


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.


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.


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 ");
  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);
    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);
}

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.

Share

  • Can a clear circuit ...-smartwatch

    smartwatch made it!

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • Sew Warm Contest 2018

    Sew Warm Contest 2018
  • Gluten Free Challenge

    Gluten Free Challenge
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

54 Comments

Hi VadimS...

Great project and Instructable!

I'm building one of these today for a big project I'm working on for a client...a remote controlled tracked personnel carrier (tank)!

You mention at the end that this will work on a propane tank...is that really true since those are usually metal? I have not seen a non-metal propane tank.

Thank you!

Sorry didn't make it. Typo below. Need help

great project

can i place your project on my website.

i'm working on a website which is related to electrical projects.

i also mention your name, link and other info.

plz reply

@Abhi909 The answer is yes, and you don't really have to ask unless you want "special permission." At the top right it says it's licensed Creative Commons Attribution-NonCommercial-ShareAlike 2.5 Generic (CC BY-NC-SA 2.5). If you click it you can view the details: http://creativecommons.org/licenses/by-nc-sa/2.5/ As long as you follow the license rules you're fine.

Nice work sir! I have few questions:

1. Did the aluminum foil is putted in the 2 sides of the bottle?

2. If 2 sides of foil is attached, where I can tap the wire on arduino specially the ground of the foils? and the data.

3. Can I replace the LCD for simple LED with 3 water levels?

4. Is this applicable for Glass Bottle?

Thanks in advance! Happy Developing!

Agree, interesting project. I just tried it and it works pretty good! However, I have some comments/thoughts and was wondering if anybody could provide some feedback.
1. Since temperature could change the result, I was wondering if a temperature sensor was implemented, could this keep it calibrated? I assume the liquid temperature would be most important. I was thinking a temperature sensor attached to the water bottle at the lowest point.
2. The instructions mentioned that shielded cable would work better. Would you put the shield to the ground piece of foil and the center wire to the other foil (sense)? I did notice that the results we jumpy and that my hand would throw it off. I wonder if the shielded cable would help the result be more consistent and prevent the noise (from my hand).
3. I see in the image of the water bottle that the wire is soldered to the foil and then wrapped around the bottle a few times. It also appears you twisted the lead back. Are these important steps as well? Would they help with the noise? Would they be required if you are using shielded wire?

I also saw another writeup on this method and it mentions using an insulator over the foil and then another layer all the way around that is a ground plane.

Thanks!

1: The best you can hope for is +- 5%, it's not vary accurate, and impurities in the water will affect the result far more then temperature.
2: Two conductor shielded cable. The shield should not be used as a conductor.
3: It's not wrapped around the bottle? The cable I used at the time was a twisted pair from an Ethernet cable.
4: An insulator and extra layer of foil would act as a shield

A far better option is a float attached to a potentiometer. I only used this because I could not put anything inside the tank.

3. What do you mean by saying: "It's not wrapped around the bottle?". It's must be wrapped around the bottle or not?
Thanks !

its half on one side, and half on the other side i thinkl

hi sir.i admire your project..im making a fuel level sensor.. please help me for my project.. can this work to the fuel tank?