tilt sensor/Reading it/08. A rattle is not a tilt
Reading it · 08 of 10

A rattle is not a tilt

The balls are loose on purpose, so a knock lifts them off the contacts and drops them again. The board's 100 nF hides any gap shorter than about a millisecond on a 3.3 V board, half that on an Uno; longer ones reach your pin as LOW. A sketch that believes a change only after it has held for 50 ms ignores all of it.

A rattle is a real change

Carry the block, or tap the table, and the balls bounce. Each time they lift off the contacts the switch really is open, for a moment. The first read prints those moments; a counter would count them; an alarm would go off.

A rattle is not a tilt
Your board
Openings
0
Read LOW
0
Capacitor holds
about 1.1 ms
Sketch saw
...
The block sits lead end down, switch closed, and is knocked. Press Play to watch the next 45 ms.

Press Play. The block sits with its left edge down, switch closed, and is knocked; the top lane is the balls, lifting off six times in 45 ms. The timing is a picture, not a measurement: nobody has put this switch on a scope. The middle lane is the part that is worked out, from the parts on the board.

What the capacitor hides

When the balls lift off, nothing is driving SIGNAL any more, but the 100 nF is still full. It empties through the 1 kΩ and the LED quickly down to about 2 V, where the LED stops conducting, then through the 10 kΩ alone, with a time constant of 1 ms. Your pin reads LOW only once SIGNAL falls under its own threshold:

  • ESP32, ESP32-S3: under 0.825 V, about 1.1 ms after the balls lift.
  • Pico: under 0.8 V, about the same.
  • Uno: under 1.5 V, about 0.55 ms, because an Uno calls LOW at a higher voltage.

A gap shorter than that never shows. Switch the figure to the Uno and two more of the six get through. It works in one direction only: when the balls land, they fill the capacitor through the contacts in a microsecond, so a brief closing from a level block is not hidden at all.

What the sketch has to do

Anything longer than a millisecond is the sketch's problem. The fix is the one every contact needs: believe a new level only once it has held for a while. A rattle lasts milliseconds, a real tilt lasts as long as the block stays tipped, so 50 ms sits comfortably between them. The four-direction block's book uses the same 50 ms, as a count of five scans; counting tips does it with a clock.

When it does not work

The Uno flickers where the ESP32 did not.

An Uno reads LOW from 1.5 V, a 3.3 V board only under about 0.8 V, so the capacitor holds the Uno's pin for a shorter time: about half a millisecond against about one. Short gaps that an ESP32 never sees can reach an Uno. The 50 ms filter covers both.

Can I use a bigger capacitor instead of a filter?

It would hold SIGNAL up longer after each opening, but it cannot hide a gap that lasts tens of milliseconds, and it slows every real change down with it. The filter in the sketch is free and adjustable; leave the board as it is.

It flickers while resting on a table that vibrates.

A level can is where the balls move most easily, and a vibrating table moves them. Mount it with one edge clearly down, so gravity holds the balls at one end, and filter in the sketch.

Where this goes next

A counter for something that tips back and forth, filtered with millis().

Counting tips →

Edit this page — content/books/tilt-sensor/a-rattle-is-not-a-tilt.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Tilt Sensor

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum →