There are plenty of commercial options for this type of switch but for quick prototyping (or hobby projects), this worked great. Best of all it was made from stuff laying around in about 10 minutes. 8 minutes to find stuff. 2 minutes to assemble. Can't beat that!
This was interfaced into a PLC (Programmable Logic Controller). The only problems I ran into was the tendency for the bolt to bounce a bit. This could be good or bad for your application. I just put a timer on the switch input so the PLC had to see a solid on or off for 1 second to react to a change. This eliminated any false positives. Without a controller to monitor the input, the switch will act as a momentary switch if bumped. When tipped to 15-20°, it will get a constant on (dependent on the weight of your bolt).
Step 1: Materials
(1) Pill Bottle (mine is Ø1.25" x 2.75" tall)
(1) Spring from Retractable Pen
(1) 10-24 Bolt, Nut, Washer (yours may vary, just make sure it threads securely into your spring)
(1) 10-24 x Ø.250" x 1.25" Shoulder Bolt (doesn't need to be a shoulder bolt, any bolt with some weight to it will work)
(1) Piece of Copper Shim Stock (enough to fully wrap inside of bottle)
(2) Lengths of 24GA Insulated Copper Wire
(1) Crimp on Loop End Connector
This same switch could be made from any number of alternatives. Get creative with what you have on hand.
Step 2: Tools Required
Soldering Iron (optional and not necessary)
Multimeter or simple circuit to test your handiwork
Step 3: Assembling The Switch
Drill a hole in the lid of your pill bottle sized appropriately for your screw.
Drill another hole in the side of your pill bottle for a wire to slip through.
Prep wires by stripping both ends. One end of the wire that will insert into the side of the pill bottle should be stripped around 1". attach a loop ring butt crimp connector to one end of the second wire.
Slide the cap bolt through the loop end connector and slide through pre-drilled hole in cap. Secure with split lock washer and nut.
Thread the spring onto the cap screw and thread the shoulder bolt or other appropriately weighted screw into the other end of the spring. You want the bolt to be heavy enough to overcome the weight of the spring but not too heavy. If you are only using a 10-24 screw, you could thread some extra nuts down to the head to add weight. Notice in the photos below, it can be pretty bouncy from the spring.
Cut a piece of copper shim stock (or other conductive material) long enough to wrap around the pill bottle. I left a bit of overlap as you can see in the photo below. Mine was the same height as the pill bottle but this isn't necessary since it only needs to be tall enough to touch the bolt head when it tips over.
Roll the copper shim stock around the pill bottle to form it into a tube shape. Test fit inside your bottle and adjust as needed. You want it to fit snug and expand to the outer wall of the pill bottle.
Insert the 1" long stripped wire end into the hole on the side of the pill bottle. Then slide the stripped wire end between the layers of the shim stock at the overlap as you slip the shim stock inside the pill bottle. You could solder the wire to the shim stock but it works perfectly fine just from the spring tension in the shim squeezing the bare wire.
Screw on the pill bottle cap and test your switch. Hooking the stripped wire ends up to your multimeter on the continuity setting, you can easily test and observe the properties of your switch. From here, you can make adjustments as needed for the desired result.