Skip to content

Bug in "Detect a Knock" code #2159

Open
@Spiffer1

Description

@Spiffer1

The sketch for the "Detect a Knock" tutorial has a bug in it that limits the sensitivity of the knock sensor.

The code can be found at:
Home / Programming / Built-in Examples / Detect a Knock

The bug is on line 53 of the code snippet. The line delay(100); should be moved up a line so that it is inside the "if" block and immediately after the line Serial.println("Knock!");. In its current location, this delay() causes the code to wait a tenth of a second between looking for knocks. As a result many knocks vibrations (which are very brief) go undetected. As the comment on line 53 suggests, the purpose of the delay(100) line is to avoid overwhelming the serial port buffer, and thus the delay is only necessary when printing to the serial port.

When I relied on this code snippet to test a knock sensor in a prototype that I built years ago, it lead me to believe that this form of knock sensor was not very sensitive. I then made many modifications to my hardware to increase the sensitivity. In the end, none of those modifications were needed, since the real problem was the bug in this code snippet and not the hardware of the knock sensor itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcommunityBugs and fixes suggested by the communitymaker

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions