Extension board · Sensors and inputs

Vibration sensor

A very simple knock and shake detector. A spring switch closes for an instant when the board is shaken; the circuit stretches that into a pulse of about 34 ms, long enough for the controller to notice and run a command.

Top view of the vibration sensor board: a ten-contact socket on the left and right edges and the cylindrical spring switch lying near the bottom edge.
Top view, drawn from the board’s design files. This is a drawing, not a photograph.
On/offSW-18020P spring vibration switch
about 34 mssimulated pulse from a 2 ms contact
High = shakedigital output on contact 3
< 2 mAcalculated, from 3.3 V
2 socketstype X input and chain
50 × 55millimetres, four M3 holes

Tech specs

PurposeDetecting a knock or that a machine is moving. Not a measuring instrument and not a crash-protection or safety device
SensorSW-18020P spring switch, mounted lying down
OutputDigital, high while vibration is detected, through 100 Ω
Supply3.3 V from the socket, under 2 mA
IndicatorGreen LED lit while the output is high
SocketsTwo 10-contact Gadgeteer type X sockets (Samtec SHF-105, 1.27 mm): input and chain
Size50 × 55 mm, four M3 holes on a 40 × 40 mm pattern
Works withSmoothieboard V2 Prime header GF through the button box module
LicenceOpen hardware, CERN-OHL-S-2.0

Every figure with its basis is in the electrical specifications appendix; hole positions are in the mounting dimensions appendix.

Board tour

The numbers on the drawing match the list below it. The board is shown from the component side.

  1. 1
    Input socket X IN (J1) — The type X socket to the controller; the signal is on contact 3.
  2. 2
    Chain socket CHAIN (J2) — Passes the unused contacts on.
  3. 3
    Vibration switch (SW1) — A spring around a pin inside a small tube; sensitivity depends on how the board is oriented.
  4. 4
    Pulse stretcher (R1, R2, C1) — A closing switch empties the capacitor quickly; the 470 kΩ resistor refills it slowly.
  5. 5
    Schmitt inverter (U1) — SN74LVC1G14 turns the slow capacitor voltage into a clean digital pulse.
  6. 6
    Output resistor (R3) — 100 Ω in series with contact 3.
  7. 7
    Indicator (D1, R4) — Green LED, lit while the output is high.
  8. 8
    LED link (JP20) — Closed as delivered; open it to switch the LED off.
  9. 9
    Chain link (JP3) — Open as delivered, keeping the signal off the chain.
  10. 10
    Mounting hole — One of four M3 holes. Mount rigidly to the part being watched.
Point at a number, or tap it, to read what the part is; the same text is in the list. On a small screen, scroll the drawing sideways.

Pinout

Check contact numbering with the power removed before wiring by hand.

J1: input socket (X IN)

ContactSignalUsePrime header GF
13.3 VLogic and LED supply3.3 V
25 VPassed to the chain only5 V
3VIBHigh while shakingPB1
4 to 9Passed throughNot usedPJ4, PA4, PG0, PJ3, PG1, PJ2
10GNDGroundGND

What you need

A controller socketPrime header GF, or any input pin through three wires.
A ten-way cable1.27 mm Gadgeteer ribbon cable.
A rigid mountingThe vibration must reach the board.

Get started

Minimum wiring: contact 1 to contact 1, 3.3 V; PB1, contact 3 to contact 3, vibration; contact 10 to contact 10, ground. Prime header GF (J37) Vibration sensor J1 contact 1contact 13.3 V PB1, contact 3contact 3vibration contact 10contact 10ground
Three connections.
  1. Mount the board

    Screw it firmly to the part to be monitored.

  2. Connect with the power off

    Plug J1 into header GF.

  3. Tap the board

    Power up and tap it gently while watching the LED.

    By design the LED flashes briefly for each knock; the simulated pulse is about 34 ms.

  4. Add the configuration

    Use the entry below, restart and tap again with a terminal open.

    The configured command should run when the output goes high.

Configuration

You wantModuleExample
Run a command on a knockButton boxThe entry below
Measure vibration strengthNoneThe board only gives on/off

Add this to config.ini. The pulse is shorter than the button box default polling period of 50 ms (20 Hz), so raise the polling rate. Replace the echo command with your own.

[button box]
common.poll_frequency_hz = 100
shake.enable = true
shake.pin = PB1
shake.press = echo vibration detected

See the SmoothieV2 button box module. The common polling rate applies to every button in the section.

How it works

Switch closure discharges a capacitor; a Schmitt inverter turns it into a high output pulse. SW1closes on shake R1, R2, C1stretch U1invert J1 contact 3high = shake
One signal path.

At rest the capacitor is charged to 3.3 V and the inverter output is low. A shake closes the spring switch for a couple of milliseconds, which discharges the capacitor through 100 Ω. The output goes high and stays high while the 470 kΩ resistor recharges the capacitor up to the inverter threshold. Repeated shaking keeps the output high.

Solder links

Leave JP3 open while the sensor is in use. Open JP20 if the light is unwanted.

