FINAL Project02 – The Use of Rainwater

Introduction of OLED I2C Display1891524023223_.pic.jpg

How to connect and program the Geekcreit 0.96 inch 4 pin white I2C OLED module with Arduino. OLED display based on a SSD1306 OLED driver IC.

The display connects to Arduino using only four wires – two for power and two for data, making the wiring very simple. The data connection is I2C (I²C, IIC or Inter-Integrated Circuit). This interface is sometimes called TWI (Two Wire Interface).

Reference from:×64-I2C-display/

Testing – 1 Display Text on OLED Screen






Connect the display to UNO board as the image shown.

Before start coding, I need to import two zip libraries for add graphic to the display.

屏幕快照 2018-04-18 04.50.39



















After reading the reviews of this module from Amazon, I’ve done some changes to the raw files, and started coding on a sketch template from×64-I2C-display/

Here’s the code.

屏幕快照 2018-04-18 05.08.50.png

This is how it shows on the display.


Testing – 2   Display Sensor Data on the Screen


Add a water level sensor to the circuit on pin A0.

A Flow Chart for Programing



屏幕快照 2018-04-18 05.02.36.png

Then add these code before setup as a intro for the water level sensor.
屏幕快照 2018-04-18 05.03.53.png




Also add these to loop to run the program, so the reading will be taken from pin A0 and displayed on the screen.




Here’s the video show how it works.

And this is the full code for this part.


As I’ve make the valve and OLED display run perfectly, then I put them into one circuit, and merged the code together.


The Full Version Flow Chart


The full code for this project is here.

Prototype Building


Here’s the video for the working prototype.

The model will leak water, so I use finger instead of water to show how it works.




WEEK 9 Project02 – The Use of Rainwater

How to use water level sensor to control a servo?


Aim to fill the toilet tank by rainwater by using the non-contact liquid sensor to control the valve. When the toilet tank is empty, the servo will rotate to open the valve for rainwater filling, and it will rotate back to the original position as closing the valve when the tank is filled up.

Testing – 1  Make the Servo Rotate in Clockwise and Anti-clockwise

屏幕快照 2018-04-18 02.45.22.png

Connect the circuit as above, then upload the “sweep” code for servo testing.

屏幕快照 2018-04-18 00.35.04.png



Testing – 2   Use Non-contact Liquid Sensor to Control Servo


Add a non-contact liquid sensor at the servo testing circuit on digital pin2, then add the sensor sketch to the servo testing code and upload it.

A Flow Chart for Programing


Full code:

屏幕快照 2018-04-18 03.34.07.png


This video shows how it works when it’s attached to the prototype, so the valve will open when there is no water detected from the toilet tank, and it will keep shut if water is detected. ( The model will leak water, so I use finger instead of water to show how it works.)

Next Step

I’m going to use a OLED I2C display to read the water level sensor in the rainwater tank for people to monitor the water level change .

WEEK 8 Project02 – The Use of Rainwater

Introduction of Reading Sensor Value on Blynk App

How Blynk Works

Blynk was designed for the Internet of Things. It can control hardware remotely, it can display sensor data, it can store data, vizualize it and do many other cool things.

There are three major components in the platform:

  • Blynk App – allows to you create amazing interfaces for your projects using various widgets we provide.
  • Blynk Server – responsible for all the communications between the smartphone and hardware. You can use our Blynk Cloud or run your private Blynk server locally. It’s open-source, could easily handle thousands of devices and can even be launched on a Raspberry Pi.
  • Blynk Libraries – for all the popular hardware platforms – enable communication with the server and process all the incoming and outcoming commands.



  • Similar API & UI for all supported hardware & devices
  • Connection to the cloud using:
    • WiFi
    • Bluetooth and BLE
    • Ethernet
    • USB (Serial)
    • GSM
  • Set of easy-to-use Widgets
  • Direct pin manipulation with no code writing
  • Easy to integrate and add new functionality using virtual pins
  • History data monitoring via History Graph widget
  • Device-to-Device communication using Bridge Widget
  • Sending emails, tweets, push notifications, etc.


Introduction of Arduino Ethernet Shield W5100


The Arduino Wiznet Ethernet W5100 Shield allows an Arduino board to connect to the internet. It is based on the Wiznet W5100 ethernet chip providing a network (IP) stack capable of both TCP and UDP. The Arduino Ethernet Shield supports up to four simultaneous socket connections. Use the Ethernet library to write sketches which connect to the internet using the shield.



From the tutorial provided by Blynk website :

I connected the shield to UNO board, and got a sketch example from:


屏幕快照 2018-04-13 04.08.23.png














However I can get the IP address, but couldn’t connect to the blynk cloud web.














Introduction of ESP-01 / ESP8266 Wifi module

As the ethernet shield is not working, I decided to try the small wifi chip to make the Arduino UNO connect to the internet.



The ESP8266 WiFi Module is a self contained SOC with integrated TCP/IP protocol stack that can give any micro controller access to your WiFi network. The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor.



