Вы находитесь на странице: 1из 13

instructables

Water Tank Levels by WiFi on Your Phone

by ItsGraGra

This instructable is entered in the "Wireless" estimate the levels.


contest. Please vote for me, Thank you
Not much fun, inaccurate and time consuming, there
When I moved to a rural property in Australia I was must be an easier way.
faced with the fact my water supply was at the mercy
of the Gods; rain from the sky to fill the tanks. Using Blynk and my WLAN was the answer, I could
see at a glance the levels on my phone.
I had a capacity of around 30,000 litres across 2
concrete tanks and checking the levels meant Check out Blynk here
climbing up a ladder, lifting a very heavy concrete
cover and peering down into the damp darkness to

Water Tank Levels by WiFi on Your Phone: Page 1


Step 1: The Hardware

The standard HC-SR04 ultrasonic sensors are not DC-DC 3.3v supply
waterproof, waterproof ultrasonic transmitter/receiver
sensors to the rescue. These are the same units used Plus a waterproof box big enough to fit all the boards
on motor vehicles for reversing and hazard detection. in.
These coupled to an ESP8266 NodeMCU WiFi board
plus a small power regulator board make up the Breadboard for testing
hardware.
Link wires
These parts can be bought from AliExpress very
cheaply (links below) or the supplier of your choice. LED color of your choice

ESP8266 NodeMcu-V3-Lua-WIFI Plug pack, 9 - 12VDC with Arduino UNO compatible


type connector
Waterproof Ultrasonic Sensor

Water Tank Levels by WiFi on Your Phone: Page 2


Step 2: Wiring It Together on the Bench for Initial Testing

I used a breadboard for initial setup and testing. ground for the sensor boards from the DC-DC
converter output pins when doing the final wiring in
For testing purposes this can run off the USB supply the box but for testing use the Arduino 3v3 and GND
from your PC but in the field I used a small 3v3 pins.
regulated DC-DC converter supplied by a 9v plug
pack. A 12v supply could be used with these Wire both sensors VCC to Arduino 3v3
converters. Use what you have laying around.
Wire both sensors GND to Arduino GND
Plug the 2 ultrasound sensor boards directly into the
breadboard and run 2 wires for each to the Arduino The LED is only on for 50mS every 2 seconds so I
as below. Be aware these ESP12E boards run on 3.3 didn't bother with a current limiting resistor but a 1/4W
volts. They have a 5v input supply pin (VIN) and also 470R resistor can be added if you wish.
run on the USB supply when connected to your PC.
Do not supply more than 5 volts to the VIN pin you LED Anode (long leg) to Arduino GPIO13 (D7)
use that. Through a resistor if desired

Wire using male to female link wires: LED Cathode to Arduino GND

Sensor1 ping to Arduino GPIO5 (D1) Now plug the Sensors into the back of the sensor
boards, they have 2 mtr long co-axial leads.
Sensor1 echo to Arduino GPIO4 (D2)
I needed to extend these, my tanks are 6 mtrs apart. I
Sensor2 ping to Arduino GPIO14 (D5) used some old co-axial cable I had laying around.

Sensor2 echo to Arduino GPIO12 (D6) If you do this, be sure to cover all soldered joints with
heatshrink.
These sensors work ok at 3.3volts. This is good as
level converters are not needed. That's all the wiring, next is the software.

It's probably a good idea to take the supply and

Water Tank Levels by WiFi on Your Phone: Page 3


Step 3: Collecting and Installing the Software

Water Tank Levels by WiFi on Your Phone: Page 4


This water level monitor uses Blynk to send info from Installation and setup of a local server is beyond the
the ESP8266 board to your phone via their servers. scope of this instructable. There are many
instructions and tutorials on the net for doing this
The Blynk server in the cloud serves up your app with starting with the Blynk website.
the information in the widgets on the phone. When
signing up with Blynk you are given 2000 energy The final version I coded for OTA (over the Air)
points. These points are used to 'buy' widgets for your updating as it is remote and I didn't want to pull it all
program. apart just to update the software. I'll discuss the OTA
software changes and methods later.
2000 points is enough to build this water monitor app.
While on the bench we have the USB serial to upload
I actually have a 'local server' running on a Raspberry code.
Pi, this allows unlimited points and better security. It
does not use the Blynk server at all, completely First thing you will need is the Arduino IDE if you
independent. don't already have it.

Get the Arduino IDE here Arduino IDE. Follow the Linux (32 and 64 bit).
getting started link on how to install this software, it is
not part of this instructable. Start Arduino and open File > Preferences window.

Download the Blynk library here Blynk library, Enter ( copy and paste - without the quote marks)
download link is at the bottom of the page. ```http://arduino.esp8266.com/stable/package_esp82
66com_index.json``` into *Additional Board Manager
Follow the instructions on that page to install the URLs* field. You can add multiple URLs, separating
library. them with commas.

Get the phone app here Blynk App. Open Boards Manager from Tools > Board menu and
install *esp8266* platform (and don't forget to select
An account can be created now for Blynk if you wish your 'NodeMCU 1.0 (ESP-12E Module)' board from
using the app. Remember the login email address Tools > Board menu after installation).
you use, you'll need it later. Probably best to use your
every day email account. From the menu select Sketch > Include Library >
Manage Libraries. Allow it to finish downloading. You
You will also need this library: should see the Blynk libraries installed.

NewPing This is an excellent library for using For your PC to communicate with the Arduino boards
ultrasound devices that does all the timing for you. No the USB to Serial software (We ESP12 USB-UART
need to mess around with milliseconds etc. CH341SER_win driver) needs to be installed. This is
needed for all Arduino comms over USB. Get it here
These instructions below need to be done to install all
the ESP8266 software. That's all the software set up hopefully.

Starting with 1.6.4, Arduino allows installation of third-


party platform packages using Boards Manager. We
have packages available for Windows, Mac OS, and

Water Tank Levels by WiFi on Your Phone: Page 5


Step 4: Test Code for the ESP8266 Board

When I write software I like to build it up from small A folder will be created with the ino file inside.
beginnings and continue testing as I go.Writing a long
program and finding it doesn't work is difficult to Confirm you have the correct board selected, click the
debug. 'verify' button (very left button on the IDE). It should
compile without error.
So we'll start with two sensors reporting back the
information to the serial monitor built into the Arduino Connect your board to the USB cable, select from the
IDE. IDE menu Tools > Port > COM n.

No reporting to the Blynk server, OTA or WiFi yet. The correct com port can be found by simply
unplugging the board and see which port disappears.
Double click the 'water_code_1.ino' file below, after
Arduino IDE starts go to File > 'save as' and save to Click the 'Upload' button in the Arduino IDE and allow
your sketch folder. it to finish compiling and uploading.

In the IDE select Tools . Serial Monitor. Test each sensor by moving it in and out from a solid
object like the wall, you should see the figures
The LED should flash every 2 seconds and the change in the monitor window. As the distance
monitor should be reporting distance, depth and liters increases this is simulating a lower water level so
for each tank every 2 seconds similar to the picture less liters will be reported and vise-versa.
shown.
If all works as expected go to the next step.
These sensors have a range of about 3 mtrs They are
set at 3 mtrs in software anyway.

Download (https://cdn.instructables.com/ORIG/FUL/Q9X1/JA36MS3S/FULQ9X1JA36MS3S.ino)
http://www.instructables.com/ORIG/FUL/Q9X1/JA36MS3S/FULQ9X1JA36MS3S.ino

(https://cdn.instructables.com/ORIG/FUL/Q9X1/JA36MS3S/FULQ9X1JA36MS3S.ino)

Water Tank Levels by WiFi on Your Phone: Page 6


Step 5: Code With WiFi and Blynk

Now lets get connected to the Blynk server. go to your email and copy the authority token, paste it
into your arduino program where it says 'char auth[] =
download and open the water_code_2.ino "YourAuthToken"

In the Arduino IDE select File > 'save as' to your Also enter your SSID and your password.
sketch folder.
Now upload it to your ESP board.The serial monitor
Open the Blynk app, sign in. Create a new project, should display connection status before it displays
chose device = ESP8266, connection type = WiFi, the water levels.
set the theme you prefer. press the Create Button.
In the next step we will finish the Blynk project in the
An authority token will be sent to your nominated app.
email account. press OK. Further instructions on the
app program in the next step.

Download (https://cdn.instructables.com/ORIG/FCL/K7Q2/JA36V5M6/FCLK7Q2JA36V5M6.ino)
http://www.instructables.com/ORIG/FCL/K7Q2/JA36V5M6/FCLK7Q2JA36V5M6.ino

(https://cdn.instructables.com/ORIG/FCL/K7Q2/JA36V5M6/FCLK7Q2JA36V5M6.ino)

Water Tank Levels by WiFi on Your Phone: Page 7


Step 6: Setting Up the Blynk App Program

Continuation of new project in the Blynk app.... Press the left Vertical Level, name it Level 1, select
V3, 0 to 1600, OFF and PUSH
Press the + at the top of the screen in the app, scroll
down and press Value Display. Do this 4 times Press the right Vertical Level, name it Level 2, select
V6, 0 to 1600, OFF and PUSH
Press the + at the top of the screen in the app, scroll
down and press LevelV. Do this twice Press the SuperChart, names Liters 1 and Liters 2.

Press the + at the top of the screen in the app, scroll Press the icon (data stream) next to Name, PIN = V3,
down and press SuperChart. slide switch = VALUES, minn = 0, max = 1600

Lay out the widgets like the picture. A long press on Press the icon (data stream) next to the second
the widget gives you handles to resize them. name, PIN = V6, slide switch = VALUES, min = 0,
max = 1600
Color them as you see fit.
You can play around with the other settings to suit
Press the first Value Display (top left), name it Depth your preferences.
1, select V1, 0 to 300 and PUSH
To delete a widget drag it to the top right of the
Press the second Value Display (top right), name screen.
Depth 2, select V4, 0 to 300 and PUSH
If everything looks ok, press the play button top right
Press the third Value Display (2 down left), name of the screen. If your Arduino is running you should
Liters 1, select V2, 0 to 9999 and PUSH see the same numbers (except distance) come up as
in the serial monitor.
Press the forth Value Display (second down right),
name Liters 2, select V5, 0 to 9999 and PUSH

Water Tank Levels by WiFi on Your Phone: Page 8


Water Tank Levels by WiFi on Your Phone: Page 9
Step 7: Setting Up OTA Updating

OTA or 'Over The Air' uploading of code is a really a Upload this to your board.
useful feature, particularly in this case where the ESP
board is in a box and outside. Now press the reset button on the board.

This is a fairly simple process: Go back to your water tank program and un-comment
the 3 places shown in the pictures, these are required
1. a OTA bootloader is first uploaded to the board. now for OTA uploading.

2. The board is reset by pressing the reset button on Upload this to your board, use serial USB.
the board.
If you look under Tools > Port in the Arduino IDE you
3. your new code for the water tank project containing will notice a new port. It will have 'esp8266', the board
the OTA additions is uploaded to your board by USB. ID and the board IP address.

Future uploads are achieved by selecting the WiFi For future upload use this port, no need for a USB
port in Tools > Port. serial connection.

Go to File > Examples > ArduinoOTA > BasicOTA The board can now be powered by some other
means but OTA will still work using power from the
The program will load up, enter your Network Name USB cable.
and Password in the code near the top f the program.

Water Tank Levels by WiFi on Your Phone: Page 10


Step 8: Mount the Boards Into the Box

I mounted the ESP8266, both the Ultrasonic boards board so we avoid ground loops. Use 3.3 volts for
and the DC-DC converter in a IP66 rated box as it everything.
would be outside and exposed to the elements. I did
however put the box inside a UV safe plastic bag just Drill a hole for the LED, try to make it a tight fit so no
to be sure. I felt the connectors could leak water into adhesive is necessary.
the box.
Check everything, especially the power wiring.
I wont go into detail about mounting the boards; your
box may be different to the one I used. Plug in the power pack and connect to the box, plug
in the sensors and switch on.
I didn't have any female connectors for the Sensor
boards so I soldered the wires and covered with You will not see anything on the serial monitor of
heatshrink. course as we are not using the USB serial
connection, but check your phone app.
If you have female-female wire links, all the better.
Move the sensors around, the figures should change
Mount the DC-DC converter to a position where the in the app.Bear in mind a ping and info transmission
power connector can be plugged in from outside. is only done every 2 seconds.

Take all the power and ground connections to this

Water Tank Levels by WiFi on Your Phone: Page 11


Water Tank Levels by WiFi on Your Phone: Page 12
Step 9: Mount the Sensors in the Tanks

Again I cant go into detail about mounting the sensors range distance of 20 cm, this is because the
in the water tanks, your tanks are most likely different transmitter and the receiver share the same ultrasonic
to mine. speaker and has speed/timing problems under that
distance.
It does however have to be within your homes WLAN
WiFi envelope. If your tanks are at a greater distance, Connect everything up and ensure everything is
WiFi extender could be used. weather proof.

However, fix the sensors pointing directly vertically Apply power, it takes a few seconds to boot, you
downwards toward the water at the height you should see the water levels on your phones Blynk
measured before, see the picture, should be at app.
'Depth1 and Depth2. It is assumed the water can
never reach this depth before overflowing. You don't Any questions I will try to answer as best I can. Good
want the sensors drowning. luck with this useful project.

I should also point out these sensors have a minimum

Water Tank Levels by WiFi on Your Phone: Page 13

Вам также может понравиться