Let's Make Robots!

ADC and strange readings

Hello guys,

I ran this sketch that would simply read an ADC port and print it out to my pc. It went just fine and results were pretty consistent, something like: 300 300 300 300 300 299 300 300 299 300 300 and so on....

But when I use Serial.print(analogRead(whatever_pin)); in a larger sketch, results are very different, something like: 300 290 305 288  310 315 306 296 and so on. This "larger" sketch has 3 interrupt service routines, and the hardware setup has 3 different chips and a loudspeaker.

I am not really sure why that happens. Is it software related (interrupt service routines ---> make the analogread lag?) or is it hardware related (lots of noise coming from chips ---> intereferes with readings)? Oh btw, i don't know if this really matter, but i am using pull up resistors on those pins (pinMode = input, digitalwrite = high) and i'm connecting "thing that gives the reading" between the ADC pin an GND.


Thank you!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The amplifiier doesn't like DC ditto. But again, I don't know if this is the cause for this problem.

Adding a .1uF cap in series with the speaker makes the readings way more stable but also makes the sound almost unhearable :=( This confirms the speaker is the big problem. Shall I try shielding it? I've seen some guys on google that use foam pads for that and get good results.

I have tested various combinations of 33uF, 47uF and 10uF capacitors in parallel (in parallel to each other, in series with the speaker) and it looks like 33uF gives the best results, much better than having no cap at all. Here's a comparison:

33uf cap: 228 228 228 229 229 231 229 229 234 234 229 230 228 229 237 228 223 239

no cap: 229 228 234 235 232 233 240 236 220 232 228 238 231 247 232 239

that's a significant difference!