tilt sensor/Using it/10. When it reads wrong
Using it · 10 of 10

When it reads wrong

Start with the LED. It lights from VCC through the balls, whatever the sketch does, so it splits every fault in two: dark with the left edge down means the edge, VCC or GND; lit means the SIGNAL wire, the pin number or pinMode. Then the angle: near level, either reading is correct.

The LED first

The LED sits on SIGNAL and gets its current from VCC through the switch. It does not need your board's pin, or a sketch, to light. So before looking at code, tip the left edge well down and watch it.

When it reads wrong
What you see
The LED is fed from VCC through the switch, so dark means the balls are not on the contacts or VCC and GND never arrived. Check it is the left edge that is down, the one the can's leads are at, and by more than about 10°. Still dark: count from the square pad, GND, VCC, NC, SIGNAL.

Pick what you see. The board shows what the LED does in that case, and the verdict says where to look.

Dark: the edge, VCC, GND

If the LED stays dark with the block tipped, first check which edge. Only the left edge, where the can's two leads are, closes the switch, and only once it is clearly below the right. Tipping the header edge down leaves the can level. Then count from the square pad: GND, VCC, NC, SIGNAL. VCC goes to your board's logic voltage, GND to GND.

Lit: the wire and the sketch

If the LED lights and the sketch says LOW, the block is fine. SIGNAL is on a different pin from the one the sketch reads, or on NC. If the sketch says HIGH with the right edge down and the LED dark, look for INPUT_PULLUP, or a GND wire that is not there.

Near level, and when it moves

Flat on a desk, or standing on its header, the can is level, and the reading is whatever the last tilt left: not a fault. When the block is carried, the balls bounce, and gaps over about a millisecond reach the pin. Filter for 50 ms, as the counting build does, and mount it with one edge clearly down.

When it does not work

The LED stays dark with the block tipped.

Check it is the left edge that is down, the one the can's leads are at, and by well more than 10 degrees. Tipping the header or top edge down does nothing. Still dark: count from the square pad, GND, VCC, NC, SIGNAL, and check VCC goes to 3V3 or 5V and GND to GND.

The LED lights but digitalRead stays LOW.

The switch works and the block has power; the level is not reaching your pin. Check SIGNAL is on the pin TILT_PIN names, and that the wire is not on NC, which is connected to nothing.

It reads HIGH whichever way it is tipped.

Something holds SIGNAL up: INPUT_PULLUP instead of INPUT, or GND not connected so nothing holds it down. The LED tells these apart from a real HIGH: with the right edge down it should be dark.

Lying flat, it reads HIGH one time and LOW the next.

That is the switch working. Flat, the can is level and the balls stay where they last rolled. Only a clear tilt of the left or right edge is a reading.

Where this goes next

One roller in a square cell, four contacts, and a reading for each edge of the board.

Four sides at once: the TK19 Four-Direction Tilt Sensor →

Edit this page — content/books/tilt-sensor/when-it-reads-wrong.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 →