Electronic circuits · no code

Tilt Switch Alarm

A tilt sensor with a small metal ball closes its contact when tilted and sounds a buzzer. It warns you that someone is moving an object or opening a lid.

  • LevelBeginner
  • Time15 min
  • Power9 V DC
  • CategoryAudio & alarms

Bill of materials

Everything you need to build it, with the reference you will see on the schematic.

Bill of materials
Qty Part Ref.
1 SW-520D tilt sensor (metal ball) SW1
1 10 kΩ resistor (brown-black-orange) R1
1 100 kΩ resistor (brown-black-yellow) R2
1 BC547 NPN transistor Q1
1 Active buzzer (3 to 24 V) BZ1
1 9 V battery with snap clip BT1
1 Breadboard (400 tie-points or more)
5 Jumper wires

Missing parts? The kits recommended by Impeca Tech include almost all of them. See the kits

Schematic & wiring

On the left, the circuit diagram; on the right, the same circuit built on a breadboard. Both connect exactly the same things.

Circuit diagram of “Tilt Switch Alarm”
Circuit diagram
Breadboard layout of “Tilt Switch Alarm”
Breadboard layout

Wire it step by step

  1. Place the components
    • Tilt sensor SW1 (SW-520D): one leg in 5f and the other in 3f (either way round), with the cylinder standing upright.
    • 10 kΩ resistor R1 (bands: brown, black, orange, gold): one leg in 3i and the other in 6i (either way round).
    • 100 kΩ resistor R2 (bands: brown, black, yellow, gold): one leg in 6f and the other in 9f (either way round).
    • BC547 transistor Q1 with the flat face (the one with the text) towards you, left to right: collector (C) in 7h, base (B) in 8h, emitter (E) in 9h.
    • Active buzzer BZ1: the long leg (marked +) in 13f and the other leg in 10f. Reversed, it will not sound.
  2. Add the jumper wires
    • Red wire: from 5j to the + (red) rail.
    • Red wire: from 13j to the + (red) rail.
    • Orange wire: from 6j to 8j.
    • Black wire: from 9j to the − (blue) rail.
    • Turquoise wire: from 7j to 10j.
  3. Connect the battery
    • Connect the 9 V battery to its clip: the clip’s red lead to the + (red) rail and the black one to the − (blue) rail. Do this last, once everything else is in place.
  4. Test the circuit
    • With the sensor upright the buzzer should be quiet. Tilt it about 45° to one side: it sounds. Put it back upright and it stops. If it is the other way round (sounds upright and stops when tilted), turn the sensor through 180° on the breadboard.

How to read the holes: the letter is the row and the number is the column of the breadboard (for example 7f). The red (+) and blue (−) rails are the two long lines along the edge.

How does it work?

  1. 1You tilt the sensor
  2. 2The ball joins the two terminals
  3. 3A small current reaches the base of Q1
  4. 4The buzzer sounds

The SW-520D is a cylinder with a small metal ball inside: depending on how you turn it, the ball joins its two terminals or not. In this circuit it acts as a switch that closes when tilted. When it closes, about 0.8 mA flows from the battery through R1 (10 kΩ) to the base of Q1 (BC547); Q1 conducts and passes about 28 mA to the active buzzer, which sounds. R2 (100 kΩ) holds the base at 0 V while the contact is open, so leakage cannot set the buzzer off. With the sensor at rest the battery draws almost no current. Depending on the maker, some SW-520D units are closed when upright and open when tilted: if yours works backwards, turn it through 180°. When shaken, the ball bounces and the buzzer sounds in bursts.

Testing & troubleshooting

What you should see

Sensor upright (at rest)
Buzzer currentunder 1 µA
Sensor tilted (the ball closes the contact)
Buzzer current≈ 28 mA
Voltage across the buzzer≈ 8.88 V
Current through the tilt sensor≈ 0.82 mA

Approximate values, calculated with typical parts. With real parts they can vary by 10 % or more.

If something does not work

It sounds at rest and stops when tilted

Your sensor closes its contact the other way: turn it through 180° (or mount it upside down). Depending on the brand the ball joins the terminals upright or tilted; the circuit is the same.

The buzzer sounds in short bursts

That is normal: the ball bounces and opens and closes the contact many times a second. If you tilt it slowly and hold it tilted, it sounds continuously. Also check that the buzzer + goes towards the battery.

Want to automate this circuit with code?

Learn how to program sensors and custom schedules in our e-book “Arduino from Scratch”.