SW-420 vibration sensor
The SW-420 vibration sensor: a sealed vibration switch on an LM393 board, one digital output. Aliases: vibration switch, shake sensor.
The SW-420 is a metal can with a contact inside that stays closed while the can sits still. Shake it, tap the table it is screwed to, or knock on the door it is taped to, and the contact bounces open and shut for as long as the vibration lasts.
Pins
| Pin | What it does |
|---|---|
VCC |
Supply, 3.3 V to 5 V. |
GND |
Ground. |
DO |
Low when still, with the lamp lit. Pulses high while it vibrates. |
Properties
threshold is the trimmer as a fraction of the supply, 0.5 by default. With a switch
on the comparator's input, the input is at one rail or the other, so the trimmer only
matters at its very ends.
While it runs
Press knock for one tap on whatever the sensor is fixed to. Press shake to keep
it shaking, and press it again to set it down.
What the model gets right
A knock is a burst. A knock is not one clean high on DO. The contact bounces
open for 0.5 to 3 ms, shut for 0.5 to 3 ms, and so on for about 30 ms, so DO pulses
high several times. A sketch that counts every rising edge counts one knock as four
or five. There is no datasheet for the contact's timing; those numbers are the order
of what a scope shows across one, and they are an assumption.
Still is low. The board hangs the switch from the comparator's input to ground
under a 10 k pull-up, so a closed contact holds DO low and the lamp lit.
What it does not model
How hard the knock is: a real switch opens more on a hard knock, and a gentle one may not open it at all. The direction of the shake is not modeled either. The bounce pattern comes from a fixed pseudo-random sequence, so a run repeats exactly.
Common mistakes
Counting edges on DO as knocks. Take the first edge, then ignore DO for about
100 ms.
Reading it as active low. On this board DO goes high on vibration, the opposite
of the FC-51 and the flame sensor.
See it in action
Secret knock lock opens a servo bolt when it hears the right rhythm. Open it at /templates.