ghost detector not working

BTW

for (int i = 0; i < NUMREADINGS; i++)
readings[i] = 0;

The array was cleared when you defined it.