Introduction: Internet of Things Toilet Uploads Events to the Cloud (Raspberry PI)
Internet of Things Toilet uploads flush events and toilet paper roll change out events to Google Drive spreadsheet.
How does it work? – An aquarium liquid level sensor float switch detects toilet tank level; flushing lowers the level closing the switch. A photo cell located in socket (blind hole) of the toilet paper holder spindle mounting arm detects when the spindle is removed to change out the toilet paper (letting light hits the photo cell, thus "closing the switch").
Signals from these two sensors are sent (wirelessly -despite what the intro photo implies) via a hacked two button key fob; that is, sensor switch closure effectively pushes a button. A 315 MHz receiver module connected to a Raspberry Pi receives switch closure signals.
The Raspberry Pi, using Python API gspread, transmits the event data to Google Drive spreadsheet.
See system layout image.
How hard and how much $ ? - Assuming you already have a Raspberry Pi, and you know how to load and run Python programs, and can build basic electronic circuits – this is pretty easy & quite inexpensive (< $40) IoT (Internet of Things) project.
Why do this? - (1) To explore IoT on the cheap, and (2) because I can.
Step 1: Stuff You Need
Assuming you already have a Raspberry Pi, additional stuff you'll need ...
Keyfob 2-Button RF Remote Control - 315MHz (products/1391) PID: 1391 $6.95
Simple RF M4 Receiver - 315MHz Momentary Type (products/1096) PID: 1096 $4.95
Photo cell (CdS photoresistor) (products/161) PID: 161 $0.95
Stacking Header for Raspberry Pi - 2x13 Extra Tall (products/1112) PID: 1112 $1.95
Adafruit Half-size Perma-Proto Raspberry Pi Breadboard PCB Kit (products/1148) PID: 1148
Radio Shack 271-009 1/8-Watt 470 Ohm Carbon-Film Resistors (4 req'd, but 5 in the pack)
Amazon.com, 1 each:
Aquarium Wired Liquid Water Level Sensor Float Switch
(1 req'd) - 5mm Through-hole LEDs with Built-in 5V Resistor, Red # 604-WP7113ID5V
(1 req'd) -5mm Through-hole LEDs with Built-in 5V Resistor, Green # 604-WP7113SGD5V
(2 req'd) - 2 pin Female Headers # 517-929870-01-02-RB
(2 req'd) - 2 pin Male Headers # 571-4-103321-4
plus misc stuff like hookup wire, solder ...
Step 2: Mount Liquid Level Sensor Float Switch in Toilet Tank
Build - Bend a coat hanger into a float switch bracket as shown. The bracket should position the switch clear of the toilet tank sidewall, and hang far enough down so the switch float ring is fully up when the toilet is "un-flushed". Position bracket along tank back wall so it doesn't interfere with anything. Secure bracket and switch leads to the top tank wall with duck tape.
Check - Connect a multimeter leads to switch to check continuity.
With the toilet un-flushed the switch should be open, flushing the toilet should close the switch, and finally as the tank refills the switch should return to open.
Note - You now have a sensor to detect when the toilet is flushed
Step 3: Mount Toilet Roll Sensor (photo Cell)
Build - Drill 1/4 inch hole centered inside the spindle roll holding "blind hole" of one arm of the toilet paper holder as shown. Note - the photo cell will be installed into this 1/4 inch hole - so with roll spindle installed, the photo cell will be dark, and when the spindle is removed, light will reach the photo cell.
To prevent light from reaching the the photocell from the back side, place photo cell leads through a small piece of black plastic (I cut mine from microwave dinner plate). Solder photo cell leads to short lengths of wire (insulate with heat shrink tubing) and a 2 pin male header. The wire needs to be long enough to reach the two button key fob placed next to the toilet paper roll holder, see photo.
With black electrical tape, secure photo cell "light tight" to arm backside.
Check - Connect a multimeter to photo cell leads to check resistance. With the toilet paper roll installed the photo cell should be dark and the resistance high (I measured 4 Mohm). Remove the toilet paper roll, room light should now reach the photo cell and the resistance should be much lower (I measured 14 Kohm).
Note - You now have a sensor to detect when the toilet paper roll is replaced
Step 4: Build and Test Circuit to Connect 315 MHz Receiver to Raspberry Pi
Overview - Objective is to connect the receiver module, and two status LEDs to the Raspberry Pi GPIO pins: 5V, Ground, GPIO-18, GPIO 23.
See circuit diagram and signal path table.
Main parts needed for this step are:
- Simple RF M4 Receiver - 315MHz Momentary Type (products/1096) PID: 1096
- Stacking Header for Raspberry Pi - 2x13 Extra Tall (products/1112) PID: 1112
- Adafruit Half-size Perma-Proto Raspberry Pi Breadboard PCB Kit (products/1148)
- 271-009 1/8-Watt 470 Ohm Carbon-Film Resistors (4)
- 5mm Through-hole LEDs with Built-in 5V Resistor, Red # 604-WP7113ID5V
- 5mm Through-hole LEDs with Built-in 5V Resistor, Green # 604-WP7113SGD5V
Build - Because we're using only the outboard GPIO pins, I cut (used a Dremel cut-off wheel) the traces on the underside of the Perma-Proto board leading to the inside GPIO pins to allow use of back half of Perma-Proto board with accidentally connecting to GPIO pins we're not intending to use (see photo). Solder the Perma-Proto board high up on the stacking header, so the board is well above all components on the Raspberry Pi (especially important if you plan to use a RasPi case). This creates a kind of a wing "flying" above the RasPi, see photos.
Follow the circuit diagram and photos to add wire, LEDs, and resistors to the board - add the receiver module.
Test - Before installing the board on your RasPi, please test - a single wiring error can easily "fry your pi."
a) Apply 5 VDC to GPIO pins 5v and gnd.
Expected results: no smoke, red and green LEDs both off, voltage between GPIO 18 and GPIO gnd is about zero (measure with mulitmeter).
b) Now press "A" button on key fob.
Expected results: no smoke, red Led on and green LED off, voltage between GPIO 18 and GPIO gnd is about 2.5 volts (measure with mulitmeter).
c) Now press "B" button on key fob.
Expected results: no smoke, red Led off and green LED on, voltage between GPIO 23 and GPIO gnd is about 2.5 volts (measure with mulitmeter).
Note - key fob can't send both "A" and "B" button presses at the same time.
Step 5: Hack, Mount, Connect Sensors & Test 2 Button Key Fob
Hack - Split key fob open, remove batteries and PCB. Remove the plastic film holding the two button tops over the PCB. Tin with solder the PCB board two "bulls eye looking" contacts. Tin and solder two female headers to PCB as shown in the photos. One female header terminal goes to the center dot, the other connects to outer ring. Cut header access slots where the buttons used to be in the semi-transparent plastic cover, see photo. Re-install batteries and reassemble the key fob.
Test - Using the receiver test setup from the previous step, "press" top button "A" by shorting top female header two socket holes together with a short jumper wire - the key fob indicator LED should go on; receiver PCB board red LED should also go on.
Repeat the above step, but this time - "press" bottom button "B" by shorting bottom female header two socket holes together with a short jumper wire - the key fob indicator LED should go on; receiver PCB board green LED should also go on.
Mount - Mount the hacked key fob next to the toilet paper holder in some removable way (like Velcro)
Connect Sensors - Using wire and two 2 pin male headers, attach the sensors to the key fob. Flush sensor goes to top "A" female key fob connector. Toilet paper roll sensor goes bottom "B" female key fob connector on the key fob
Test 2 - Using the receiver test setup from the previous step, flush the toilet - the key fob indicator LED should go on; receiver PCB board red LED should also go on. After the toilet tank refills itself, both LEDs should go off.
After the above test is completed, then remove the toilet paper roll - the key fob indicator LED should go on; receiver PCB board green LED should also go on. Replacing the toil paper roll should turn both LEDs off.
Step 6: Connecting to Google Docs Spreadsheet
Step Objectives -
Properly setup spreadsheet in Google Drive to receive info uploaded from Raspberry Pi
Load two python libraries gspread and Rpi.GPIO the python program will need to run properly
Build - Read the first half of instructions from the Adafruit leaning system
read down to where it says "Next, in the examples directory again, ..."
You need to do pretty much the same things here except the spreadsheet name is "Potty_logger" and the spreadsheet only needs two columns: "Date & Time" and "Activity"
Also follow the instructions to load gspread library
To load Rpi.GPIO library follow these instructions:
Step 7: Load Python Program and Final
Build - Download pottylogger.py to your computer and transfer to /home/pi directory on RasPi. I usually use WinSCP to transfer files between my PC and RasPi ...
Edit pottylogger.py to put in your real Google account details, see below:
# Google Acoount Details
email = 'firstname.lastname@example.org'
password = 'xxxxxxxx'
Attach the receiver module to RasPi GPIO pins
Test - enter the below command from the RasPi /home/pi directory command line
sudo python pottylogger.py
There should be no error messages. Now flush the toilet - the event info should be written to both the RasPi screen and after a minute or so be appended to the Google Drive spreadsheet Potty_Logger, see photo examples.
Now wait a minutes or so for the toilet to finish the flush cycle, then remove and then re-install the toil paper spindle - again the event info should be written to both the RasPi screen and after a minute or so be appended to the Google Drive spreadsheet Potty_Logger.
Notes - To prevent event double counting the python program pauses for 60 seconds after the beginning of a flush event and 120 seconds after the beginning of toilet paper R&R event, so if things happen faster than that, they don't get counted.
You can have this python program automatically start whenever the RasPi boots up, see reference below.
This same method might also be used for other simple event logging like refrigerator doors openings.
This instructable was enabled and inspired by the below project on the Adafruit Learning system:
Finalist in the