3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Building a Capacitive Liquid Sensor

Step 7Programming

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);
}
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
8
Followers
3
Author:VadimS