This entry was posted in no categories.

Watertank Depth and Temperature Sensor

Watertank Depth and Temperature sensor, with LCD Screen - Arduino Project

The Project

It began as an experiment with the Arduino kit over christmas and building a temperature sensor ... after building the example from the tutorial book that was quickly extended to displaying the current temperature in binary with some LED's. Then the discussions began - how do we measure the tank water depth? This project does just that with the sensor for distance (it works as distance to water!!!!) and the breadboard has a temperature and humidity sensor as well. To make life easy all the data is output to the LCD screen and the buttons around the screen are used to control what is displayed.

I have had the board powered on for the last couple of days... and coming downstairs this morning I noticed there was NOTHING on the LCD screen - fearing a short I powered off the board and left things until I got home from work - repowered it up and noticed some faint lettering... It was working but the LCD had faded? can it do that? I've been able to tweak the pot on the LCD screen to change the brightness - but I think it's now changing on me...

Moving forward... I'd like to add the cell phone calling module to the Arduino and send it a text message and get a response of tank depth remotely one day... but at ~$150 - that's a bit expensive for this purpose - but it could be fun and illustrates potential.

/* ---------------------------------------------------------
 * | David G. Wilson
 * | 30 December 2012
 * ---------------------------------------------------------
 * 
 * A simple program to output the current temperature to LCD Screen
 * 
 * https://www.sparkfun.com/products/11282
 * 
 *
 */
#include 
#include 
#include "Wire.h"
//#include "Adafruit_BMP085.h"
LCDKeypad lcd;
//Adafruit_BMP085 bmp;
// Altitude for BMP085 Adjustment
// http://learn.adafruit.com/bmp085/using-the-bmp085
// requires knowing pressure at sealevel in pascals
float seaLevelPressure = 100100;
// Range Finder
int rangePin = 2;
// http://www.maxbotix.com/articles/016.htm
float scaleFactor = 5.0 / 512; // 5.0 = supplied voltage
// LCD Print information
int optionStart;
int previousOption;
int availableDisplayOptions; // is NOT zero relative
float tankDepth; // measure in meters
float tankOffset; // max fill to head of tank
// -----------------------
#define BMP085_ADDRESS 0x77 // I2C address of BMP085
const unsigned char OSS = 0; // Oversampling Setting
// Calibration values
int ac1;
int ac2; 
int ac3; 
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1; 
int b2;
int mb;
int mc;
int md;
// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5; 
short temperature;
long pressure;
const float p0 = 100900; // Pressure at sea level (Pa)
float altitude;
// -----------------------
/*
 * setup() - this function runs once when you turn your Arduino on
 */
void setup()
{
 lcd.begin(16, 2);
 lcd.clear();
// bmp.begin(); 
 Wire.begin();
 bmp085Calibration();
 availableDisplayOptions = 5;
 optionStart = 0;
 previousOption = 999; // begin with some high number
 tankDepth = 2.4;
 tankOffset = 0.400; 
}
void loop() // run over and over again
{
 lcd.clear();
 lcd.print("LEFT = tank depth");
 lcd.setCursor(0,1);
 lcd.print("RIGHT = display");
 int buttonPressed;
 do
 {
 buttonPressed=waitButton();
 }
 while(!(buttonPressed==KEYPAD_LEFT || buttonPressed==KEYPAD_RIGHT));
 waitReleaseButton();
 // LEFT = set tank depth
 // RIGHT = stats display
 if (buttonPressed==KEYPAD_LEFT)
 {
 tankSetUp();
 }
 else if (buttonPressed==KEYPAD_RIGHT)
 {
 sensorStatsDisplay(); // will loop until select is pressed
 }
}
void tankSetUp()
{
 lcd.clear();
 int buttonPressed;
 do
 {
 lcd.setCursor(0,0);
 lcd.print("Depth=");
 lcd.print(tankDepth,2);
 lcd.setCursor(0,1);
 lcd.print("UP/DOWN to change - select to Exit");
 buttonPressed=waitButton();
 if (buttonPressed==KEYPAD_UP)
 tankDepth = tankDepth + 0.01;
 if (buttonPressed==KEYPAD_DOWN)
 tankDepth = tankDepth - 0.01;
 }
 while(!(buttonPressed==KEYPAD_SELECT));
 waitReleaseButton();
}
void sensorStatsDisplay() // run over and over again
{
 int button;
 do
 {
 button = buttonPressed();
 if (button == KEYPAD_UP)
 optionStart = optionStart - 1;
 if (button == KEYPAD_DOWN)
 optionStart = optionStart + 1;
 if (optionStart <0) optionstart="0;" if (optionstart> availableDisplayOptions - 2) 
 optionStart = availableDisplayOptions - 2; // value should be one less than max so that the last 2 x lines are displayed
 if (previousOption != optionStart)
 lcd.clear();
 int lcdLineNumber = 0; 
// Option 0 - RANGE FINDER
 if (optionStart == 0)
 {
 lcd.setCursor(0,lcdLineNumber);
 float range = getVoltage(rangePin) / scaleFactor; // result is range in inches
 range = range * 2.54; // output in centimeters
 lcd.print("Range: ");
 lcd.print(range,2);
 lcdLineNumber = lcdLineNumber + 1;
 }
// Option 1 - Water Tank Fill
 if (optionStart == 0 || optionStart == 1)
 {
 lcd.setCursor(0,lcdLineNumber);
 float range = getVoltag
You must be logged in to post comments.