The finished Arduino wireless water sensor

Back at the end of 2009 I started playing about with an Arduino solution to monitor the water level in a water tank about 300m from the house. The tank isn’t visible from the house so a standard visual tank indicator wouldn’t work. In a nutshell, this sensor measures resistance through an array submerged in the tank to determine the water level, then sends that data back to a server in the house for humans to read. I covered the prototype and the first iteration of the sensor in this post.

There were a few more steps beyond the prototype required to make it really useful and along the way I discovered some issues with the first model which I’ve improved on, but that’s why you call it a prototype.

Here is the Arduino with an added WiFly shield – an add-on that gives the Arduino the ability to (mostly) seamlessly communicate over the farm’s existing 802.11 WiFi network. Arduino shields piggy-back on top of the board, and in this case the WiFly shield has a handy prototyping area – perfect for projects like this where you need to add a few components to a solution. The red and black leads you can see here connect to the water level sensor in the tank. The whole thing is mounted on an aluminium bracket I made up to fix it securely in the project box.

And here’s the whole assembly in the waterproof (IP66) project box. It’s designed to sit out in all weather, diligently saving me endless trips to the tank to manually check the water, so it needed a good enclosure. The battery taking up most of the box is a bog-standard sealed 12v motorcycle battery. I’ve tried to keep as many components as possible off-the-shelf to keep costs down and make future maintenance easy. The external antenna for the wifi is at the bottom left of the enclosure and the 4-way connector on the right is for signal from the sensor and solar power to come in.

The close up shows it’s a pretty snug fit in there. The Arduino is mounted on an angle so the USB port on the right hand side is accessible without unpacking everything. I learned from version one that there will always be lots of tweaking before it works well, so I wanted to make future software changes easy.

The enclosure mounted on a post just above the water tank. The 4-way connector makes it easy to connect up without taking the lid off (important if the weather is rubbish) or take the whole thing back to the workshop when I need to make physical changes.

The sensor array of resistors and an earth return wire lie inside the plastic pipe. The whole thing is submerged in the tank. Originally I had joined the string of resistors together with soldered nichrome wire but after a few months some corrosion (and what seemed to be electrolysis) was starting to look unsightly. I replaced the connections with plain light gauge insulated lead-out wire and it seems to be fine now. The sensor sends 5v DC through the water for a few milliseconds to take a reading so I don’t expect too many problems long term (the tank and all its fittings are plastic). The original post has photos of the array being built.

To power the sensor, I’ve used a 10W solar top-up charger with a built in charge controller. It’s a standard item from most automotive suppliers. At such low power it’s difficult to over charge a 12v battery but having the charge controller adds a bit more margin for error. This panel provides more than enough power to keep the battery topped up. The Arduino draws a tiny amount of power, but the WiFly shield does use a bit of power when it’s transmitting. The ideal angles for a solar panel are: facing due North (in the Southern hemisphere) and inclined to an angle from the horizontal equal to your latitude (about 42 degrees here). I had to cope with the curved surface of the water tank so it’s a best-guess effort.

The distance back to the house is over 300m. We have a fairly powerful wireless access point attached to the outside of the house so small wifi devices can connect to the network pretty easily if they have line of sight.

Back in the house, we can visualise the data, thanks to some great work on the server software from our friend Dave. Making this prettier and adding some smarts like alarms will be the next phase of this project.

The Arduino code is still a work in progress, but I’m more than happy to share it if anyone might find it useful. The software is quite modular so it can be fairly easily adapted for other sensors. We use it for several temperature sensors around the farm and I’m currently working on another sensor to record wind data at a remote site we are thinking about putting some wind turbines on.

Update November 2011 – Triumph!

After a few more tweaks to improve reliability and error tolerance I’m happy to publish the code. I’ve just started playing with Fritzing, so hopefully soon I can put up a proper schematic for the project.