Solder links as delivered: JP3 open; JP20 closed. JP3 · openchain contact 3 JP20 · closedindicator LED
The links as delivered. Close one with a small blob of solder across both pads; open it by removing the solder or cutting the copper between the pads.
LinkWhat it doesAs delivered
JP3Joins contact 3 to the chain socketOpen
JP20Powers the indicator LED from the outputClosed

Chaining

A further board on CHAIN can use contacts 4 to 9.

The controller's ribbon cable goes to the connector X IN of the vibration sensor board. Inside the board each of the ten pins runs through a solder link to the connector CHAIN, where a second ribbon cable continues to the next board. A closed link passes its pin on, an open link stops it. Controller one ten-pin port vibration sensor board X IN CHAIN pin 3, vibration stops here pin 4, free passed on pin 5, free passed on one solder link per pin Next board sees what is passed on
Chaining: one port of the controller serves two boards. Pin 1 of X IN leads to pin 1 of CHAIN, pin 2 to pin 2, and so on, each through its own solder link. The three lines stand for the ten pins and show the links as delivered. Two boards must never drive the same pin, and a pin that one board uses for a signal is not free for the next. Pin 3 stops here; pins 4 and 5 are wired straight through.
ContactSignalOn CHAIN
1, 2, 10Power and groundPassed on
3VibrationStopped by open JP3
4 to 9FreePassed on

Troubleshooting

SymptomLikely causeWhat to check
LED never lightsNo 3.3 V, JP20 open, or vibration too weakTest point 3.3 V, then tap harder or turn the board
LED lights but no command runsPolling too slow or wrong pinSet the polling rate to 100 Hz and use PB1
Triggers constantlyMachine vibration or loose mountingMount elsewhere; the switch has no adjustment
Misses some knocksKnock along an insensitive directionChange the board orientation
Light Meaning
Green (D1) Output high: vibration detected

Still stuck? Read how to ask for help or see the general troubleshooting guide.

Downloads

FileWhat it is
Schematic (PDF)The circuit diagram
Parts list (CSV)Every component with its value, footprint and part number where one is chosen
Board drawing (PNG)The top view used on this page
3D view, top (PNG)Rendered from the design files
3D view, angled (PNG)Rendered from the design files

Appendix: mounting dimensions

For drilling a mounting plate or designing an enclosure. Positions are hole centres, in millimetres, measured from the top-left corner with the board seen from the component side.

Mounting drawing of the vibration sensor board, component side: outline 50 by 55 millimetres with 4 mounting holes. Hole positions are listed in the table below. COMPONENT SIDE · millimetres 50 55 0, 0 X Y 1 5.00, 5.00 2 45.00, 5.00 3 5.00, 45.00 4 45.00, 45.00 Numbered rings are mounting holes. Positions are hole centres, X then Y, from the marked corner.
Board outline 50 × 55 mm, corners rounded to a 1 mm radius, board thickness 1.6 mm. Drawn from the design files, component side up, in the same orientation as the board tour.
HoleX (mm)Y (mm)DiameterUse
15.005.003.2 mm, not platedMounting, M3 screw
245.005.003.2 mm, not platedMounting, M3 screw
35.0045.003.2 mm, not platedMounting, M3 screw
445.0045.003.2 mm, not platedMounting, M3 screw

Appendix: electrical specifications

Every figure is a design value, a calculated or simulated value, or a manufacturer’s data sheet value, as the last column says. A dash means no figure is given.

ParameterApplies toLowerNominalUpperBasis
Supply voltageJ1 contact 1—3.3 V—Design
Supply current3.3 V——2 mACalculated, LED lit
Output pulse from 2 ms contactContact 3—34 ms—Simulated; depends on inverter threshold
Peak contact currentSW1—25 mA—Simulated
Output series resistanceContact 3—100 Ω—Design

Component stress limits

PartLimitUse on this board
Switch contact current50 mA (limit used)25 mA peak (simulated)
Capacitors16 V3.3 V

Appendix: simulation

The pulse stretcher was simulated with ngspice for a 2 ms switch closure, with an assumed 1.6 V inverter threshold.

Each simulated value (yellow mark) against its allowed range (green band). Output pulse from a 2 ms contact closure33.8 ms Peak contact current against 50 mA rating25.4 mA Node level while closed913 µV
Simulated value (yellow) against the limit used for it (green). Each bar has its own scale.
ResultSimulated valueLimitOutcome
Output pulse from a 2 ms contact closure33.8 ms15 ms to 60 msWithin
Peak contact current against 50 mA rating25.4 mAat most 50 mAWithin
Node level while closed913 µVat most 400 mVWithin

Not simulated: mechanical sensitivity, frequency response, contact bounce and the spread of the inverter threshold.

Appendix: datasheet

The first page of each manufacturer data sheet. Click a page to open the PDF.

First page of the SW-180 series vibration switch datasheet
SW-180 series vibration switch — BaiLing, 3 pages.
First page of the SN74LVC1G14 single Schmitt-trigger inverter datasheet
SN74LVC1G14 single Schmitt-trigger inverter — Texas Instruments, 52 pages.

See all boards on the extension boards page.

This is a wiki! If you'd like to improve this page, you can edit it on GitHub.