A simple circuit to detect tilting motions.
- Raspberry PI 3 running Raspbian
- 1 - Mercury Switch Sensor
- 4 - male - male short jumpers
- 5 - male - female long jumpers
- 1 - Red two lead LED
- 1 - Green two lead LED
- 2 - 1K Ω Resistor (Brown, Black, Red, Gold)
A graphical representation of the Mercury Switch Circuit.
- Insert a male - female long jumper in the hot (red) column
- Insert a male - female long jumber in the ground (blue) column
- Insert the Mercury Switch into rows 15 (GND) through row 17 (S)
- Refer to the wiring image for module orientation
- Insert a male - male (short) jumper into the ground (blue) column and row 15
- Insert a male - male (short) jumper into the hot (red) column and row 16 (VCC)
- Insert a male - female (long) jumper into row 17 (S)
- Insert the Green LED into rows 26 (short lead) and 27 (long lead)
- Insert the Red LED into rows 26 (short lead) and 27 (long lead) on other side of the centerline
- Insert two 1KΩ resistors into rows 27 and 30, one on each side of the centerline
- Insert two male - male (short) jumpers into row 26 and the ground column, one on each side of the centerline
- Insert two male - female (long) jumpers into row 30, one on each side of the centerline
- Power down your Raspberry PI
- Open a terminal window and type
sudo halt - Unplug the Raspberry PI
- Open a terminal window and type
- Connect the hot female connector to Pin 4 (+5v)
- Connect the ground female connector to Pin 6 (Ground)
- Connect the female jumper from row 17 (S) to Pin 36 (GPIO 16)
- Connect the female jumper from row 30 (Red LED) to pin 38 (GPIO 20)
- Connect the female jumper from row 30 (Green LED) to pin 40 (GPIO 21)
- Verify your wiring! Mis-wiring will destroy the sensor!
- Boot your Raspberry PI
- Open a terminal window
- Execute ...
- mercury.py
**Note: **You may need to compile the program.
Can you modify the included code to change its behavior?
- Swap the red and green LED actions
- Change a while loop to a for loop
