Skip to content

Latest commit

 

History

History
63 lines (44 loc) · 1.7 KB

Vibration.md

File metadata and controls

63 lines (44 loc) · 1.7 KB

Vibration Sensor

  • KEYWORDS: Vibration,Switch,Shake,Movement,SW18010P,SW18015P,SW18020P

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.

Wiring

Wire these up exactly like is described for a [[Button]].

Software

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;
  shaken();
  shakeTimeout = setTimeout(function() { shakeTimeout = undefined; }, 200);
}, B3, {repeat:true, edge:"rising"});

Using

  • APPEND_USES: Vibration,SW18010P,SW18015P,SW18020P

Buying