knock sensor/How a knock becomes HIGH/03. The pull-down and the light
How a knock becomes HIGH · 03 of 10

The pull-down and the light

A 10 kΩ resistor from SIGNAL to GND holds the pin at 0 V while the spring hangs clear, and a red LED behind 1 kΩ lights whenever SIGNAL is HIGH. At rest the block draws no current at all. During a touch it takes about 3.5 mA from 5 V, for as long as the touch lasts, which is why the light flashes rather than glows.

The whole board in one drawing

The pull-down, the capacitor and the light
VCC
The spring
LED
about 3.00 mA
Pull-down
0.50 mA
From VCC
about 3.50 mA
Touching, SIGNAL is at 5 V. About 3.00 mA goes through the LED and its 1 kΩ, 0.50 mA through the pull-down, and the capacitor charges at once. It lasts only as long as the touch, a fraction of a millisecond at a time, so the light flashes rather than glows.

VCC goes to the switch. From the switch's other leg, SIGNAL goes to your pin and, on the board, three ways to ground: the 10 kΩ pull-down, R3; the 100 nF capacitor, C1; and the red LED with its 1 kΩ resistor, R4, after it. That is every part on the board. Flip the spring between at rest and touching and watch where the current goes.

The pull-down

An input pin with nothing connected to it reads whatever stray charge is on it, HIGH and LOW at random. At rest the switch connects SIGNAL to nothing, so without R3 that is what your pin would do, and a sketch would count knocks nobody made.

R3 ties SIGNAL to ground. At rest no current flows through it, so there is no voltage across it, and SIGNAL sits at 0 V: LOW, every time. During a touch the switch connects SIGNAL straight to VCC, which overrules a 10 kΩ resistor outright. The TK04 push button uses the same resistor for the same job, and its book shows the floating pin in a figure.

Two rules follow, and every sketch here keeps both: pinMode(pin, INPUT), not INPUT_PULLUP, and HIGH is a knock.

The light

The LED lights whenever SIGNAL is HIGH, from the wiring alone. On this board SIGNAL is HIGH only while the spring touches the rod, so a knock gives a flicker, not a glow: each flash is about as long as one touch. It is still the quickest test there is. A flicker when you knock means the switch and the supply work, and any fault is between SIGNAL and your sketch; no flicker means the block has no supply, or the knock never reached the spring.

Its current is worked out rather than measured. The LED is red, and a red 0805 LED drops about 2.0 V at these currents:

from 5 V:    (5.0 V - 2.0 V) / 1 kΩ = about 3 mA,    plus 0.5 mA in R3
from 3.3 V:  (3.3 V - 2.0 V) / 1 kΩ = about 1.3 mA,  plus 0.33 mA in R3

That current flows only during a touch, and it comes from the block's VCC pin through the switch, not from your input pin. At rest the block draws nothing.

When it does not work

Should I use INPUT_PULLUP?

No, use INPUT. The block already has its pull-down. Switching on the chip's internal pull-up as well puts two resistors in a tug of war on SIGNAL, and at rest it settles somewhere around a volt: not a clean LOW, and not a level any datasheet promises to read the same way twice.

I cannot see the LED flash.

Each flash lasts about as long as one touch of the spring, a fraction of a millisecond to a few milliseconds, so it is easy to miss in daylight. Look at it side on in a dim spot and knock the board itself firmly. On a 3.3 V board it is dimmer as well, about 1.3 mA against 3 mA from 5 V.

Does the block drain a battery while it waits?

No. At rest the spring touches nothing, so VCC is connected to nothing and no current flows through the pull-down or the LED. Current flows only during a touch: about 3.5 mA from 5 V, about 1.6 mA from 3.3 V, for milliseconds at a time.

Can I turn the LED off?

Not from code. It is wired to SIGNAL, so it flashes whenever the spring touches and VCC is connected. That is the point of it: it shows the switch and the supply are working even when the sketch is not.

Where this goes next

The 100 nF part, and why it stretches each touch by a millisecond or less.

What the capacitor does

Edit this page — content/books/knock-sensor/the-pull-down-and-the-light.mdx

Community

Questions about this product

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

Ask a question ↗

Knock 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