I'm currently developing a project using arduino duemilanove 328 and several sound sensor to detect the sound level of a particular place. I don't need it to be so accurate. I just want to know the place currently is quite or noisy, and is my sensor is working well or disconnected already. My problem is whenever I removing my sensor from the board, the analog input pin give me several noise value. I would like to set it to zero so that in case my sensor is malfunction, i'll know... Is there any suggestions??? or any recommended sound sensor??? Please lend me a hand...
What sensors do you have, please post a link or spec. data sheet.
It sounds like you are reading the floating voltage value. Try using something like a 10k resistor to pull the input either to +5v or ground so that it doesn't float. Your sensor circuit and associated code of course needs to be compatible with this arrangement.
emdee, thanks for your suggestion...it works quite well
Unlike with logic inputs you have to be careful with analog inputs not to load the sensor too much. Say you are expecting to read the sensor's output voltage to a 1-in-1024 accuracy (full theoretical precision of ADC). If the sensor has an output impedance of 1k ohm (not that unlikely) then you cannot add a 10k pull-down or pull-up resistor without introducing 10% error. 1Mohm would be the lower limit.
In practice you won't get 1 part in 1000 accuracy anyway, but a better way to reduce the noise is to use a high-value resistor and a capacitor on the analog pin. The capacitor will act as low-pass filter in combination with the sensor output impedance and may reduce noise from the sensor as well as when it's not connected.
Actually i don't need it to be so accurate, i just want to detect the presence of sound and the "dis-connnection" of my sensor. I'd tried with your method before but it is not what i want to... Anyway, thanks for your suggestion...