1

I am puzzled. I just connected 3.3 V input to the Analog pin A5 of the Arduino UNO. On the script, I am reading all the input pins. Surprizingly, all the pins are giving voltage as that of A5 pin. This made me think whether all of them shorted?

code:

int a0_analogPin = A0; 
float a0_val = 0; 
int a1_analogPin = A1; 
float a1_val = 0;
int a2_analogPin = A2; 
float a2_val = 0;
int a3_analogPin = A3; 
float a3_val = 0; 
int a4_analogPin = A4; 
float a4_val = 0; 
int a5_analogPin = A5; 
float a5_val = 0; 

void setup() {
  Serial.begin(9600);           //  setup serial
  pinMode(a0_analogPin,INPUT);
  pinMode(a1_analogPin,INPUT);
  pinMode(a2_analogPin,INPUT);
  pinMode(a3_analogPin,INPUT);
  pinMode(a4_analogPin,INPUT);
  pinMode(a5_analogPin,INPUT);  
  Serial.println("A0_val,A1_val,A2_val,A3_val,A4_val,A5_val");
}

void loop() {
  a0_val = analogRead(a0_analogPin)*5.0/1023.0;  // read the input pin
  Serial.print(a0_val);          // debug value
  Serial.print(",");
  a1_val = analogRead(a1_analogPin)*5.0/1023.0;  // read the input pin
  Serial.print(a1_val);  
  Serial.print(",");
  a2_val = analogRead(a2_analogPin)*5.0/1023.0;  // read the input pin
  Serial.print(a2_val);  
  Serial.print(",");
  a3_val = analogRead(a3_analogPin)*5.0/1023.0;  // read the input pin
  Serial.print(a3_val);      
  Serial.print(",");
  a4_val = analogRead(a4_analogPin)*5.0/1023.0;  // read the input pin
  Serial.print(a4_val);    
  Serial.print(",");
  a5_val = analogRead(a5_analogPin)*5.0/1023.0;  // read the input pin
  Serial.println(a5_val);        
}

Board: enter image description here

Serial Monitor: enter image description here

3
  • you set all analog pins as digital inputs
    – jsotola
    Jul 18, 2023 at 17:23
  • 1
    @jsotola, analogRead configures the pin for ADC. Mainland, unconnected pins act like an antenna
    – Juraj
    Jul 18, 2023 at 17:40
  • @Juraj The problem is solved after I connected remaining to the ground. Thanks
    – Mainland
    Jul 18, 2023 at 17:41

2 Answers 2

2

Most of your analog pins are not connected to anything. In electrical engineering, that's called "floating". It means they have no reference to anything and thus their value can be anything.

Basically their value is determined by static electricity. Moving your hands near the pins or moving them away may be enough to change the value you read.

It could be that your "oscilloscope view" actually shows that nicely. One pin gets the voltage immediately (value 6) and through static electricity, the other pins slowly take that value as well (value 1, value 2, ...). Probably the steepest curve of those is closest to the pin that is high and the most shallow curve is furthest away. Your observations may vary depending on humidity and temperature, since that makes static electricity spread faster or slower.

Solution: don't let your pins float. Connect them to a defined value, e.g. ground if you want them to have a predictable value.

2

You are seeing crosstalk between the analog input channels. In the datasheet of the microcontroller you can see the analog input circuitry. See the capacitor labeled “CS/H”? This is the “sample and hold” capacitor. Its job is to hold the voltage being read while the ADC performs the conversion. When you measure channel A5, you are charging this capacitor to 3.3 V. Then, when you switch to a floating input, the capacitor has no path to discharge, and you end up measuring the same voltage.

Actually, you do not measure exactly the same voltage. The reason is that each input pin has a parasitic capacitance. When you switch from A5 to A0, the charge in CS/H splits between this capacitor and the stray capacitance of the pin A0. Then, you switch to A1 and the remaining charge is split between CS/H and the stray capacitance of A1, and so on. Eventually, when you come back to A5, you charge again CS/H to the full 3.3 V and the cycle starts again. The net effect is that you are progressively moving charges between the successive pins. This is why the curves look like exponential relaxations, where each successive pin charges more slowly than the preceding one.

The solution, as already written in other answers, is to avoid leaving the pin floating. The datasheet recommends making sure the connected source has an impedance no larger than 10 kΩ.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.