I Added an adapter to this module and connect it as below.


屏幕快照 2018-04-13 04.54.48.png

I got a sketch example from:

However the network kept showing “not responding”, it doesn’t work as well. Probably because the module wasn’t in the latest firmware, it should be flashed.

Next Step

As reading the sensor on App seems quite difficult to come true, I ‘m planning on reading sensor data on a LCD or OLED display.






WEEK 7 Project02 – The Use of Rainwater

Introduce Water Level Sensor

NO.1 Testing


Water level sensor is a module that can sense the depth of water, whose core part is an amplification circuit composed of a transistor and several comb-shape PCB cables. When placed in water, the comb-shape cable will change its resistance with the depth of the water and convert the depth signal into an electrical signal. With an ADC on the SunFounder Uno board dealing with that signal, we can know the water depth changes.


屏幕快照 2018-04-12 21.13.03.png

Connect the circuit like above. Connect the sensor to A0, and led to pin3.

屏幕快照 2018-04-12 21.14.22.png

Select the AnalogInOutSerial code in Example, and make sure the Output pin is correct.

Reference from:



NO.2 Non-contact Liquid Level Sensor


The non-contact liquid level sensor utilizes advanced signal processing technology by using a powerful chip with high-speed operation capacity to achieve non-contact liquid level detection. No contact with liquid makes the module suitable for hazardous applications such as detecting toxic substances, strong acid, strong alkali and all kinds of liquid in an airtight container under high pressure. There are no special requirements for the liquid or container and the sensor is easy to use and easy to install.
The liquid level sensor is equipped with an interface adapter that makes it compatible with DFRobot “Gravity” interface. There are 4 levels of sensitivity which are set by pressing the SET button.



Using the same connection and code as the previous one to test the non-contact liquid sensor.


Next Step

I’m going to work out how to use water level sensor to control a servo for valve opening and closing, also have a look at how to read sensor data on a smart phone App.

WEEK 6 Project02 – The Use of Rainwater

Project Aim

By collecting rainwater for home using to reduce the water consumption and make our lives more sustainable.

Initial Idea


To create a smart toilet flushing system by using collected rainwater. When the toilet water tank is empty, the Valve1 will open to let rainwater flush the toilet. If the rainwater tank is empty as well, the Valve2 will open to use city tap water to flush.

Developing Concept


Using one water level sensor in toilet tank to control the valve in the rainwater tank for opening and closing, and using smart phone app to observe the volume of the water in the tank by reading the value from the sensor in the rainwater tank.

Component needed:

Arduino UNO Board


Water Level Sensor x2


Wifi Shield / Wifi Module / Bluetooth Module

Smart Phone App


WEEK 5 Project02 – The Use of Rainwater



Water consumption is always a big problem for our human in nowadays. How to use water efficiently in our lives should be an important aim for everyone. Therefore it reminds me that we can use rainwater to reduce the pressure of city water supply. Rainwater itself is generally clean, but it can pick up microorganisms, pollutants and debris when it hits the roof. This is why systems for rainwater use inside home often include filtration or other treatments for safety.

Uses for Rainwater

Flushing Toilets

This is another huge water drain. Toilets use almost 27 percent of water in your home. To use collected rainwater instead, try keeping a bucket of it next to your toilet. When you need to flush, pour the rainwater straight into the bowl of the toilet. This will automatically flush your toilet. Make sure your bucket can hold the amount of your toilet’s tank. For instance, if you have a toilet with a 6 gallon (22.7 liter) tank, use at least a 6 gallon bucket of water

Another option is to plumb a pipe for rainwater directly into your house and connect it to your toilet for flushing.

Watering Lawns, Gardens and Houseplants

Rainwater is naturally designed to water plants, and it can easily be used for your indoor and outdoor gardens. You can use rainwater in watering cans to water plants by hand. You can also attach any rainwater storage tanks directly to an automatic irrigation system.

Passive systems to conserve and collect water in your soil are also helpful. Plant garden beds along the edges of your driveway, or at the bottom of a hill, to take advantage of water’s natural movement. Also, try planting a rain garden at the ends of your eavestroughs to catch any excess runoff.

Rinsing Vegetables

Dirty rainwater is great for rinsing vegetables straight from your garden, especially root vegetables. Try filling a large bucket with rainwater, adding some carrots, potatoes, beets or other hard vegetables, and swish them together to knock the soil off.

Washing Vehicles and Equipment

Washing outdoor items is another excellent use for untreated rainwater. Cars, garden tools, lawnmowers, tractors and even the driveway and sides of your house are all perfect candidates.

Reference from:

Rainwater harvesting

Rainwater from roofs and hard surfaces such as car parks can be stored and used in and around properties. The simple rainwater butt, used for garden watering, is a familiar method of storage.

There has been a recent growth in the use of the collected water for a range of non-potable uses, particularly for flushing toilets. Stored water is generally held in a suitably sized underground tank and pumped to the point of use. A mains water supply is usually provided as a back-up if rainwater is not available.


Reference from: