MAKER:LiamOSM/Translated by:Fun Endless
The smart home series has featured various projects. For instance, the “MAKER’s Wardrobe: Raspberry Pi + RFID for Smart Wardrobe“, the hands-on “Cool ‘Thanos Glove’ Appliance Control Terminal”, and the security project “Cat Away!Computer Vision Cat Repellent Equipment“.
This time, we will create an environmentally friendly energy-saving project—a water usage monitoring device for showerheads. By installing a flow sensor on the showerhead, we can record water usage, real-time water costs, and other information to encourage water conservation and improve water efficiency.
The project will display the water used for each shower, the flow rate, and the water cost, making it a highly practical project with a very rigorous design approach. This feature can also be applied in other water usage scenarios.
Materials List
Arduino Nano × 1Flow Sensor × 1LCD Display × 1Boost Converter × 1Lithium Battery Charger × 1Waterproof Switch × 1Waterproof Button × 1M3 Screws × SeveralM3 Nuts × SeveralBrass Standoffs × 4Brass Standoffs with Bolts × 43.5mm Female Socket × 23.5mm Male Plug × 13.5mm 3-inch Cable Components × SeveralUSB Cable Components × Several1/2 inch NPS Female-to-Female Connector × 1500mAh 3.7V Lithium Battery × 1Soldering Iron × 1Solder × 1Wire × SeveralPliers × 1Double-Sided Tape × 1Phillips Screwdriver × 13D Printer (Optional) × 1
3D Printed Case
The waterproof treatment of the case should be the most challenging part of this project. Since the water-saving device is to be installed next to the showerhead, it must be moisture-proof and able to withstand occasional splashes of water.
You have two options: customize a 3D printed case or buy a ready-made one. I chose to make my own case.
Using Fusion 360 software to design the case. The 3D printing file can be downloaded from the project file library. https://make.quwj.com/project/137 100% fill for all materials.
Bottom of the case: three circular holes for installing two female 3.5mm sockets and a switch.
Case lid: a 16mm hole for the momentary button, a rectangular window for the screen installation, four holes for fixing the screen, and four additional holes at the corners for securing the lid of the case. Use 3M screws.
The rectangular window for the screen installation needs to have a waterproof film added to prevent moisture from flowing in through the gaps. If you are using a transparent lid for the case, this step is not necessary.
The size of the waterproof film is approximately 5mm thick and 27x77mm large transparent plastic rectangle. When installing, trim the corners so that they do not obstruct the surrounding holes. Use strong glue to adhere the waterproof film to the window.Tip: When sealing with glue, use a small fan to help dry it, and finally let it sit for twelve hours to ensure it is completely dry.
Installing the LCD Screen
The LCD is a 16×2 character display that supports I2C, and the wiring is simple, with two power wires and two signal wires.
Four 10mm brass standoffs are used to install the screen. One end of each standoff is a male screw, and the other end is a female screw. Follow the steps shown in the image.1. Pass the male screw through the LCD and tighten it with an M3 nut.
2. Secure one end of the standoff to the lid of the case with four M3 screws.3. Fix the standoffs. Be careful not to overtighten the screws to avoid deforming the plastic lid. When installing the LCD, pay attention to the orientation; the row with sixteen pins should be at the top.
Installing the Momentary Button
The momentary button is made of chrome material and comes with a rubber ring to prevent moisture from entering the case through the screw.Install the button as shown in the image.1. Loosen the nut, but the rubber ring should be fitted on top.
2. Insert the button into the hole on the lid and then tighten the nut from the back. Be careful not to overtighten the nut to avoid damaging the rubber ring, which would negate its waterproofing effect.
Power Supply and Charging Circuit
This step involves assembling the battery components. This includes the battery, main switch, lithium battery protection board, and boost converter. Use a single-cell lithium battery of 3.7V 1500 mAh, which fits perfectly in the case. You can also use an 18650 battery, but the size of the case will need to be adjusted.1. Solder the battery to the TP4056 charging board. Solder the JST RCY connector to the battery and charger (this step is optional). Be careful to observe the polarity of the battery when soldering to ensure correct installation.
2. Solder the wire from the positive output port of the charger (next to the positive battery wire) to the positive input port of the boost converter. Then solder the negative output wire (next to the negative battery wire) to the common (center) pin of the main switch.
Finally, solder the wire from the normally open pin of the switch to the negative input of the boost converter. If you connect a multimeter to the output of the boost converter and turn on the main switch, the voltage should be displayed.
3. Arduino, LCD screen, and flow sensor all require a 5V power supply, so set the output of the boost converter to 5V. Use a screwdriver to rotate the button on the potentiometer to adjust.
Turn on the main switch, connect the battery, and connect the multimeter to the output of the boost converter. Slowly rotate the potentiometer until the output reading is 5V.
4. Use a 3.5mm headphone jack for charging to avoid opening the case every time. Insert the connector into the hole at the bottom of the case (since the charging plug will often be unplugged, the hole must be at the bottom to prevent splashes from entering).
After installing the lock washer and tightening the nut, solder the two wires to the “tip” and “ground” of the connector.
5. The pin distribution of the connector is shown in the image. Solder the other end of the “ground” wire to the negative input port of the charger (next to the micro USB port).
Solder the “tip” wire to the +5V pad on the other side of the USB port. Do not use the USB port on the charger, as it is not guaranteed to be waterproof.
Making the Charging Cable
As shown in the image, make a power adapter using a wire with a USB A plug and a wire with a 3.5mm jack, where the 3.5mm audio jack serves as the charging port and USB A as the plug.
1. Prepare the USB wire. Strip the white wire sleeve from the white wire, exposing the red and black wires, then strip the insulation from the red and black wires. Some USB wires have four wires inside: red, black, green, and white. The green and white wires are used for data transmission and can be ignored.
2. Connect the 3.5mm plug to the USB wire. Connect the red wire of the USB to the middle soldering pad and the black wire to the ground soldering pad.
Flow Sensor
1. Working principle of the flow sensor:The flow sensor is very simple, compact, and waterproof. It features a rotor component that rotates based on the flow of water. The rotor component has a magnet.
The outside of the sensor has a small PCB board with a resistor and a Hall effect sensor. Each time the magnet passes the Hall effect sensor, it switches between high and low. In other words, every time the rotor component rotates, it switches between 5V and 0V.
To read the sensor, connect the red wire to +5V, the black wire to ground, and read the digital signal from the yellow wire.As shown in the image, when the flow is open, the signal changes. Initially, the signal is always zero. When the flow starts, the pulse frequency rises rapidly and stabilizes.When writing the program, note that the sensor outputs 450 pulses per liter.
2. Wiring the flow sensorThe flow sensor comes with a three-pin JST-XH connector. Since the connector’s wires are too short and have exposed points that can cause short circuits, they need to be connected to a wire with a 3.5mm audio jack. About three inches long, it is tinned wire, easy to solder.
Open the flow sensor cover to remove the circuit board, heat the three wires with a soldering iron, and solder them to the respective wires.
Then solder the 3.5mm audio wire to the pads. Solder according to the wire colors. +5V is on top, signal is on the ring, ground is on the sleeve. The setup is the same as for the charging port. If you accidentally plug the charger into the sensor port, it won’t damage the device.
3. Installing the flow sensor
Remove the showerhead and connect the flow sensor to the shower pipe. Since both ends of the sensor are male, a female-to-female coupler needs to be made. Use a 1/2 inch brass pipe to make a coupler, other materials are also acceptable (ensure the pipe matches the size of the sensor port).
Connect one end of the coupler to the flow sensor and the other end to the pipe. The flow sensor has an arrow indicating the direction of water flow. Make sure not to install it in reverse, or the measurement will be inaccurate. Finally, install the showerhead to the end of the flow sensor.
During installation, to prevent leaks, you can wrap the joints with plumber’s tape.
Installing the Arduino on the Circuit Board
1. Take a 1×2 inch rectangular circuit board, install the Arduino Nano in the middle of the board, and mark the position where the pins pass through.
2. Take two female headers, each with fifteen pins. Solder them to the circuit board. The Arduino can be removed for programming.
Be sure to mark the direction of the Arduino USB port to insert it into the circuit board in the same direction.
Assembly
The connection method of the components is shown in the image.
1. Cut some male headers and solder them to the +5V and ground rails on the circuit board. Then solder two headers to connect to Arduino’s A4 and A5 pins. Use female-to-female jumper wires to connect the LCD screen.
2. Solder the two wires from the output port of the boost converter to the +5V and ground rails. This powers the Arduino, LCD, and flow sensor. Cut two wires and connect them to the button’s port. One wire connects to ground, and the other connects to digital pin 3.
3. Solder the flow sensor. Since the sensor already has a 3.5mm plug installed, you only need to install a 3.5mm female socket. First, solder three wires, each labeled. Then insert the plug into the case and secure it with a nut.
Connect the sleeve to ground, the tip to +5V, and the ring to digital pin 2. I connected digital pins 2 and 3 to the button and flow sensor, respectively, as they are interrupt pins and easy to program.
4. Secure the LCD. Four female-to-female jumper wires are needed. Connect the “Vcc” pin to +5V, the “Gnd” pin to ground, the “SCL” pin to A5, and the “SDA” pin to A4. To better fit the LCD screen with the case, bend the pins backward. Be careful when handling to avoid bending the pins repeatedly.
Arduino Programming
Implement the following functions through programming:1. The first line of the LCD displays the total liters of water used, and the second line displays the total cost of the water or flow rate.2. When the showerhead is opened, the button can switch between displaying the cost and flow rate.3. When the showerhead is closed, the button clears all data and resets the screen.4. Use interrupt programming to read the sensor to avoid counting errors.5. When updating the screen, only update the changed values, rather than refreshing the entire screen each time (which causes flickering).
The program follows a simple structure. By using the millis() function, a delay is created without stopping the execution of the program. Please refer to this tutorial https://www.arduino.cc/en/tutorial/BlinkWithoutDelay, which is a case of blinking an LED without using the delay() function.
When the Arduino is powered on, the millis() function returns its milliseconds. By creating a variable “previousMillis” and subtracting millis() – previousMillis(), you can see the time used to update previousMillis.If you want it to happen once per second, you can write the following code:
if((millis() - previousMillis) >= 1000){
previousMillis = millis();
toggleLED();
}
Check if the difference between millis() (the current time) and previousMillis (the last time) is greater than or equal to 1000 milliseconds. If so, set previousMillis to the current time. Then proceed with other steps.
In this project, the next step is to toggle the LED. Then exit this code and complete the rest of the loop() function before returning to the start and repeating. This method is better than using the simple delay() function. Because delay() sets a time interval between instructions without considering the time spent running other instructions in the loop() function.
If what you are doing takes longer than blinking an LED, such as updating the LCD screen, the time spent is not negligible and will accumulate after several cycles. If you are preparing to update the LCD screen on the clock, it will cause delays.
The structure of the entire program has been introduced, and now you can insert instructions. Please carefully review the flowchart. Each segment of Arduino code has explanations, please read carefully. Relevant files can be downloaded from the project file library.https://make.quwj.com/project/137
Since water costs vary by city, please make changes according to the situation. The cost per liter of water in this city is 0.2523 cents. Please change it:
const float COST_PER_LITRE = 0.2523; // cost per litre, in cents, from city website
If you choose to measure water in gallons instead of liters, change all “LCD.print()” lines from “L” or “L/s” to “G” or “G/s”. Then remove the following line:
const float CONVERSION = 450.0; // keep this uncommented for litres
And uncomment this line:
const float CONVERSION = 1703.0; // uncomment this and delete the line above for gallons
You will notice the “¢” character; I prefer not to use dollars as costs often show as “$0.01” or less. Therefore, I custom-defined a character. The following byte array is used to represent this symbol:
byte cent_sign[] = {
B00100,
B00100,
B01111,
B10100,
B10100,
B01111,
B00100,
B00100
};
After creating this array, you must “create” and store this character.
lcd.createChar(0, cent_sign);
When done, print the custom character using the following line:
lcd.write(byte(0)); // print cents sign (¢)
The display can accommodate up to 8 custom characters. For more information:https://www.arduino.cc/en/Reference/LiquidCrystalCreateChar
At the same time, use the online tool:https://maxpromer.github.io/LCD-Character-Creator/It helps you design custom characters using a graphical interface and automatically generates the custom byte array.
Closing the Case
So far, the project is almost complete. Place all electronic devices into the case and close the lid.
1. Take four 30mm connected brass screws. I fixed them to the holes at the bottom of the case with four M3 screws.
2. Check that all electronic devices are securely fixed. Connect the charger and boost converter to the lid with double-sided tape.3. Wrap some tape around the metal surrounding the two 3.5mm sockets to ensure they do not short-circuit when connected to the connector.
4. Install the Arduino in the lower left corner of the side, with the USB port facing right. Use double-sided tape to secure the battery below the LCD screen, facing the bottom of the case.
5. Once all components are installed, close the case with four M3 screws.
Testing
1. Insert the 3.5mm connector into the flow sensor. Then turn on the device for operation.2. Turn on the main power switch. When no water flows in, the front panel button will not perform any operation except clearing the total and clearing the screen. The default total is zero, and the button will not perform any operation.
3. When the showerhead is opened, the total will start to increase. By default, the cost will be displayed. If you press the front panel button, the flow rate will be displayed on the last line. Pressing the front panel button will toggle between displaying flow rate and cost. When the showerhead is closed, pressing the front button will remeasure and clear the screen.
Notes
1. How to install the device will depend on the layout of your bathroom. It can be placed on the bathroom rack, and if not, suction cups can be used, but they are only suitable for smooth surfaces.
2. TroubleshootingThe screen is on, but the backlight is off—ensure the jumper is installed on the two pins on the I2C module side.
The screen is blank, but the backlight is on—check if the I2C address is correct using the I2C scanner https://playground.arduino.cc/Main/I2cScanner/.
The screen is on, but the value is zero—check for a signal from the sensor by measuring the voltage on pin 2. If there is no signal, check if the sensor is connected correctly.
The screen is blank, and the backlight is off—check if the power LED on the Arduino is lit and if the screen is powered.
The screen flickers, and then everything stops—you may have set the voltage on the boost converter too high (components cannot withstand more than 5V).
The device works, but the values are incorrect—ensure that the flow sensor you are using has the same conversion coefficient, i.e., 450 pulses per liter. Different sensors have different values.
Improvement Directions
Currently, the software runs well, but the ability to add different users (such as other family members, roommates, etc.) could be added. The device would store statistics for each person (total water usage and total showers) and display the average water usage for each person. This could encourage more people to conserve water.
1. Add EEPROM installation, the built-in non-volatile memory of Arduino. This way, data can be retained even when the device is turned off. We can create some specific spreadsheets to view data and plot graphs, making it clearer to see which season people bathe more frequently and for longer durations throughout the year.
2. Add a battery indicator. Currently, the only indication that the device needs charging is when the battery management board cuts off power. Connecting an additional analog input to measure the battery voltage is very simple. Since the battery voltage is always less than 5V, there is no need to install a voltage divider.
The project file library address:
http://make.quwj.com/project/137
via instructables.com/id/Save-Water-With-the-Shower-Water-Monitor/
Links in the text can be clicked to read the original at the end
More exciting content
Make a percussion band with Raspberry Pi
Biometric lock made with ESP8266
3D printed minimalist automatic fish feeder
Raspberry Pi + matrix to make a Bitcoin tracker
Cool ‘Thanos Glove’ appliance control terminal
Raspberry Pi + hat = wearable video recorder
Make an FM radio with Arduino
Leave a Comment
Your email address will not be published. Required fields are marked *