# Using IoT for Cistern and Water Tank Level Monitoring
## 3 Monitoring of Water Architecture
### Water Tank and Cistern System Description
#### 3.5.1. Cistern Sensor Node Electronic Circuit Diagram  
The following diagram (Figure 9) shows graphically the connections needed to operate the cistern sensor node. In this diagram, each component is indicated by a numerical label as an identifier.  
Figure 8. General architecture.  
Figure 9. Node-RED programming code for the dashboard, where all sensors and actuators are connected for visualizing on the Internet.  
Microcontroller (NodeMCU V1.0) (for writing purposes, this is referred to as the microcontroller): It controls all sensors and actuators in the system. Its input and output pins were configured through the Arduino IDE programming environment. The MQTT protocol over the local network establishes communication with the sensors and actuators.
2. Ultrasonic waterproof sensor (JSN-SR04T-2.0): This is used to measure the water level in the water tank. This sensor sends a signal that bounces off the water's surface, allowing it to calculate the distance and, therefore, the volume of water. The connection of this sensor to the NodeMCU includes the following: * 5V pin to the 5V pin of the microcontroller. * Ground pin (GND) to GND of the microcontroller. * Trigger pin (Trig) to the D7 pin of the microcontroller. * Echo pin to pin D8 of the microcontroller.
3. Water flow sensor (YY-S201) (this sensor requires a PULL-UP resistor to be set since it generates interruptions): It measures the pressure of the water entering the tank from the main supply. The pressure measurement is crucial for estimating the filling time of the cistern. The connection to the microcontroller includes the following: * 5V pin to the 5V pin of the microcontroller. * Ground (GND) pin to the microcontroller's GND. * Signal pin to the D4 pin of the microcontroller.
4. Relay module: It activates or deactivates the submersible pump, depending on the water levels in the cistern and tank. The pump turns on when the tank level is below 50% and turns off when it is full. The relay connections are as follows: * 5V pin to the 5V pin of the microcontroller. * Ground (GND) pin to GND of the microcontroller. * Signal pin to pin D6 of the microcontroller.
5. Submersible water pump: It transfers water from the cistern to the upper tank. The relay module controls the activation of the pump. The connections are as follows: * Positive wire to the NO terminal of the relay. * Negative wire to the negative terminal of the 9V battery.
6. Battery (9v): This battery helps us close the circuit of the submersible water pump since it changes state from on to off and vice versa. A commercial battery was used, and a battery clip was adapted.
7. Sensor TDS meter v1.0: It measures the amount of dissolved solids in the water, expressed in parts per million (ppm), which estimates water quality. The sensor configuration includes the following: * 5V pin to the 5V pin of the microcontroller. * Ground (GND) pin to the microcontroller's GND. * Signal pin to the A0 pin of the microcontroller.  
The electronic circuit diagram of the cistern node is designed to continuously send collected data to the Raspberry Pi 4 server via the MQTT protocol. This architecture allows the pump to be activated and deactivated as needed, optimizing water use in the home.