Introduction

This project is about a simple and easy way to monitor and measure any liquid level at your house. This is tested and fully working at the tank that I have at my basement full of petroleum. There are many times especially at the winder that I need to be aware of the level. Furthermore, It is quite useful to record how much petroleum have you consumed per year and gather all these information to economic analysis.

## Step 1: Hardware Parts

For this project I will be using the following:

• Arduino Uno
• Ethernet shield
• HC-SR04 UltraSonic Sensor
• Wires for connecting the sensor to arduino
• CAT5 cable
• Router
• Laptop

## Step 2: Upload the Software

Upload the software to the arduino before doing anything else. Please notice that the following code uses an ethernet shield and HTTP request to answer to a client (browser). So, in the next step we will see that the server responds with a HTTP request as written below. If you want for any reason to use a Wi-Fi shield or anything else you may need to modify the code.

The value (integer) that the user gets is simply what the sensor detects. So, actually its not the liquid level. BUT you can simply calculate the level if you abstract from the full tank the hypothetical liquid according to the value you just got. Simple mathematical equations.

```/*****************************************************************************
An idea for Future Smart Homes

Oil Monitoring is a project that lets you monitor the ammount of oil
at yourhome. Alerts you with a message on facebook, gmail or even SMS
the past.

* Arduino Uno
* Ethernet shield and ethernet cable | Wireless shield
* UltraSonic Distance Sensor
* Wires for arduino pins

Developed by Tzivaras Vasilis
Last Update: [10-06-2015]
*****************************************************************************/

#define echoPin 7
#define trigPin 8

#include <SPI.h>
#include <Ethernet.h>

// UltraSonic sensor min and max value to be accepted.
int maximumRange = 200;
int minimumRange = 0;

long duration, distance;

byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

// Open serial communications and wait for port to open:
Serial.begin(9600);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}

void getSensorValue() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

digitalWrite(trigPin, HIGH);
delayMicroseconds(10);

digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);

//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
}

void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");  // the connection will be closed after completion of the response
client.println("Refresh: 5");  // refresh the page automatically every 5 sec
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");

getSensorValue();
client.print("{\"id\":");
client.print("1770,");
client.print("\"measurement\":");
client.print(distance);
client.print("}");

client.println("<br />");
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
```

## Step 3: Connecting the Hardware

This is pretty easy to do. Grab four wires and connect them to the sensor and the Ethernet shield. Mount the shield over the arduino. Notice that the sensor has one GND (ground) one 5V (power) and two more pins named echo and trig. Echo is connected to 7 digital pin in arduino and trig to the 8 digital pin.

After that use cat5 cable to connect the shield with the router. Power up your laptop and go to the next step.

## Step 4: Test Everything Out

Now we are ready to test this out. Open a browser at your laptop and type 192.168.1.177. It should be working :)
Notice that at the code we uploaded we said that the arduino has the above IP. You can change it if you want. Now you can place the device at the tank.Place a router there and go to your home and type the IP and see how much water, or petroleum is left in your tank.

for any questions please comment bellow.

Hi, Thank you for sharing above info. <br>Can you tell me how to modify this to measure accurately remaining fuel in an oval shape tank ?
Curious... I was thinking of ways to make the sensor more resistant to things like water.. Would a rubber boot, or something like a small thumb condom work over the transducers... Not effecting it's capabilities?
<p>what is the max height that can be sensed with this sensor?</p>
<p>very good i will try to do it but i may use wireless and feed the data to the cloud i may need your help. i will let you know. thanks.</p>
<p>if you are measuring fuel this will not give you a accurate level, Your sensor should be re-calibrated for a different acoustic velocity. sound moves approximately 1110ft or 338m/s per second in natural gas environment. I'm not positive what a Fuel oil vapor density would be, but with a heavy vapor your wave would move faster.</p>
<p>please if you mail me that because i am not in the pro version..</p><p><strong>Hkasera7262@gmail.com</strong></p>
<p>what exactly do you need in a mail?</p>
What if I wouldn't like to use a laptop even wireless can I use a led for ardunio
Hi,<br><br>you mean, not use a data feedback at all? It is possible to modify this project and according to the liquid level change the brightness of a LED or turn on and off a LED. That would be useful in case you don' t want to look inside a tank to see the level of the liquid. Just look at the brightness of the LED. Nice.<br><br>Vasilis
Nice one I was looking for something like that but it was expensive<br>Thanks, I'll try it
Assuming that you can buy anything you need from ebay the total cost is about 15 euros. So, yes It is quite cheap :)
<p>Really cool! Thanks for sharing!</p>
You re welcome :) If there is anything that I could write some more information please let me know.