Got indoor plumbing? Yep. Got city water? Nope. Then you're in the right place. If you have a well, then you probably have a water tank. This project is a way to measure how much water is left in your tank. You could use this project for other applications too, such as tracking the level of a lake, reservoir, cattle tank, moat, etc.
What is it?
The key of this project is a weather proof ultrasonic distance sensor (similar to the backup sensors on a car) connected to a Spark Core Wi-Fi module. The Spark Core module reads the sensor and posts the measurement to Twitter. You can view the water level using the Twitter app already on your phone... and you can track water usage history by looking at old tweets.
Step 1: Step 1: You Will Need...
Ultrasonic Range Finder - XL-MaxSonar-WR1
6" of Schedule 20 1" PVC pipe
3/4" threaded reducing female adapter (such as a Dura 435-131, which is usually carried by your favorite big box building supply store)
1" PVC end cap
soldering iron and lead-free(!) solder
- Spark.io Core works great for this application, but a Photon has a connector for an external antenna which will probably improve the Wi-Fi distance.
- PVC pipe comes in several thicknesses. Use Schedule 20 (the thinnest walled pipe) for this application so that we don't affect the antenna too much. It's cheap, but you probably have to buy a really long pipe, so plan to either fold it by hand, or bring a saw with you to the store so you can fit it into your car.
- Sometimes the color used to die plastics affects the antenna, so choose white PVC instead of gray or black if you have a choice.
- Most of the MaxBotix ultrasonic distance sensors would technically work, but the expensive water proof ones will last better inside a water tank. We use the Analog Output of the sensor because the serial port of this specific sensor is incompatible with most Arduino style boards, including the Photon Core.
- It's really tempting to use lead solder, but DON'T DO IT! After all, you're putting this in your water supply.
- The best way to get the right PVC pipe fittings is to carry the sensor into the building supply store and buy whatever fits.
Step 2: Step 2: Connect the Spark.io Core to Your Wi-Fi Network
The Spark.io Core is the brains of the system. Plug it into a USB power supply and follow the directions at http://docs.spark.io/ to get it onto the Wi-Fi network.
You will need to know your Wi-Fi network SSID and password. The app will attach the Spark.io Core to you network, and also help you set up a Spark.io account. Finally, this will connect your specific Spark.io Core to your new Spark.io account so that you can deploy code to it.
There are many, many ways to connect the Spark.io Core to your Wi-Fi network. Use whatever works as long as in the end:
- it's connected to your Wi-Fi network
- it's connected to your account
(I did it the hard way using a serial port)
Step 3: Step 3: Create a New Twitter Account for Your Sensor
Create a twitter account for your sensor at https://twitter.com/signup. Don't be too picky about the username. Unless you want the whole world to watch your water level, it's probably best to use one of the randomly generated suggestions. It's best to create a new account for your sensors instead of reusing your existing account, so that your loyal twitter followers don't feel like they're getting spammed with M2M data.
Step 4: Step 4: Get a Security Credentials for the Twitter Account
Log on to your new Twitter account, then from the same web browser go to http://arduino-tweet.appspot.com/oauth/twitter/login , and click Authorize app.
SAVE THE TOKEN! You'll need to paste it into the code to make it post to YOUR Twitter account instead of My Twitter account.
We are using the incredibly useful site http://arduino-tweet.appspot.com/ to interface between the Arduino/Core friendly code and the enterprise class Twitter APIs. Because we don't use https, the data is sent unencrypted to arduino-tweet.appspot.com. This is OK, since we're about to post it to Twitter on an account that only exists to post this data, but you probably don't want to use this technique if you're monitoring coolant level in a nuclear reactor, launch codes, Area 51 secrets, etc.
Step 5: Step 5: Build the Circuit
Solder wires to connect these 4 pairs of pins:
Sensor pin AN --> Core pin A7
Sensor pin 4 --> Core pin D2
Sensor pin V+ --> Core pin 3V3*
Sensor pin GND--> Core pin GND
- Run the wires through the PVC pipe adapter before soldering them. Neither the Core, nor the sensor will fit through the inside of the adapter. Fortunately, you can attach the PVC pipe later.
- Either use colored wires, or mark each wire before soldering it so you know which wire goes to which pin on the sensor.
Way to go! You've finished all the electrical parts of the sensor!
Step 6: Step 6: Load the Software
Spark.io has a web based programming tool for the Core at https://www.spark.io/build
Go there and paste the code in the attached file tankmeter.txt into your first program.
Replace the TOKEN "2958....MeZz" with your own token from the previous step.
Click the lightening bolt icon to deploy your code.