Hi, I'm working on an IR phototransistor and some other devices that need to be read by analogRead from an Arduino Nano.
I started a thread previously for some problem with the phototransistor that you can see here , anyway the phototransistor is now connected to ground with a 680k ohm resistance to get some decent results.
If I read it alone, when nothing else is being read, the readings are correct (from 0 to 900~), but if I read some other device connected to the Arduino on the same cycle, it reads wrong values.
I searched a bit and even in this forum I find some threads that address this behavior. I read that the ADC in the Arduino is one multiplexed for all analog inputs and that the previous reading can affect the next one.
The only solutions were
a) do multiple readings and keep the last one (I need 3 readings to get back to the correct one)
b) wait some time before reading
Is there a solution beside these? I read something about a capacitor but no solution were given in the threads
EDIT: Here are some more explanations, the code and some attachments.
With a 680k pull-up, you are going to require some settling time for the ADC given the recommended input impedance is around 10k.
A capacitor - try a 100 nF - is one approach but you realise it will slow the response of the phototransistor. Just realise that you will not be able to respond to fast changes however you do it. The other option is to use an op-amp in a current-to-voltage buffering mode.
Here is a schematic. I hope it is readable.
The phototransistor's Collector and the IR LED anode are connected to 5v.
The phototransistor's Emitter is directly connected to an analog pin and to Ground through the 680K ohm resistance. Also the IR LED catode is connected to Ground.
Why have you drawn a photo resistor when you say it is a photo transistor or is it a photo diode.
Anyway the resistor is way too high to be read directly, you need either a delay between selecting the channel with the multiplexer and reading it or have an emitter follower or Darlington arrangement before the analogue input.
IR LEDs can normally take a lot more continuous current than a 220R will allow, so you could probably drop that to 90R to get more light.
Grumpy_Mike:
Why have you drawn a photo resistor when you say it is a photo transistor or is it a photo diode.
Anyway the resistor is way too high to be read directly, you need either a delay between selecting the channel with the multiplexer and reading it or have an emitter follower or Darlington arrangement before the analogue input.
IR LEDs can normally take a lot more continuous current than a 220R will allow, so you could probably drop that to 90R to get more light.
I drawn a photoresistor because the Fritzing software didn't have (or I didn't find) a phototransistor.
Some days ago I actually forgot to put a resistor at all on the IR LED and it was working. I soldered a 220 ohm as I noticed, but I think I'll go lower to 90 then
I have connected one analog pin to ground, say A0. I then put the analog signal to be read on A1. I do a read of A0 to bleed off the past 'charge' then do a read on A1.
It may be worth your while to do a read on the grounded pin. store what value was read on the grounded pin. Read the analog signal and subtract the grounded pin reading from the read signal. Worked well for me.