Prevent random values (Sharp 2D120X)

Hi everyone.

I'm new here, so be kind to me :D

I'm currently programming a theremin on arduino, using a IR sensor Sharp 2D120X. My code is working just fine within the sensor's range, but when I'm out of the range, the sensor sends me random values (for example: when the closest object is the ceiling 2m away). The problem is that I use this sensor for the frequency. So whenever my hand is not in the sensor's range, I still have a random melody.

That apart, everything's working just fine.

Do you have any idea/solution to avoid this melody when I'm out of the range?

Try put the whole part of the code that makes the music, inside a test for the analog value being less than some threshold you choose, so that if it's too low (ie your hand is too far), do nothing. Something along those lines, anyway.

(Simple forum rules.... post code, post links to product info. (Not up to the reader to Google for a datasheet.))