While the sensor worked well most of the time, when you’re dealing with a device a long way from the house that needs to just work, “most of the time” isn’t quite good enough. The problems I had with the WiFly shield were the reliability of communications and recovery from errors.

The code supposedly resets the WiFly client for each data-gathering cycle, but every now and then (from 1 hour to 1 week) it would fail to initialise properly and hang. This would hang the Arduino entirely. From the research I did, and asking people smarter than me, it looked like the WiFly shield wasn’t properly shutting down or clearing its buffers. I’d noticed that it always worked first time, just after a power reset. To replicate that I connected the power to the WiFly shield via a small relay, controlled by the Arduino. Now I have the ability to cut power to the WiFly shield at the end of each data-collection cycle, and power it up each time. This seems to have solved the comms problems and has the added advantage of not wasting power on the WiFly shield between transmissions.

The second problem was the Wifly shield’s fairly fragile handling of errors. If for example, the wifi network or remote server were not available to connect to, the WiFly shield would hang. No retries, no resets, just hang. After much playing around I came across the documentation for the watchdog timer, that allows you to define a reset clock in the code that will reset the Arduino if certain points in the code aren’t reached in a timely manner (ie it has hung). So now, if for any reason, the WiFly can’t post data to the remote server, it resets and tries again (and will keep resetting until it has successfully completed a data post).

The basic function of the sensor is: Take sensor reading > join Wifi network > sent http GET request to remote server > wait >repeat

The Code:

It’s in three parts; the main .pde file, the settings file, and the water level reading function in it’s own file – just put all three in the same place. To use it you’d need to change any settings specific to server and wifi network settings to suit you. There is also a serial printout of the sensor data and comms status so you could easily modify the code to send data somewhere else, print to LCD, write to an SD card etc.

