Arduino locks up, powering down doesn't fix but serial monitor does

  if (analogRead( detect) == 0)

What, EXACTLY, is connected to this pin? Why doesn't the detect variable have pin in the name, to make it clear that it holds a pin number?

Why are you expecting an analog value of exactly 0?

 .
 .
 .
 etc

There is not a snowball's chance in hell that the code you posted will compile. Why are you wasting our time?