Go Down

Topic: Water Level Sensor for Water Tank (Read 31601 times) previous topic - next topic


I once accidentally killed some lobsters via immersion in fresh water when I was a kid - didn't know better.

Was the water boiling?
The art of getting good answers lies in asking good questions.


Was the water boiling?

:P It was cold tap water. Between osmosis and whatever the water company adds to the wate to make it biologically safe, they were dead within an hour. It's one way to reduce the saltiness of their flesh, I suppose.  :smiley-eek-blue:


So here is an update to my progress. 

I got the eTape and the arduino Uno and the ethernet shield. I used some basic code from adafruit.com and I'm getting resistance readings in the debug panel.

Here is the exact code I put in:

Code: [Select]
// the value of the 'other' resistor

// What pin to connect the sensor to
#define SENSORPIN A0

void setup(void) {

void loop(void) {
float reading;

reading = analogRead(SENSORPIN);

Serial.print("Analog reading ");

// convert the value to resistance
reading = (1023 / reading) - 1;
reading = SERIESRESISTOR / reading;
Serial.print("Sensor resistance ");


And this is the way I wired it.

I connected pin #2 of the sensor to ground, then pin #3 to a 560 ohm resistor. The other side of the 560 ohm resistor to VCC to create a resistor divider. Pin #4 is between the sensor and the resistor and pin#1 to A0 on the arduino.

I read through a lot of the documentation and most of it is over my head to be honest.  I tried to the code examples that were given here http://www.parallax.com/tabid/768/ProductID/590/Default.aspx but they get kicked back on verify in the arduino software.

Also, most of the documentation on the eTape is for an older version.  The version written about has only two pins, the newer version has four pins.

At the end of the day, what I want is for the arduino to printout a "percent" that tells me the water level.  From that point, I want to have that info uploaded via ethernet to Cosm or possibly send me an email with the reading once a day.

Can anyone help me with the next step in this?  Essentially that would be getting the code printout a percentage reading telling me how much water is in the tank.  Also, do I need to wire this sensor differently?  From the datasheet it can be wired in these manors (non of the mean anything to me), simple voltage divider, whitestone bridge and differential op-amp. 


How does this look for code and I have a few questions regarding the output. 

1.  Its giving me what seems like a pretty accurate reading.  I do notice that the analog reading does vary a bit from 679-680, anyway to smooth that out? 

2.  Is it necessary to run a calibration script?

3.  Any suggestions on where to begin with uploading this data via the Ethernet shield?

Code: [Select]
int sensorMin = 680;
int sensorMax = 783;
void setup() {
  // initialize serial communication at 9600 bits per second:

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float depth = sensorMax - sensorValue;
  float depth2 = sensorMax - sensorMin;
  float percentFull = (depth / depth2) * 100;
  Serial.print("Percent Full %");


A couple of things you can do.

For one, I would avoid long delays and use the time instead to do something useful. Like lots of analog reads that you can either average (solving your problem) or decimate to actually potentially get better resolution than 10 bits out of your 10-bit ADC. Google Decimation and Atmel, go over the paper published by Atmel and learn how right-shifting can become very interesting indeed.

Calibration scripts are tricky because you presume that you can measure the range of fill heights. I would avoid doing this as part of every setup() function... rather, I'd use the serial monitor to wait for input and if the right command is sent from your CPU to the Arduino, the calibration script is initiated. However, instead of keeping the values in the actual program, you'd have to store them in the EEPROM space instead. That way, they'd be available the next time the Arduino is restarted.

As for ethernet and all that, I'd look into getting a Cosm account and then download the Cosm client. Once you've managed to upload random data, you can graduate on to merging the two programs to upload the data of interest.


That is a very interesting article, thank you for sharing that with me. Thankfully I don't need my data to that exact, I think if I do an average of readings it will smooth things into a more than acceptable range for me. 

When I looked into averaging sensor readings, the code below is the only thing I could find.  Is that the correct code to use?  Or do you know of a better option?

As for the ethernet, I was able to get my data up and posting to cosm, it works very well.  The downfall for me with cosm is that there is no iphone app.  Ideally I would like to get this data transmitted to my iphone via email or have the arduino create some sort of rss feed that I can monitor.  Any suggestions?  I tried setting up the wiznet web server but it never seemed to work. 
Code: [Select]


  Reads repeatedly from an analog input, calculating a running average
  and printing it to the computer.  Keeps ten readings in an array and
  continually averages them.
  The circuit:
    * Analog sensor (potentiometer will do) attached to analog input 0

  Created 22 April 2007
  By David A. Mellis  <dam@mellis.org>
  modified 9 Apr 2012
  by Tom Igoe
  This example code is in the public domain.


// Define the number of samples to keep track of.  The higher the number,
// the more the readings will be smoothed, but the slower the output will
// respond to the input.  Using a constant rather than a normal variable lets
// use this value to determine the size of the readings array.
const int numReadings = 10;

int readings[numReadings];      // the readings from the analog input
int index = 0;                  // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

int inputPin = A0;

void setup()
  // initialize serial communication with computer:
  // initialize all the readings to 0:
  for (int thisReading = 0; thisReading < numReadings; thisReading++)
    readings[thisReading] = 0;         

void loop() {
  // subtract the last reading:
  total= total - readings[index];         
  // read from the sensor: 
  readings[index] = analogRead(inputPin);
  // add the reading to the total:
  total= total + readings[index];       
  // advance to the next position in the array: 
  index = index + 1;                   

  // if we're at the end of the array...
  if (index >= numReadings)             
    // ...wrap around to the beginning:
    index = 0;                           

  // calculate the average:
  average = total / numReadings;         
  // send it to the computer as ASCII digits
  delay(1);        // delay in between reads for stability           


A running average is a good way to do it. 10 readings should be sufficient. Another approach could be to use a capacitor on the inputs if the signal has some spiky transients in it.

As for getting stuff to the iPhone, one low-tech approach is having your shield send you a SMS when things are out of whack. I have no experience with the web-server, sorry.


Regard james Can you share me a complete code I'm a student and I need to practic to use  eTape to water level can you email code to me
thank you verymuch


Not sure if anyone has made this suggestion but I wanted to do something similar and was hoping to adapt one of thesewireless remote tank levels  kits  just buy adding a 433mhz shield ..... Assuming they use 433Mhz



can i use PT-500 Submersible Pressure Transducer with Arduino microcontroller board to measure water level in tank or well.


plz help its urgent.


Go Up