I appreciate this isn’t exactly a comprehensive how-to. This project (and documentation) has been evolving over a year and a half. If there’s interest I can put some time into making this more of an “instructible” to make replication a bit easier.




  1. Russ Says :
    21 June, 2011 at 9:27 am

    Good effort there John (and Dave).

    I’d be interested to hear how you go with the turbines and the consenting process. I’m looking into starting small right now with solar PV but will ultimately look to rig up a modded chinese turbine from EcoInnovation in the corner of our section.

  2. Lancewiggs Says :
    21 June, 2011 at 10:04 pm

    Have you seen Just released…

  3. Lancewiggs Says :
    21 June, 2011 at 10:26 pm

    aha –

  4. StepaUK Says :
    29 June, 2011 at 10:06 am

    Hello John, your project is a great resource and inspiration.

    I’m working on my well level meter and I’m wondering about your ‘plain light gauge’. Does it mean you have replaced the original resistor based solution with array of optical sensors? Or maybe just one sensor measuring the level from above? I’m curious if you’re getting stepped or continuos reading.

    So far I’m testing level measurement using ultrasound sensors but I’m not getting satisfactory results yet, so I’m looking into other sensor option.


  5. John Says :
    30 June, 2011 at 9:38 pm

    Hi Stepan and thanks for the comment.

    When I wrote plain light gauge I was referring to the thickness of the wire – apologies for any confusion. This water sensor still uses a simple resistance measurement, shorted out by the water level.

    But since you mention it, I am also working on another version using a sealed measurement tube (still using resistors, but ‘shorted’ by magnetic reed switches and activated by magnets in a floating collar).

    I’ve seen pressure-sensor based systems, like the solution Lance mentioned above, so there are a few interesting possibilities yet to be explored :)


  6. Mike Barton Says :
    1 July, 2011 at 1:07 am

    Hi there John.
    Being a Wairarapa lad I am curious as to where you property is. I couldn’t quite work it out from the photo above.I have recently got involved with Arduino boards and was looking at doing a tank level meter for my older brother and had been looking at various ways until I came across your site.
    I had been looking at using a MagnetoPot from Mindkits with a kind of float affair but your way appears to be better.
    I am curious as to how you had the breadboard wired up in your initial post on the subject.
    I am also curious as to what the 10k resistor does at the top.
    Thanks for your time and well done.

    Mike Barton

  7. StepaUK Says :
    1 July, 2011 at 8:41 am

    Thanks John for explanation. I’m looking forward your new improvements. Once I have a prototype of my application, I’ll post the results somewhere.


  8. Brian Says :
    8 July, 2011 at 4:58 am

    Hey John, I was wondering a little more about the web application that Dave created. does the Arduino just send the info to a specific IP address? and how does the server read it? I have a lot of confidence about doing the arduino part, but I don’t really have any idea how to actually put it on, and read it from the web

  9. Tim B Says :
    21 July, 2011 at 3:20 am

    I would sure like to see your source code.

    I’m building something similar, but I’m using the self-heating effect of Thermistors: run some current the the chain of devices and they will self- heat. The ones in the liquid will be much cooler than the ones in the air.

    Good article!

  10. avidan Says :
    3 August, 2011 at 6:10 pm

    this looks great. any chance you could share your code? i am looking to use a humidity sensor, but would hate to reinvent the wheel.

  11. TehSnarf Says :
    5 August, 2011 at 8:58 am

    I’m actually attempting to do this with temperature sensors for a fermentation monitor, and would love to see the code if at all possible. I’m still learning how to use Arduino’s and code in general, and would appreciate any pointers or assistance! Thanks a lot!

  12. Derek Says :
    16 August, 2011 at 10:01 am

    Hey John,

    This is a really cool project. First time I’ve seen someone using a WiFly. Everyone usually uses the Ethernet shield.

    I’d love a peak at your Arduino code. I’ve been beating myself up over a project using the WiFly.


  13. Mike Says :
    17 August, 2011 at 9:44 am

    Great project John!

    I was wondering if you would be willing to share your software? I just recently bought a wifly and haven’t set it up yet…I’m sure looking at your code can help.


  14. Andrew Says :
    18 August, 2011 at 2:54 am

    I woul dbe very interested in your code so far, I am creating a sensor fro a bathroom scale to measure the weight and therefore the status of kegs in my keg fridge.

  15. [Test] Wifly Shield (shield wifi arduino) « Skyduino – Le DIY à la française Says :
    22 August, 2011 at 10:47 pm

    [...] le module wifly qui bug ? 18Ko/s c’est vraiment pas énorme ! Pourtant il existe des projet utilisant la wifly shield sans probléme [...]

  16. Christopher Overstreet Says :
    17 September, 2011 at 8:35 pm

    I would love to see the code. I am nervous about implementing wifi into my current project as I can’t seem to find any example code online which does what I want…. a simple udp stream with all the sensor data. I don’t want to reload a webpage served by the wifly/arduino but instead send a fast stream of data consisting of about 10 numbers. Are you doing something like this? How often do your sensors update? Please send me link to your code if you are still willing.

    Thank you. I look forward to following your work.

  17. David Thompson Says :
    27 September, 2011 at 3:57 am

    John- Is there a chance you could share your Arduino code and a little more about how you went from a wifi link to applications code? Is the wireless monitor a network node that provides a web page from which you can extract data, or ??? It would be fun to see how you structured this system.

  18. Aidan Says :
    29 October, 2011 at 2:20 am


    Quick question on the server software/ display side of the system:

    Are you able to access the Arduino as a URL in a web browser? If it is not accessed via a broweser, how do you connect over the Wifi to the device?



  19. EoinFarmerIRE Says :
    31 October, 2011 at 12:57 am

    I know its a long time since this was first made, so I’m asking about how it has worked out. Has it continued to provide data readings for you? Has it made work easier, removing the need for numerous trips to the tank as was the plan?
    Also on the implementation, the wifi module datasheet seems to say that you need to keep the antenna from being blocked, have you found this to be an issue with the weatherproofed box and the large distance between you access point and the device?
    Overall I think this is an excellent idea, and your work to show it to the world is great also. Really hope that you have had time to think about expanding the idea to implementing some control.

  20. David Schwartz Says :
    17 November, 2011 at 5:47 am

    I would like to try and duplicate your project similar to yours as a demo for my lab students next spring. Could you please give me access to your code and also could you please tell me what router you are using (I have had some problems with a few of routers and Arduino Wifi)

  21. David Schwartz Says :
    17 November, 2011 at 3:11 pm

    PS Sorry for the typos in my first message. I was late for work and seemed to have missed a number of words while typing quickly!

  22. michelangelo macapugay Says :
    9 December, 2011 at 5:38 pm

    hi john,
    i am not very familiar with microcontrollers but from what you have made it seems like the arduino can be made to measure voltage and current, record the value and compute resistance. i would like to tinker with electrical resistivity surveying but needless to say the equipment is far too pricey for the weekend archeologist wannabee aka yamashita treasure hunter! ive just been browsing through electrical resistivity surveying methods for archeological exploration and it speaks of measuring apparent resistances by injecting voltages at certain predetermined patterns and corresponding currents to measure apparent resistance. do you think such function can be replicated by arduinos?

  23. Miguel Says :
    10 December, 2011 at 6:11 am


    I need to have something to read me the water level and the diesel level of two tanks, and after by connecting this to my network to have it displayed in a screen to monitoring this online.

    I also need to have a interface to configure different levels of alarm and some emails to send in case of low level alarm.

    Is it possible to use your project?

    Where can i find the user interface?

  24. Sergei Says :
    31 December, 2011 at 1:12 pm

    Great project and efforts to make WyFly to work as it should! I would suggest a slightly different configuration that would eliminate costly WyFly and make it very reliable project:
    1. Use digi’s ZigBee Pro to contiguously reading and transmitting data from your water tank sensor. No need for Arduino by the water tank and no need for a big battery.
    2. Put Arduino with another Zigbee to receive and process the data in the house connected to ethernet.
    3. Use EtherNet shield or Arduino Ethernet board to serve the data via HTTP server.

    I am using this configuration in a different type of security project and it works very well.

  25. Filippo Says :
    8 March, 2012 at 3:59 pm

    Great John, good work, I’m curious to look at your code!

  26. Thomas Says :
    7 April, 2012 at 9:44 am


    What type of solarpanel did you use? I’m building a similar-looking project and i’m looking for a durable energy source for my arduino wifi

    thx !

  27. Peter Sek Says :
    8 May, 2012 at 12:00 am

    Nice work; I have used Untrasonic distance module for measuring water level in a plastic tank. Very accurate and stable. These sell on e-bay for around $3+
    You might like to consider it for your project
    eg ‘Arduino Ultrasonic Module HC-SR04 Sensor Ranging Distance Measuring Transducer’

  28. alvaro jose Says :
    18 May, 2012 at 5:50 am

    quisiera saver si en ves de embiar datos de un sensor ,lo puedo poner a resibir informacion desde mi pc para activar un dispositivo (relevo) por ejempo. si tienes un tutorial te lo agradeseria.
    agradeciendo tu pronta respuesta .
    atte alvaro rodriguez

  29. Technology for Sustainable Farmers – criteria | Green Machine Farm Says :
    4 June, 2012 at 4:00 pm

    [...] Wi-Fi Water sensor [...]

  30. ENLACES A: ARDUINO+Server+Wifi Says :
    9 September, 2012 at 3:31 pm

    [...] [...]

  31. Monica Says :
    14 October, 2012 at 6:28 pm

    I would love to see this as an instructable. Do you recommend the WyFly shield?

  32. Dave Collins Says :
    7 December, 2012 at 12:28 pm

    Awesome write-up!! Thanks so much for taking the time. I’m awaiting my WiFly and hoping to get a jump-start on a project based on what you did here.


Leave a Comment