Piezo readings for 'secret knock' with electromagnetic lock don't seem correct

Hi, I'm am a very new user to Arduino, but since I have a background in C++ (ancient history) I got tasked with creating the secret door mechanism for my brother's new escape room. I cobbled some concepts together from about 4 different places, and ended up with a secret knock lock in addition to a wireless route to lock (and if necessary unlock) via a computer. The wireless has been working great, and I finally got the lock behaving properly, but last night I tried to incorporate the piezo, and it is not my friend. I had done the secret knock project that came in the starter kit book, so I thought I knew what I was expecting – wrong. The readings either come back with a constant stream of bad knock between 300-400 or higher (when nothing is going on in the room). I tried switching from A0 to A5 and now it will give me random readings which unlock the door all by itself. I’m afraid that I damaged the board or something. Has anyone seen this type of thing before?
Thanks for your help! Diane

const int piezo = A5;
const int LockPin=13;
int WirelessInput;
int knockVal;
const int quietKnock=500;
const int loudKnock=800;
boolean locked=false;
int numberOfKnocks=0;

void setup() {
Serial.begin(9600);
pinMode(LockPin, OUTPUT);
}

void loop() {
//check wireless
  if (Serial.available()>0) {
    WirelessInput = Serial.read();

    if(WirelessInput == 'U') {
      digitalWrite(LockPin, LOW);
      Serial.println("The door is unlocked!");
      locked=false;
    }
    if(WirelessInput == 'u') {
      digitalWrite(LockPin, LOW);
      Serial.println("The door is unlocked!");
      locked=false;
    }

    if(WirelessInput == 'L'){
      digitalWrite(LockPin, HIGH);
      Serial.println("The door is locked!");
      locked=true;
    }
    if(WirelessInput == 'l'){
      digitalWrite(LockPin, HIGH);
      Serial.println("The door is locked!");
      locked=true;
    }
  }

if(locked==true)
  {
  knockVal=analogRead(piezo);
  if(numberOfKnocks < 3 && knockVal > 0)
    {
    if(checkForKnock(knockVal)==true)
      {
      numberOfKnocks++;
      }
    Serial.print(3-numberOfKnocks);
    Serial.println(" more knocks to go");
    }
  if(numberOfKnocks>=3)
    {
    digitalWrite(LockPin, LOW);
    delay(20);
    Serial.println("The box is unlocked!");
    locked=false;
    numberOfKnocks=0;
    }
  }
}

boolean checkForKnock(int value){
if(value>quietKnock&&value<loudKnock)
  {
  Serial.print("Valid knock of value ");
  Serial.println(value);
  return true;
  }
else
  {
  Serial.print("Bad knock value ");
  Serial.println(value);
  return false;
  }
}

When something is not working, start with a simple test, test every part on its own, and combine everything when all the parts are working.

Use the Arduino (without XBee), connected to a computer (without the 12V battery and without the 9V battery). Connect a piezo and resistor to it.
Try to make that work.
To detect knocking and not sound, you could use the bare piezo disc and glue it onto something (for example wood).

Use another breadboard or remove everything else from it. Don't think that a few wires connected to something else will be okay. You have to start with something basic and simple and make small steps.

If that is working, add the XBee, and if that is working add the activator.

On this forum we say : Use the 9V batteries in a smoke detector but not for your Arduino.
A 9V battery is too weak.

Could you give a 'schematic' of your wiring. You could draw something on a piece of paper and make a photo of that.

Keep the high power activator always apart from the sensitive piezo. You can not use them on the same breadboard. The ground currents of the activator can make the piezo completely useless. If it is not the voltage shift, then it is the current noise of the activator that passes the piezo, since a piezo can behave as a capacitor.

Hi again,
So I did go back and took it all apart, testing as I went. I removed the 9-volt battery and the lock to see where I was. I discovered that the large readings only start occurring when the End Device starts receiving data wirelessly from the Coordinator. Any thoughts on that?

A schematics drawn by hand would be usefull. Can't be figured out from those pictures.