Thanks for all the suggestions
I take it that one end of the pipe is sealed?
No both ends are open. Like sciguy said, doing that would lower the pitch and we don't want that.
would an IR or ultrasonic distance finder work?
Yes, that would work but i'm doing this with all of my own parts and any new parts I have to buy. So doing that wold be too expensive.
why not just use a microphone to pick up the noise of the tube being hit?
Well that might work but I think it would be too unreliable because if the kids around it were making a lound noise, that might trigger it.