GHOST ON BOARD

My board keeps registering inputs from A0 even though there is no piezo element attached. Could it be that there’s a short circuit somewhere on the board because the Knock code registers knocks on the serial monitor even though there is no knock sensor attached. I modified the code a bit incorporating other elements and the board behaves the same way. HELP !

Here’s my modified “knock” code:

#include “pitches.h”
#include <LiquidCrystal.h>

const int ledPin = 13;
const int knockSensor = A0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int notes = { NOTE_A4, NOTE_B4, NOTE_C3 };

int ledState = LOW;

void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
lcd.begin(16, 2);
}

void loop() {
int sensorValue = analogRead(knockSensor);
int threshold = 500;
float voltage = sensorValue * (5.0 / 1023.0);
if (sensorValue >= threshold) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“ABOVE THRESHOLD!”);
lcd.setCursor(0,1);
lcd.print(voltage);
lcd.print(" volts");

tone(8, notes[sensorValue], 20);

ledState = !ledState;

digitalWrite(ledPin, ledState);
Serial.println(“MOTION DETECTED ABOVE THRESHOLD!!!”);
Serial.print(voltage);
Serial.print(" volts");
Serial.println();
}
else {
noTone(8);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“BELOW THRESHOLD!”);
lcd.setCursor(0,1);
lcd.print(voltage);
lcd.print(" volts");

Serial.println(“MOTION DETECTED BELOW THRESHOLD!!!”);
Serial.print(voltage);
Serial.print(" volts");
Serial.println();
}
delay(500);
}

HELP !!!

My board keeps registering inputs from A0 even though there is no piezo element attached.

And what if it is connected?

It's a common noob misconception that an unconnected input will read zero.

Thank you for your VALUABLE help.

I believe your board is possessed. Douse it in IPA and chant your favorite scripture at it.

Welcome to the concept of electrical noise and floating pins. If you want, just add a 1K resistor to ground from the pin while not in use and it will generally read 0.