This is a basic tilt sensor inspired by ball-and-cage style sensors, but 2d instead of 3d. A captured nickle connects pairs of wires depending on the sensor orientation. These are quick to build, and pretty cheap; I came up with them for a project where I wanted to know which face of a cube was pointing up (a task for which you only need two -- I'll leave that as an exercise to the reader).
The nickle does sometimes catch a bit on the perfboard; gluing something a bit slipperier onto the board, or lightly sanding it, might help.
Step 1: Break the Perfboard
Figure out how many holes apart you will need each pin in the cage to be -- you'd like it to be the case that the nickle only touches two at once, but too much play will waste board. I left six holes between pins, axis-aligned. This was a bit looser than I would have liked. Having the cage slightly diagonally oriented might allow a better fit.
After doing the layout, score and break the board. I score a few times on each side with a box knife and break over the corner of a table. In these pictures I'm making two sensors, so I've made four plates -- a top and a bottom for each. The little bit of extra board was useful elsewhere in the project.
Step 2: Build the Cage
To build the cage, cut and strip some solid-core wire (I happened to have copper around), and solder into one of the boards to create corner posts. Shore up the cage by gluing shims at each corner beside the posts. These are cut from popsicle stick, because popsicle stick plus hot-melt glue was just think enough that the nickle could slide freely.
Step 3: Top It Off.
Finally, glue the top down. With hot-melt, I could only manage to get two corners glued (any more and the glue would cool before I could thread the pins through the top board). I squished some extra in from the sides on the other corners.
Step 4: The Finished Product
You now have a cheap tilt sensor -- well, at least in as much as you already have perfboard, wire, solder, and hot glue. Show below, I've wired the sensor up to some leads, ready for installation into my orientation sensing cube.