Sensor Input from Analog Pin Possible Coupling?

Hi everyone,

I'm having an issue where my input pin is influencing another input pin. When A0's signal decreases, so does A2 when A2 should be staying constant. The values of the two pins should be independent of each other. Even when there is no signal going to A2, it still shows a substantial reading. It seems like there is a clear influence of the A0 pin on A2. Any thoughts why?

I have a circuit below:

with the one tweak that the lower LED is not receiving voltage, ie that branch is not connected to the circuit.

with the code:
int PhotoPin1=0; // the number of the Phototransistor pin (Analog: intensity)

int PhotoPin2=2; // the number of the Phototransistor pin (Analog: intensity)

int w_sensorRaw1;
int w_sensorRaw2;
int w_sensorRawA;

void setup()
{
Serial.begin(9600);
//powered waveguide
pinMode(PhotoPin1, INPUT);
//unpowered waveguide
pinMode(PhotoPin2, INPUT);
// pinMode(LEDPin1, OUTPUT);
//pinMode(LEDPin2, OUTPUT);
// analogWrite(LEDPin1, 255);
//analogWrite(LEDPin2, 245);
}

void loop()
{
delay(10);
//dummy reading
analogRead(PhotoPin1);
//real reading
w_sensorRaw1=analogRead(PhotoPin1);
//allow the A/D reader to switch
delay(10);
//dummy reading
analogRead(PhotoPin2);
//real reading
w_sensorRaw2=analogRead(PhotoPin2);

//print powered waveguide value
Serial.print("Powered Waveguide = ");
Serial.println(w_sensorRaw1);
// Serial.print(", ");
//print unpowered waveguide value
Serial.print("Unpowered Waveguide = ");
Serial.println(w_sensorRaw2);

delay(1500);

}

A very common issue. Probably your signal’s output impedance is quite high, so the ADC doesn’t charge fast enough when switching to another input (the chip uses a single ADC that gets connected to the respective pins when needed).

Solution: read the pin twice, discarding the first value (i.e. just use two analogRead() calls). That allows the ADC to charge to the new voltage. The second reading will be correct.

wvmarle:
Solution: read the pin twice, discarding the first value (i.e. just use two analogRead() calls). That allows the ADC to charge to the new voltage. The second reading will be correct.

The OP is doing that…see snip below. But since the first call is not being used (assigned to a variable), the compiler may discard it.

void loop()
{
   delay(10);
   //dummy reading
   analogRead(PhotoPin1);
   //real reading
   w_sensorRaw1=analogRead(PhotoPin1);
   //allow the A/D reader to switch
   delay(10);
   //dummy reading
   analogRead(PhotoPin2);
   //real reading
   w_sensorRaw2=analogRead(PhotoPin2);

I don't think it is the code, I stored the dummy reading and am still having issues. I think it has to do with the circuit, somehow it is coupled, anyone have an idea how to decouple the inputs or why they might be coupled?

As explained in #1.
Too high output impedance of whatever is connected to the pin (recommended is <10kΩ)

So you think changing the resistors from 3M to <10K would work? I’m confused because the readings are not the same, they are a couple hundred off, they just both decrease when the one decreases, they don’t read the same value.

What resistors?
3M is way too high for an analog input.

Circuit attached. Ok I’ll have to check on the resistors then

circuit (1).png

That are phototransistors?

Check the data sheet of them, it can very well be that they need a 3M resistor for a proper signal, and that 10k is simply too low (it of course WILL affect your voltage range, as it's a voltage divider). In this case you will need to buffer the signal (usually through an OpAmp at unity gain) instead.

Please use code tags when posting code. Image is broken in post as well.

You need to either decrease the load resistors on the phototransistors to something reasonable, and possibly add a 10 nF cap from the analog input to ground, or use a buffer amplifier.

If this an extremely low light situation that requires 3 MEG load resistors, you definitely need the amplifier. And part or all of the problem might be stray light.