[MUSIC PLAYING]
[TOILET FLUSHING]
Welcome to DIY Tryin.
Attach sensors to
all the things!
I'm Patrick Norton.
I'm Michael Hand.
This man is the hero
of our office today.
That's what we're
going to do today.
We're going to make you
into the office hero.
Sensors, Raspberry Pi, website.
Yeah, hundreds of
people hours saved.
So here at DVN, we have
a big bathroom problem
where there's two bathrooms.
Well, yes.
[LAUGHING]
And like 54 people.
Yeah.
So, there's a lot of waiting
in line for the bathroom.
I made a website using a
Raspberry Pi to update and tell
you whether or not the
bathroom is actually open.
So, you know, you could if you
want to, use the Raspberry Pi
B+, the recent update to
the Raspberry Pi model.
We did a review of
that on Tekzilla,
youtube.com/tekzilla
I guess last week,
two weeks ago when it came out.
Like that.
It's very similar,
and watch the video
to find out how
similar it actually is.
But right now, you're
actually, basically
using a door sensor, a
homemade door sensor,
feeding in information
to Raspberry Pi, which
sends a signal out
to a web server.
Using Dropbox for that
because I'm cheap.
I like being cheap.
And the final piece,
de resistance,
which is disconnected
at the moment
so I don't electrocute myself.
A Signal light. [LAUGHING]
Yeah, so we have
signal lights so
that if people don't want
to go to the website,
they can just check that out.
Should we start with the sensor,
the code, or the website?
Let's just do it all, right
after, one after another.
Sensors.
Sensors it is.
Here are my ghetto
aluminum foil and duct
tape with some wires sensors.
So, it's pretty simple.
There's one sensor on
the inner door jamb,
and then one the door over here.
So when the door closes,
it will close the contact,
and then the Raspberry Pi knows
that the button is closed.
All right., our
door sensor wires
are running to this
breadboard, which
we have it wired up
with some resistors
so that the Raspberry Pi knows
when the connection is closed,
and which door the
connection is closed on.
So from there, we can
see that, and then we
can modify some HTML
in our update page,
and then send that up to
Dropbox because that's
what we're using as our hosting.
So also connected here, is
we have an 8-channel relay,
but we're only using
two channels of it.
This is used so that when the
door connection is closed,
it will turn on a light so
that if people don't want
to go to the website, they can
just check to see if the lights
on.
Because if it's on,
someone's in the back.
Michael and I got back from the
local building recycling center
with a couple of 8-1/2
inch stoplight lenses,
and a big ole' length of heavy
duty extension cord that I
basically connected all of
the neutral lines from the two
lamps, and from the pigtail we
needed for the power supply.
And since we're in
a pretty simple kind
of scroungy mood
on this project.
We got out the
Gorilla tape and used
that to tape our
stoplight lenses
to the front of our lamps.
On to the actual code.
First, we have all of our
libraries that we're importing.
The important ones
here are BeautifulSoup,
which makes it really
easy to modify HTML,
and RPi.GPIO that makes it
so you can access the GPIO
pins on the Raspberry Pi.
Then we set up our GPIO pins.
I'll put a link
in the show notes
of what you need for
the Raspberry Pi.
It's a little bit
different than Arduino
you just need a
resistor, pretty much.
We have our input pins
that are connected
to the doors and our output
pins, which trigger the lights.
We got some generic
variables here.
And then the HTML
file that we'll
be actually updating, and
onto our first function.
Some cool things, the
threading.Timer function,
will let you just keep
on running a function,
so that's how it will
run indefinitely.
Getting access to
our count variables
so that we can check how
long someone's been in there.
Not as creepy as it sounds, it's
just so that after 10 minutes,
if the door has been closed,
I'll post a status saying,
"Hey, the door might just be
closed and no one is in there,
so check it out."
Then, onto actually
checking to see
if our connections are closed.
So if it is closed, we'll send
the status one and the bathroom
number to our
updateHTML function.
Show that in a minute.
We'll update the timer, and
then we'll turn on the light.
Otherwise, we'll
send status zero,
we'll reset the count timer, and
then we'll turn the light off.
And then, if the count
has been over 600 seconds,
we will send status
three in the bathroom.
Same idea for bathroom two.
So our updateHTLM
function, it'll
accept the bathroom
number that's being sent
and the status number.
First we open up our HTML file.
If the bathroom is closed,
then it will modify the DIVs
and all that.
And BeautifulSoup
makes things so easy.
If the bathroom is open,
then we'll say it's open.
And if the bathroom has
been closed for a long time,
we'll say, "Jiggle the handle."
Then we need to
update the website.
Right now, I'm using
a script called
Dropbox uploader that just
uploads files to Dropbox,
and I'm sending it
to the public folder,
so that I can do a generic URL
forwarding from the website
that I bought.
And then the end of
the function is just
to set off the initial function
so that the timers can kick in.
And that's about it.
And from all of that, we can
go to our bathroomstatus.com
and refresh.
I should probably
put an auto refresh,
but you can see that
bathroom one is now
closed as of this time.
And bathroom two is
open at this point.
And of course, our lights
also signal that information.
And if you want to learn more
about Python or the Raspberry
Pi, you can check out our
sponsor at lynda.com/DIY
They've got tons of Python
tutorials up and running with
the Raspberry Pi.
Lots of good information.
You'll learn something, and
you'll help out the show
lynda.com/DIY
Hey Trace, what do you
think of bathroomstatus.com?
I think it's awesome.
I even put it on my dashboard.
Currently, bathroom
one is closed.
Sadly.
Hey Trace, do you
notice the new addition?
What new addition?
Look over there.
Oh my God!
You got some lights.
Wow.
That's a really massive
light. [LAUGHING]
OK.
Bathroom one is open.
Bathroom two is open.
I'm going to pee.
Hey relax.
It's empty.
[LAUGHING]
See you around.
People are so into this project.
I've had like 10 people
come up to me and be like,
this is the best
thing I've ever seen.
That's because people hate
waiting for the bathroom
because they can be
finishing a script,
or calling somebody to
set up an interview,
or ordering something on
Amazon, or ordering cannoli,
or rearranging their
pencils or doing anything,
but sitting in line and
waiting for the bathroom.
The thing is though,
while we used,
you know, a sensor, plus
Raspberry Pi, plus Python
to create a device that tells
people when the bathroom is
open or not open,
you could use this
to say with a thermal
sensor to send you
a message when your freezer
is getting above 32 degrees.
Uh-huh.
Or if there's water in the
basement of your house.
You can use
BeagleBoards, Arduinos,
anything that you want.
It just depends on how much
money you want to spend,
whether you need networking,
and what you like to code in.
What do you like to code in?
Do us a favor, tell us
DIYTryin@revision3.com
or @DIYTryin And do us
a favor, share the show
with your friends.
Tell them to subscribe.
If you haven't subscribed,
you should subscribe.
Find out all about it on our
new website, DIYTryin.com
It's slick.
It's awesome.
It's shiny.
And there's buttons that
help you share and get
the RSS feeds, or however
you want to watch us.
We're on the Roku.
We're on iTunes.
We're everywhere, man.
And of course, where
on youtube.com/diytryin
But go to the new website
because it's nice.
It's nice.
I'm Patrick Norton.
I'm Michael Hand.
We'll see you next
week on DIYTryin.
Making lives great.
That's it for this
episode of DIYTryin.
We're going to quit
while we're ahead.
This is our last episode.
Sorry.
Yeah.
It was--
[LAUGHTER]
We need a shot of that face.
We were joking, but we
need a shot of that face.
That was awesome.
