When a knock does nothing
Knock the board itself and watch the red LED. A flicker means the switch and the supply work, and the fault is between SIGNAL and the sketch, most often a delay() that sleeps through the pulses. No flicker means VCC, GND, or a knock that never reached the spring.
Start with the light
The red LED on the block is wired to SIGNAL, so it lights whenever the spring touches the rod, from the wiring alone. No sketch, no pin number, no serial port is involved. That splits every fault in two before you open the code.
It only flickers, though: each flash lasts about as long as one touch of the spring. Look at it side on, out of direct light, and knock the board itself, firmly, rather than the far end of the table.
Pick what the block is doing. The first check in each list is the one that is most often the answer, and the ringed part on the board is where to look.
A flicker, and nothing in the sketch
This is the common one, and it is nearly always time rather than wiring. A
knock keeps SIGNAL HIGH for a few milliseconds in all, spread over several
short pulses. A loop() with a delay(100) in it looks at the pin ten times
a second and misses nearly all of them, which is what the old sketches for
this block did. Catching it with an
interrupt
is the fix that survives any amount of other work in loop().
If the sketch never waits and still sees nothing, check that KNOCK_PIN is
the GPIO number SIGNAL is wired to, not the pin's position along the
header, and that the block and your board share a GND.
No flicker at all
Then the switch has nothing to deliver. VCC is not connected, GND is not connected, or the cable is one pin over: count from the square pad, GND, VCC, NC, SIGNAL. If all three wires are right, the knock is not reaching the spring: fix the board down and knock closer.
Too many knocks
Several counts per knock is the spring ringing, and a hold-off of about
100 ms, as in one knock is many
pulses, counts it
once. Hundreds of counts per knock means the sketch is counting every pass
of loop() while SIGNAL is HIGH, not the change to HIGH. Counts with
nobody knocking are vibration from something else on the same surface.
When it does not work
The knock reached SIGNAL, so look after it. A delay() in loop() is the usual cause: each pulse lasts about a millisecond, and a loop that sleeps for 100 ms is asleep for almost all of them. Read the pin in a loop that never waits, or with an interrupt. Then check KNOCK_PIN is the GPIO number SIGNAL is on, and that the two boards share a GND.
Something is shaking the surface: a motor, a fan, a speaker, footsteps on a wooden floor. The switch cannot tell them from a knuckle. Move the block, or put it on something that damps vibration, and make the sketch want a pattern of knocks rather than one.
A spring resting on its rod would do it, but the usual cause is the sketch: a test for LOW copied from an active-low sensor, or INPUT_PULLUP fighting the pull-down. If the LED is dark while the pin reads HIGH, it is not the block.
The spring has to swing far enough to reach the rod, and a board held loosely in a breadboard absorbs some of the knock. Fix the block firmly to what is being knocked, through its two mounting holes, and knock near it. There is no sensitivity adjustment on the board.
Run the first read from this book, which reads continuously and prints every pulse. If that prints when you knock, the block is fine and the fault is in the other sketch.
Forty-odd blocks. The TK17 collision sensor is this one's closest relative: the same circuit behind a lever.
Back to the blocks →Edit this page — content/books/knock-sensor/when-a-knock-does-nothing.mdx
Questions about this product
See what other owners have asked, and read their solutions.
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.