Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in "Detect a Knock" code #2159

Open
Spiffer1 opened this issue Sep 11, 2024 · 0 comments
Open

Bug in "Detect a Knock" code #2159

Spiffer1 opened this issue Sep 11, 2024 · 0 comments
Labels
bug Something isn't working community Bugs and fixes suggested by the community maker

Comments

@Spiffer1
Copy link

Spiffer1 commented Sep 11, 2024

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.

@per1234 per1234 added bug Something isn't working community Bugs and fixes suggested by the community maker labels Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community Bugs and fixes suggested by the community maker
Projects
None yet
Development

No branches or pull requests

2 participants