Inconsistent analogRead when a short delay is used between reads

I’m working on a project to make a spare smoke detector alert me via text or email if the alarm goes off. I’m a typical run of the mill home smoke detector made by First Alert. I’m basically using an analog pin to read if there is voltage going to the piezo buzzer which of course would have voltage if it the alarm is sounding. As with most home smoke detector the buzzer goes on and off when beeping so I have the spark core reading the analog pin every half second or so. Unfortunately if I make it read the pin that often I start to get erratic readings and false positives. If I make it read less often I don’t seem to have the problem. Is there some kind of problem reading an analog pin over and over with quick intervals? thanks

Do you have some data for us to review?

Just wondering how huge a difference the values are over fast interval and slower ones

@naterackers, what is the maximum voltage you are trying to read and how fast are you sampling?

The max voltage coming from the smoke detector would be 3 volts. If I read at 300ms intervals it seems like I can expect at least 6-10 times in 8 hours that it will think it reads a voltage (false positive). The longer my interval is the less issues I seem to have with false positives but I wonder if that is only because I’m not reading as often. The false positives my be happening anyway. I’m curious why there is any voltage at all when the alarm is not sounding. I’d expect it to always read 0 until the alarm sounds.

Do the different values correlate with the times the smoke detector flashes the LED? Most of these devices are very cheaply made and I could see that happening.

If the alarm is piezo electric element and not a speaker, you should know that they work “in reverse” too, as a generator. If you take a piezo element and give it a mechanical shock even from a loud audio sound, it will generate a voltage. This is actually how those trigger lighters make a spark: when you pull back on the trigger, a spring and lever mechanism strikes a piezo that generates a high voltage spark.

If you have a photoelectric type (not a radioactive ionization type) you might be better off just using the photocell directly.

Well I actually removed the piezo and am just hooking to its terminals to measure voltage. So what you are saying is that some devices are made cheaply and its possible that the voltage doesn’t stay steady and it may periodically be sending some to the piezo terminals as other things are happening on the board (like a led flashing)

1 Like

Or the piezo itself could be generating voltage because of sound in the environment. If you read out data from the piezo and then clap or play loud music, does the value increase?

well the piezo itself is removed. I"m reading voltage from the terminals it was connected to.

@naterackers, if you have one, I would put an oscilloscope on the piezo drive signal. It may not be what you expect!