One analog pin always showing "wrong" value Arduino Uno

Hi everyone,

I'm reading voltages on the 6 analog pins and 5 seem to be working fine. Pin A4 however, always gives me a higher voltage no matter what I connect to it. This is the same when I use a different Uno. I'm a little baffled by this and was wondering if anybody had this issue or knows what's going on?

My serial output:
12:55:41.777 -> 3.43
12:55:41.777 -> 3.41
12:55:41.777 -> 3.42
12:55:41.777 -> 3.41
12:55:41.777 -> 4.12
12:55:41.810 -> 3.42

My code:

/*

Setup of Arduino and SD card
* analog sensors on analog A0 to A5
 * SD card attached to SPI bus as follows:
 ** MOSI - pin 11
 ** MISO - pin 12
 ** SCK - pin 13
 ** CS - pin 4 
 ** power to 3.3, need to check output as USB doesn't provide enough power to run it. Gives error of particition not found if not enough juice
RTC
VCC to 5V
GND to GND
SDA to SDA
SCL to SCL
SQW unused

//  Thermistor connection
//    Vin (5V) --\/\thermistor\/\---- Vout to analog input pin
//                                 |
//                                  ---(\/\/\R2\/\/\)--- GND

//  For best results select R1 equal to the thermistor resistance
//    at the temperature being read (maximizes resolution of ADC)
//  (25k Ohm coresponds to ~6C)
// Thermistor: Thermistors, US Sensor PS103J2, 10K ohm 615-1003-ND Digikey
// Resistor: RESISTOR, 0.01% 25K; Resistance:25kohm; Resistance Tolerance:± 0.01% USR2-0808-25KT-ND Digikey

print_time() returns a string in the format mm-dd-yyyy hh:mm:ss
*/

#include <RTClib.h>
#include <SPI.h>
#include <SD.h>


//RTC_DS1307 rtc;



const int chipSelect = 4; // where SD CS is connected

File dataFile;

/*String print_time(DateTime timestamp) {
  char message[120];

  int Year = timestamp.year();
  int Month = timestamp.month();
  int Day = timestamp.day();
  int Hour = timestamp.hour();
  int Minute = timestamp.minute();
  int Second= timestamp.second();

  sprintf(message, "%d-%d-%d %02d:%02d:%02d", Month,Day,Year,Hour,Minute,Second);
  
  return message;
}*/

void setup(){
  Serial.begin(9600); // opens connection to arduino
  
pinMode(4, OUTPUT); // select pin for output, where CS is on SD card
  if (!SD.begin(4)){
    Serial.println("Error: SD card would not initiate.");
  } else {Serial.println("initialization done.");
  }

 /* Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.initialized()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
     rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }*/

  
  dataFile = SD.open("TMSt1.csv", FILE_WRITE); // makes file and read and writes
  
  if (dataFile) {
    Serial.println("writing to TMSt1.csv ");
  dataFile.println("Date, Time, TM1, TM2, TM3, TM4, TM5"); // writes header into file once, if reset pressed it will do it again at the end of the file before new reading begin
  dataFile.close(); // ensures that header is saved, always need to close file to save
  } else {
    Serial.println("TMSt1.csv didn't open ");
  }                                      
}

