I just read “Making Things Talk” by Tom Igoe , and wanted to have a go at a physical computing project.
I thought I’d make our cat door “twitter”. Ok, it’s not original, there are a few projects already done and published out there, but I thought it provide a fairly easy path into several topics I’ve not explored before :
- Electronics, components, soldering
- Arduino microprocessors http://www.arduino.cc/
- Twitter programming interface http://apiwiki.twitter.com/
I’m not complete on this project yet, but you can read how I’ve got on after the break…
To detect when the cat enters the house through the cat door, and post an “I’ve just come in” event to twitter. Similarly, when she goes out, to post a “I’ve just gone out” event to twitter.
All this must be done with low power consumption, and cheap components (no RFID detector, or web cam, as I don’t want to power a laptop 24 hours a day, and pay for the juice).
(no idea why it’s come out on it’s side 🙂
Overall, a normal catflap. This one happens to be a magnetic one which lets the cat in only if she has a collar. We’ve had neighbours cats coming in and eating food before we got this one.
The additions I’ve made are two reed switches, top and bottom, with wires which connect them to the arduino. These are stuck-on with Blu-tak right now.
In the middle of the door, there is a taped-on magnet. I’ll explain what that’s for next…
So the magnet taped to the door triggers the “coming in” sensor at the top of the unit, and the cat triggers the “going out” sensor at the bottom of the unit.
These switches are connected to the arduino +5v and via a pull-down resistor arrangement, to pins 0 and 1.
The arduino code can then hook interrupts from those pins to get a signal which fires on the “rising edge” of the switch state change, so there is no need to poll constantly for a switch state change.
Here you can see the circuit wired to the arduino on a breadboard, and the two reed switches.
The circuit has 2 LEDs attached also. The green one indicates that there is a connection to the broker which is working, the red one indicates that there is a problem with the connection to the broker.
Control logic on the arduino uses the arduino MQTT library, with the ethernet library, to connect to and post events to the broker.
I already had a damned small message broker installed on the slug, so it was an obvious choice to make the arduino publish a “cat coming in” or “cat going out” to the broker, and have a smarter program pre-process the events in the slug before sending them on to twitter.
Using a broker in this way also allows multiple programs to access the events, so a logger to a database can also be written, hooked up to a web page. I have left this for later as it’s an add-on to view historic events, just to prove how lazy our cat is.
The slug runs a java program using the “cvm” runtime, and subscribes to the broker topic so it can see the events from the door, selects one of the pre-canned phrases and posts that to twitter from there.
These kind-of speak for themselves…
A few were created by me with a hand-held magnet, just to get more traffic, as our cat is soooo lazy, and I didn’t want to wait getting the screen shot.
- An arduino off cool components. I went for the beginners kit, which it turns out would have been cheaper at nuelectronics. Never mind.
- A regulated, switched 9v (600ma) power supply. I don’t want to power a PC just to get a USB power connection to the arduino. This came from the most excellent Rapid Components, which seems to sell pretty much anything to do with electronics.
- An ethernet shield, also from cool components, so I can connect the arduino to our home network.
- A multi-meter, as I would need to test circuits. This was in the £7 area from Maplins. A simple handheld one which does volts, ohms and a few other things I’ve never used.
- Two “reed switches” from Maplins, though they do sell them in the local D.I.Y store too. These are switches which are sensitive to magnetism, so when a magnet is near, the switch is “on”. They are commonly used on windows and doors and connected to burglar alarms.
- A magnet, which I had already, stuck to the fridge door.
- A few LEDs and resistors
- A breadboard for prototyping
- A cat door. We have a Staywell 32 magnetic door, which allows the cat to come in only if she has a magnet hanging from her collar.
- One cat 🙂 Pretty obvious, but you need one of these to cause events to be generated, unless you use a magnet and do it yourself as above.
- Use the built-in pull-up resistors which you can turn on in software, instead of those I had to add, and use the falling-edge of the circuit to fire the interrupt.
- Use vero-board rather than a bread-board, or get a proto-shield to mount the components onto.
- Use a jack connector of some sort to plug the reed switches into the board.
- Smarten it all up with a box, white wires so they are non-obvious, and screw it to the wall
- Smarten-up the software so it recovers better when the connection to the broker fails (which it does sometimes with timeouts).
See how I did in other articles :
I’ve learnt a load of stuff doing this, and it’s given me a glimpse of what’s possible. Fantastic fun.
Feel free to follow @TipsyTheCat … I expect I’ll leave it all running for some time as I refine it.