Vibration Sensor

SW18010P outside

The SW18010P, SW18015P, SW18020P, etc Vibration sensors are effectively just a delicate spring with a sturdy piece of metal in the middle. When moved, the spring wobbles around and touches the metal, momentarily making contact.

SW18010P inside

These are very useful little devices as they draw absolutely no power. They could easily be used in something like a toy, causing it to be activated when shaken, but otherwise not causing the battery to run down.

The number after SW18 specifies how much force is needed for them to make contact. We'd recommend the SW18010P, as a sensor such as the SW18020P requires quite a large amount of vibration before it'll trigger.


Wire these up exactly like is described for a Button.


You can use these exactly like a Button as well. The only difference is that you can't use debounce - as the spring inside the sensor will almost always be bouncing!

Instead, you'll want to detect the first vibration and then ignore everything else for a few milliseconds:

function shaken() {
  // do things here

// 'watch' B3 for shakes
var shakeTimeout;
setWatch(function() {
  if (shakeTimeout) return;
  shakeTimeout = setTimeout(function() { shakeTimeout = undefined; }, 200);
}, B3, {repeat:true, edge:"rising"});



This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.