Is my Arduino ADC broken?!

I've been struggeling for days trying to interface a QRB1134 sensor trying to get a wheel encoder to work. I kept getting extremely fluctuating (random?) readings no matter what I did.

It never occured to me that it might be my Arduino that was broken. But I'm afraid that is the case now. I tried connecting something as simple as a potmeter (1K to 100K) to the ADC according to this setup.

And even now I'm getting the extreme fluctuations. I ran this little program:

void setup() {
  Serial.begin(9600);
}

void loop() {
  int val = analogRead(0); 
  Serial.println(val);
  delay(500);
}

What I get in the serial monitor is like this:

726
631
526
471
275
305
441
0
728
71
139
0
727
620
548
322
410
528
727
634
556
219
0
727
638
561
334
574
219
0
727
631
600
70
141
0
726
621
0
727
626
548
709
835
529
464
731
0
728
71
137
0
725
890
666
219
0

As you can see it jumps around more than it should. The readings do change when I turn the potmeter but as it is the readings are useless.

Hope to hear from someone who know about these things :(

That code looks like you have not grounded your potentiometer. If you do not ground it then it will not work. Are you sure that the the pins are connected to everything properly. You need to connect 5v to one pin and gnd to the opposite pin, then connect your analog read pin to the centre.

If it still fluctuates then are you sure you are reading from the right pin?

Your arduino will not be broken, human error will be the cause...

Mowcius

These numbers sure look like it was floating due to lack of grounding, but I'm sure that it was grounded and that I was reading from the right pin, because I checked it several times.

However I tried it again and now it WORKS properly (?). It seems that my breadboard is causing loose connections, which may also explain atleast SOME of the inconsistencies I've been experiencing when interfacing the QRB1134 sensor. Sometimes the readings are extremely noisy and other times COMPLETELY off (like floating).

But it doesn't seem like it was a missing ground connection on the pot. If I remove the ground from the pot I get these readings:

1017
1021
1015
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1022
1023
1023
1023
1023
1021
1023
1023
1023
1023
1023
1019
1023
1015
1021
1022
1023
1023
1016
1023
1023
1023
1017
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1023
1021
1020
1023

That is (close to) max readings no matter how I turn the pot.

The strange thing is though that the first time I connected the pot (and turned it to its max) I got readings like this:

1023
0
1023
0
1023
0
1023
0
..etc..

Then I reconnected it and got the readings I posted before.

Anyway sorry if I have bothered you unnecessarily and thanks a lot for the reply :)

The area of the optimum response approximates a circle .200” in diameter.

Firstly, outside this areas I may expect the values to be 'floating' for the sensor.

Have you used a pot not on a breadboard? Or is it just the sensor that you used on the breadboard

If you connect a wire directly from the sensor pin to ground do you get 0, also if you connect a wire directly from 5v to the sensor pin do you get 1023? This would be the first thing I would check...

Mowcius

I only used the pot on a breadboard and I'm currently trying out the sensor circuit on a breadboard. I also tried a soldered circuit but I went back to breadboard so I can experiment with different resistor sizes etc. In fact I bought the pot today to use it to replace the pullup resistor of the sensor circuit in an attempt to tune in on the optimal value.

This is the circuit I'm using:

And I've been testing for HOURS using different sensors, resistor values, caps, distances etc etc.. At NO time did I get a clean HIGH reading. It always fluctuates between 0V and the HIGH value and for some reason it likes to rest on ~1V quite frequently.

Here is an example of what is supposed to be HIGH readings:

And here is an example of corresponding LOW readings (fluctuating between 0V and ~1V and also resting on ~1V):

And note: these are some of the CLEANEST readings I've gotten so far :S

If you connect a wire directly from the sensor pin to ground do you get 0

I don't understand what you mean by that?

if you connect a wire directly from 5v to the sensor pin do you get 1023?

Yes!

If you connect a wire directly from the sensor pin to ground do you get 0

I don't understand what you mean by that?

Opposite of the 5v, just plug a wire from the analog pin to ground...

Ah off course ... sorry I'm tired after several hours of testing and stuff ...

But yes I did it and yes I got 0...

Ok. It sound like the ADC on board is perfectly fine then. If there are no fluctuations when doing that then it looks good...

Have you tried using a bigger cap to smooth the values from the sensor?

Mowcius

Yes I’ve tried several caps between 0.1uF and 100uF. It doesn’t do anything about the fluctuations it only slows down the transitions.

It really is odd. When I block the sensor completely I’m supposed to get all HIGH readings but instead get something like this:

1023
0
1023
0
999
0
1011
0
…etc…

And then suddenly I get:

220
220
220
220
…etc…

Until it drops back to the previous pattern. If you look at the scope screenshots you’ll notice that is the plateau where it sometimes rests in between the HIGH and 0 readings.

The low readings ALSO frequently rest on that exact same number: 220. It doesn’t make any sense. :-/

Ok, I suggest that you ignore the fluctuations and do an average read from the sensor.

How fast is the change in sensing. If it is just whether something is by it or not then you could do an average over half a second (or less).

Because of the values you are getting, doing an average should still set them apart...

or maybe you could use the max function or constrain to ignore specific values...

Mowcius

Lose the capacitor altogether, increase the phototransistor side resistor to 100K or even above. Take the wheel out of the equation, Use a piece of tinfoil as a reflector and alternate the sensor looking at open space and the piece of tinfoil, does the signal switch from high to low when its looking at the tinfoil ?

I also tried without a cap and I tried a pullup resistor up to 100K (the max of the pot) which gave me readings like this no matter what I did with the sensor:

That is: 0 1023 0 1023 0 1023 0 1023 etc.

I've also been playing with different ways of averaging the values out both by simply saving the readings in an array and calculating the average when the array is full as well as by using this smoothing filter (which I also built into my homemade software scope). In both cases it takes too long to get some smooth data. If the application had been simple line following or something it might have been useful but since it is a wheel encoder it needs to detect transition pretty fast. The ideal would be to use external interrupts actually.

A better (faster) way I thought of is to simply discard ALL zero values. That takes care of the worst fluctuations however not this tendency to rest on 220 for longer periods as I mentioned before.

Besides I don't think it's supposed to be THIS problematic. I think there is something wrong with my sensors (now that I've ruled out that the ADC is broken). For instance another guy who's trying something similar using a QRD1114 (seemingly identical to the QRB1134) gets readings like this:

The spikes being HIGH readings. Not a perfect squarewave either but infinately better than mine. And he didn't even use a cap.

However I'll try the tin foil later and I also bought a 74HC14 Schmitt trigger today which I'll try to integrate into the circuit. But 1st I'm gonna get some sleep.

Anyway thanks a lot for the input guys ;)

The sensor is two halves (just two seperate components in a common plastic housing), the LED half can be 'tested' by looking at it through a digital camera or mobile phone camera, you'll be able to see it lit up as they are sensitive to Infra Red.

You can test the phototransistor half by pointing a good bright light into it and seeing if the voltage moves (They are invariably sensitive to some of the visible spectrum).

OMG IT'S WORKING :/

At this point I have no idea what was wrong before though because I started all from scratch again...that is rewrote the code and rewired the circuit on a different part of my breadboard using different resistors and mostly different jumper wires. So now I'm getting beatyful HIGH/LOW readings:

At some point I will try to find out what was wrong before but right now I'm more interested in seeing what I can do with these readings. :P

Thanks for your help and patience and sorry if I've wasted your time unnecessarily. If it makes you feel better it's nothing compared to the hours I've wasted myself probably because of some silly noob mistake :/

OMG IT'S WORKING :/

At this point I have no idea what was wrong before though because I started all from scratch again...that is rewrote the code and rewired the circuit on a different part of my breadboard using different resistors and mostly different jumper wires. So now I'm getting beatyful HIGH/LOW readings:

IMG

At some point I will try to find out what was wrong before but right now I'm more interested in seeing what I can do with these readings. Tongue

Thanks for your help and patience and sorry if I've wasted your time unnecessarily. If it makes you feel better it's nothing compared to the hours I've wasted myself probably because of some silly noob mistake :/

Well just glad it's working for you :D

Mowcius