loading

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 ...

Adafruit

1 each:

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

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

http://www.amazon.com/gp/product/B006Z965BI/ref=oh...

Mouser

(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:

Adafruit:

  • 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)

Radio Shack:

  • 271-009 1/8-Watt 470 Ohm Carbon-Film Resistors (4)

Mouser.com:

  • 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

- Adafruit tutorial - connecting to Google Docs

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:

How to load RPi.GPIO

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 ...

WinSCP Download page

Edit pottylogger.py to put in your real Google account details, see below:

# Google Acoount Details

email = 'nnnnnnnnn@gmail.com'

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.

Running A Python Script At Boot Using Cron

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:

DHT Humidity Sensing on Raspberry Pi

<p>This is a very cheap and effective way to remotely monitor older people living alone. Monitor toilet flushes and usage of kettle is a good indicator all is well. Some things in life we do reguarly, making tea and going to the loo is one of them</p>
<p>It needs to weigh 'deposits' and keep scores online feature</p>
I don't know if anyone has suggested but... a weight sensor could ID the occupant with a moderate degree of accuracy.<br><br>Also, I can see this being miniaturized and built into a toilet seat with accompanying accessories like the roll holder and perhaps a moisture sensor/weight sensor in a mat to detect male occupants, ID them, and scan for &quot;splash factor&quot;. On second thought... being that I am male and married... let's not do that one. Hahaha!
<p>There's such a thing as TMI. </p>
<p>How about measuring the time spent in the restroom? This would have to be the time between when the door closed and the flush... You'll be able to tell if there was somebody either constipated or just sitting on the cell phone...</p>
<p>There are other bathroom tasks, like bathing, to consider</p>
<p>XD with a LED outside showing &quot;CONSTIPATED INSIDE 00:45:12&quot;.</p>
There were 2 flushing very close to each other.... Indian food?
<p>Don't recall, but probably failure to combine task type #1 &amp; #2</p>
<p>great work with the sensors, radio, and writeup. how might you check if the flush is proceeded with the washing of hands?</p>
<p>I usually was up afterwards</p>
I would probably attach a switch to the soap pump if you have one.
<p>how about just 2 wires under the faucet? the water would complete the circuit</p>
<p>Water really doesn't conduct that well unless you are dealing with pretty short distances or wall outlet-level power. You could still sense it, but the wires would have to be sticking out too. Besides, I'm one of those people who doesn't count a quick rinse without soap as washing.</p>
<p>Great! Now mum can keep an eye on whether you're going to the toilet regularly... How about modifying it to automatically open the window for 5 minutes after the flush has been used?</p>
<p>Would seem like task #1 or #2 would need to be detected</p>
<p>Priceles !!!!!</p><p>Lets get tweeter involved too. </p>
<p>Doable put not desirable IMO</p>
<p>It'd be like &quot;Poop Session - 4 mins 32 secs - 20cm TP used.&quot;</p>
<p>If it could make you flush remotely, It would be more powerful for people can't remember whether they did it or not...</p>
Please don't have it post pictures!!!
<p>this is great news for people that tweet everything they do. Now they can automatically tweet or post in facebook when they take a c**p. Fabulous advance for the human race!</p>
<p>Kewl. As someone who has been known to load up on Grape-Nuts (a US breakfast cereal) occasionally, how feasible do you think detecting a toilet clog/overflow might be?</p>
<p>Grape Nuts used to be in the UK as well but haven't seen them lately. One of my favs!</p>
The sensor would be extremely easy to make, just attach something buoyant to a limit switch and put it in back where it is out of the way. Just don't plan on reusing it afterwards ;)
<p>If you put an accelerometer inside the paper roller you could tell when and how much paper was taken. This could distinguish #1 from #2.</p>
<p>Yes, yes all very clever, but... you forgot the most important sensor of all... GAS!</p><p>Bugger the hand washing and flushing thingies, we need to know when it's safe to enter!</p>
<p>this is hilarious, i have a chrome extention that changes the word &quot;cloud&quot; to the word &quot;butt&quot; and the title says: Internet of Things Toilet Uploads Events to my Butt<br><br>this could not be a more appropriate (or rather inappropriate) time for this XD</p>
How about instead of reporting toilet paper change, alerting of low amount left?<br>Nice project. I'm in!

About This Instructable

54,837views

277favorites

License:

More by e024576:Small Parts Rack From Repurposed Chick-Fil-A Fruit Cups Magnetically Attached Small Part Bins Arduino Controlled Game: Pong-Bot Vs Human  
Add instructable to: