
Arduino Sensor Network – Bathroom occupancy detector - tonyd256
http://robots.thoughtbot.com/arduino-sensor-network
======
macNchz
My company made a very similar tool (using photoresistors instead of reed
switches to determine whether that bathroom was occupied) a couple of years
ago, it was a major lifesaver with single occupancy bathrooms:
[http://www.sanbornmediafactory.com/portfolio_pieces/bum/](http://www.sanbornmediafactory.com/portfolio_pieces/bum/)

------
revelation
Why would you abuse the WDT to periodically wake the AVR? You could connect
one of the reed switches to a true external interrupt and use that as your
wakeup call. Saves battery and you don't run the chance of missing anything in
between the second long checks.

~~~
tonyd256
I used the WDT to make a platform for sensing any sensor in second intervals.
Using the reed switches as external interrupts would have been specific to
this application. Also, the ATMega328P doesn't allow you to set the interrupt
to fire on CHANGE when using the lowest power mode.

For a door opening and closing a 1 second delay is fine. If it misses an event
with that delay then it was probably a fluke. Think of it as a buffer to
prevent false readings.

~~~
fancyketchup
This isn't to suggest that using the WDT in interval mode is the wrong
approach, and I know there's a certain amount of elegance to doing everything
with one chip, but you could still use the level interrupt by adding a 7486
(standard quad XOR gate). For the gate's inputs, you would use the reed switch
and a output pin from the AVR, and the gate's output would go to the external
interrupt line. If the ISR toggles the state of the output pin each time it
runs, the gate's output is only in the IRQ-asserted state for as long as it
takes the ISR to fire up--so you don't get constant interrupts while the
switch is closed, only a single one on the opening and closing transitions.

The 74LVC86 variant only draws a dozen, or so, microamps, which is dwarfed by
the current in the 10k pull-down resistor when the reed is closed, and
comparable to the standby current of the radio in the new radio.

~~~
tonyd256
I totally agree. There are definitely some more things like this that I could
have done to reduce power further and use normal external interrupts. I was
going for more of a general purpose sensor board though and wanted to keep it
minimal. I could also have used the HIGH and LOW level interrupts on those
pins and just change which it triggers on every time it triggered. But I
decided to go with the WDT.

------
Jemaclus
I did this a few years ago, but I simply bought a motion detector and hooked
it up to a light in the other room. Cost me like $25 and worked like a charm.
Buuuut one of the girls at the office complained because she thought it was
creepy, so we had to take it down. Somehow, someone standing around outside
the door waiting for their turn is less creepy...

------
jelder
Boundless ([http://www.boundless.com/](http://www.boundless.com/)) did this
first, and I think we did it better IMHO.

[https://github.com/jelder/doors](https://github.com/jelder/doors)
[http://doors.boundless.com/](http://doors.boundless.com/)

~~~
tonyd256
Great to see others are doing this too! I like your solution, very cool. I
have some of those digispark boards but decided to go in a different direction
making a standalone sensor board that transmits its sensor data to a hub for
pushing to the cloud. There are tons of ways this could be done. The way I
describe here worked best for us and achieved my goals for it.

------
chriskelley
Love it. A company I used to work with had something like this and hooked it
up to a dashboard widget - knowing "occupancy status" was just an F12 away!
The bathroom was on the far end of the floor and it was such a waste of time
to walk all the way over there to find it occupied. Such a great fix.

------
georgemcbay
Pretty cool, but why reed switches on the door instead of a passive IR
detector with a timeout? Neither is perfect, but the PIR doesn't rely on
people to remember not to close the door when leaving (which I assume is how
they determine actual occupancy?).

You could wire the same PIR to also control the light on/off state, so if
someone is having an epic poop but not moving too much you can be pretty sure
they'll move to make the light go on if they hit the timeout.

~~~
StavrosK
I did exactly this for my home light, I connected the Arduino as a USB
peripheral to my home server and use a PIR sensor and a photoresistor to turn
lights on/off when it's bright/dark/I'm home/I'm away. It works very well.

Partial writeup: [http://www.stavros.io/posts/control-rf-devices-with-
arduino/](http://www.stavros.io/posts/control-rf-devices-with-arduino/)

------
platz
Would it be possible to use something like an attiny2313 or even an attiny45,
do the job of handling the reed switch data and then delegating the rest of
the logic to a central server? I would think you'd get the most power savings
that way.

~~~
tonyd256
The ATMega328P is pretty low power. I could probably save a bit more with a
smaller more targeted MCU, but I wanted this board to be as close to the
Arduino Uno as possible. I'm not sure what you mean by a central server. It's
possible to use an ATTiny series chip to sense the reed switches and transmit
to the nRF24 board.

------
silicontroll
How original.
[http://stuffandymakes.com/2011/03/03/ipotti%E2%84%A2-release...](http://stuffandymakes.com/2011/03/03/ipotti%E2%84%A2-released/)

~~~
Udo
Someone shares something they made - with quite a bit of programming details -
and your reaction is "how original"? I've got news for you: _most_ things
aren't fundamentally new. That doesn't mean they're uncool or people hacking
hardware for the fun of it deserve your ridicule.

Now go, make something, and come back.

~~~
silicontroll
You're great at reading usernames.

~~~
Udo
I got the name, but I still wanted to invite you to do something more
rewarding with your time.

------
exelius
Downvotes for Arduino -- didn't you know the maker community has moved on to
Raspberry Pi? Nothing in the Arduino community has been updated in the last 2
years.

Edit: Jeez, sarcasm folks...

~~~
christoph
Arduino and Pi really serve different purposes to an extent. They are
different platforms and each does some things better than other. There are
certain things you can't achieve with a Pi that you can with an Arduino. Just
look around at the projects joining the two devices together for proof of
this.

Edit - just found this Kickstarter -
[https://www.kickstarter.com/projects/john-cole/arduberry-
uni...](https://www.kickstarter.com/projects/john-cole/arduberry-unite-
raspberry-pi-and-arduino)

~~~
exelius
I dunno, the Pi has a GPIO bus that replaces 99% of what people do with
Arduinos.

~~~
gnerd
THe GPIO is not going to help you build a custom H-bridge to drive motors
forward and backward with variable speed. You can use the 2 relay switches to
make one of those, but it will be noisy and you only get 1 H-bridge out of all
that wiring. You can get an add-on board for the Pi but most designs (I have
seen) seem to hijack all the GPIO pins, so any sensors you want to add onto
your robot will likely have to use USB (which rules out a lot of the cool low
power stuff).

There is a place for both systems, they do different things (even though there
is some overlap) so for any moderate project (say a little hexapod robot) you
are likely to use both. The Pi as a general purpose computer that can do all
your nav/ANN/signalling stuff and an Arduino board to receive the signals and
actually run your motors/servos (assuming you need more than 1 or 2).