void loop(){    // as a loop it keeps reading and writing the values into file on sd card
  
  int sensorValue_A0 = analogRead(A0); //pin at which thermistor is connected (A1-A5)
  // convert analog to voltage
  float voltage_A0 = sensorValue_A0 * (5 / 1023.0); 
  int sensorValue_A1 = analogRead(A1); //pin at which thermistor is connected (A1-A5)
  // convert analog to voltage
  float voltage_A1 = sensorValue_A1 * (5 / 1023.0); 
  int sensorValue_A2 = analogRead(A2); //pin at which thermistor is connected (A1-A5)
  // convert analog to voltage
  float voltage_A2 = sensorValue_A2 * (5 / 1023.0); 
  int sensorValue_A3 = analogRead(A3); //pin at which thermistor is connected (A1-A5)
  // convert analog to voltage
  float voltage_A3 = sensorValue_A3 * (5 / 1023.0);
  int sensorValue_A4 = analogRead(A4); //pin at which thermistor is connected (A1-A5)
  // convert analog to voltage
  float voltage_A4 = sensorValue_A4 * (5 / 1023.0);
  int sensorValue_A5 = analogRead(A5); //pin at which thermistor is connected (A1-A5)
  // convert analog to voltage
  float voltage_A5 = sensorValue_A5 * (5 / 1023.0);

//DateTime now = rtc.now(); //gets current date and time from rtc
  
Serial.println(voltage_A0); // to check it's reading something and if it makes sense, need to check how to write all readings in one line
Serial.println(voltage_A1);
Serial.println(voltage_A2);
Serial.println(voltage_A3);
Serial.println(voltage_A4);
Serial.println(voltage_A5);
/*Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(") ");
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);*/
Serial.println();


 File dataFile = SD.open("TMSt1.csv", FILE_WRITE);
 if (dataFile){
  
 
  
  
 // dataFile.println(now); //write date and time reading in file
  //dataFile.println(","); //seperates voltage from date and time
  dataFile.print(voltage_A0); //writes voltage in file
  dataFile.println();
  dataFile.print(",");
  dataFile.print(voltage_A1); 
  dataFile.println();
  dataFile.print(",");
  dataFile.print(voltage_A2); 
  dataFile.print(","); 
  dataFile.print(voltage_A3);
  dataFile.print(",");
  dataFile.print(voltage_A4);
  dataFile.print(",");
  dataFile.println(voltage_A5); 
  dataFile.close();  //works perfectly now, write everything until println in same line
 }
 else{ Serial.println("couldn't open file");
 }
  delay(5000); //prints time and voltage every 5 seconds
}

no matter what I connect to it.

And, what are you showing us?

Are all of the analog inputs connected together to one temperature sensor, or do they have separate temperature sensor circuits?

Have you checked the voltage with a multimeter?

Each input has it's own temperature sensor.

How do I check the pin with a multimeter? I've tried different temperature sensors on the A4 pin and it always shows 4.12 when the same sensor showed 3.42 on a different pin.

Try and use one source for A4 and some other inputs. Short them together. Could be a sensor. Then make a run and report what You get.

How do I check the pin with a multimeter?

Measure the voltage between the analog pin and ground (the Arduino ground).

...I can't believe you have two Arduinos with the same defect. I'm assuming it's something different (maybe simply tolerances) in the attached sensor circuit giving a different reading.

If you do as Railroader suggests, short all of the analog inputs together and connect just one temperature sensor, they should all read the same (within one count plus maybe a little noise-variation). If that works your Arduino and software is OK.

padmoo:
I've tried different temperature sensors on the A4 pin...

You did ofcourse also check/swap the pull up resistor for that thermistor.
Leo..

Wonder what the effect of the RTC connected to SDA (A4) is?

JCA34F:
Wonder what the effect of the RTC connected to SDA (A4) is?

Duhh, good catch. Missed that.
The Arduino enables pull up on that pin, and the RTC module also has a pull up resistor.
Can't use A4, A5 for both functions.

OP might think the SDA/SCL pins close to the USB socket are different from A4, A5.
They are not (on an Uno). There is a straight connection between them.

Could use a Nano, with A6, A7 available (analogue pins only).
Leo..

Me thinken the same. :slight_smile:

It's a frequently made mistake, double use of the pins dedicated for USB or I2C...
Well done finding it out.

Wawa:
Duhh, good catch. Missed that.
The Arduino enables pull up on that pin, and the RTC module also has a pull up resistor.
Can't use A4, A5 for both functions.

OP might think the SDA/SCL pins close to the USB socket are different from A4, A5.
They are not (on an Uno). There is a straight connection between them.

Could use a Nano, with A6, A7 available (analog pins only).
Leo..

Wait what??!! With an RTC attached I can only use A0 to A3 on an Uno?
Just to be clear so I am not missunderstanding, my thermistors, each with an individual resistor circuit, are going into the analog in (A0-A5), my RTC is going into SCL, SDA on the digital input side.

That is the conflict? Any way of resolving that without buying a different board? Where is that mentioned in the Arduino Uno description??

Any recommendations which board to use with an RTC, an SC card module and my 6 thermistors (technically only 5, but I might need 6)?

Use digital one wire temperature sensors instead on thermistora, like DS18B20.

TheMemberFormerlyKnownAsAWOL:
Use digital one wire temperature sensors instead on thermistora, like DS18B20.

It's too late for this for me. My probes are already made with a different thermistor. But thank you for the tip!

padmoo:
Wait what??!! With an RTC attached I can only use A0 to A3 on an Uno?
Just to be clear so I am not missunderstanding, my thermistors, each with an individual resistor circuit, are going into the analog in (A0-A5), my RTC is going into SCL, SDA on the digital input side.

That is the conflict? Any way of resolving that without buying a different board? Where is that mentioned in the Arduino Uno description??

Any recommendations which board to use with an RTC, an SC card module and my 6 thermistors (technically only 5, but I might need 6)?

The Uno docs include the pin map that shows SDA and SCL as being analog pins. BTW, the analog pins are digital pins with ADC connections.

But how can you not know that your RTC is connected to A4? There's only 1 A4 pinhole.

You may try running the RTC on 2 other pins as "soft-wire". There may be a library. Or maybe find a serial or SPI RTC.

Port expanders is another option.
A 74HC4051 (74HC4067) turns each analogue input into 8 (16) analogue inputs.

A string of (waterproof) DS18B20 (one Arduino pin) is easier to use, has a higher temp resolution across a larger span, and is potentially more accurate than thermistors (that need calibration).

Not sure what you're measuring.
Could have used a WeMos D1 mini and 6 DS18B20 sensors, nothing else.
The ESP8266 on there can keep time and update it from the internet, and/or store timestamped temps in it's SPIFFS memory, and/or display it on it's own webpage, and/or post it on the web.
Maybe for your next project.
Leo..

GoForSmoke:
But how can you not know that your RTC is connected to A4? There's only 1 A4 pinhole.

Erm, because there is a pinhole for the SDA and SCL each, and one that says A4. I couldn't find the pin map and I'm pretty sure I would have not seen that A4 is connected to something else too as I'm pretty new to all this.

Would I be able to use the Mega with my setup?

Wawa:
Port expanders is another option.
A 74HC4051 (74HC4067) turns each analogue input into 8 (16) analogue inputs.

A string of (waterproof) DS18B20 (one Arduino pin) is easier to use, has a higher temp resolution across a larger span, and is potentially more accurate than thermistors (that need calibration).

Not sure what you're measuring.
Could have used a WeMos D1 mini and 6 DS18B20 sensors, nothing else.
The ESP8266 on there can keep time and update it from the internet, and/or store timestamped temps in it's SPIFFS memory, and/or display it on it's own webpage, and/or post it on the web.
Maybe for your next project.
Leo..

Thank Leo, I'll keep that in mind if I have to do this again. I've used the thermistors and resistors as they were recommended by somebody who has built these before and provided the calibration too. I didn't dare to "shop around" for other options as I wouldn't have known how to check them or make sure they are actually working right. I'm measuring temperatures from -20C to +10C in saltwater.
I'm encasing my whole thermistors strings in epoxy. Would that work with your recommendations too?

I look at my Uno R3 and the Arduino Uno page .... and they look the same.
https://store.arduino.cc/usa/arduino-uno-rev3

I see no pin labeled SDA or SCL there and only 1 hole for pin A4 and 1 for A5 that can also be used as SDA and SCL.

Perhaps your board is not an Uno?

Here's the ATmega328 (family which includes the 48, 88 and 168 which can all run in an Uno socket) pin map:

The red text shows which Board Pins relate to which Chip Pins (in black). Note that A4 and A5 can also serve as state change interrupts PCINT12 and PCINT13.

It should be possible to wire the RTC to 2 digital pins and use a library to access it. Then your A4 will be clear.

Hi,
Some UNO clones have extra pins on the end of 13 and Aref, labelled SLA and SCL.


Tom.. :slight_smile:

GoForSmoke:
I look at my Uno R3 and the Arduino Uno page .... and they look the same.
https://store.arduino.cc/usa/arduino-uno-rev3

I see no pin labeled SDA or SCL there and only 1 hole for pin A4 and 1 for A5 that can also be used as SDA and SCL.

Perhaps your board is not an Uno?

There are labels on the back:
a000066_back_1_1.jpg

a000066_back_1_1.jpg