I spend quite a lot of time on figuring out what box to use. I had different ideas, from building one in wood by hand or with a CNC router, or buying a box at a home furnishing store. But then I started to look for cigar boxes, and I found lots on them on online auction sites.
So, next thing was construct the electronics. The coolest thing is obviously to do this without a microcontroller, but I decided to go for an Arduino Pro Mini, which is a tiny version of the Arduino. I had one at home and wanted to give it some excercise.
Another thing to decide was what to use for driving the mechanics. I wanted to learn using servos, so I got myself two standard servos.
The Arduino Pro Mini is a really compact Arduino where lots of features has been stripped away, among other things the ability to connect USB and reprogram the chip, so for that you need a separate board or cable, for example this or this.
When I started trying out the servos, I discovered they tended to move a little during Arduino boot, so I made a circuit that gives the servos power first when the boot is done. I build the circuit on a perfboard and added some nice headers where the Arduino Pro Mini can be stacked. You can read more about this circuit in this blog post.
When I started working with the code I started out with for-loops and delay() statements, which quite quickly turned in to a mess, and I wanted to be able to move two servos at different speeds at the same time, and make sure flipping the switch gave instant feedback. So therefore I made a super simple but neat library class for this. I will write about this in a later blog post. But the source code for the scetcn and the librarires is available here.
To make it more interesting and dynamic I added a bit of randomness to the speed and delay of the movements. Here’s a video demonstrating it.