Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug in "Detect a Knock" code #2159

Open
Open
Labels
bugSomething isn't working communityBugs and fixes suggested by the community maker
@Spiffer1

Description

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 working communityBugs and fixes suggested by the community maker

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /