Faulty analog read output

Hello,

I am working on a thermoelectric module. The hot and cold sides of the device have a thermistor, which then have analog pickoffs to read their voltage with analogRead. Using manufacturer formulas I can then get temperatures and display them on a screen. This part works, and I am receiving reasonable values.

I also want to display output voltage of the thermoelectric unit on the screen, but the analogRead function seems to be faulty here. The values are random and nowhere near the actual value. I have copied the code to show what I did.

//Include library
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

//Define OLED dimensions
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

//Define constants
int R = 2200.; //Nominal resistance of fixed resistor
int Vs = 5.; //Supply voltage

//Assigning analog pins
int Analog0 = A0;
int Analog1 = A1;
int Analog2 = A2;

//Thermistor properties
int amphenolPropsBeta = 3435.; 
int amphenolPropsR0H = 10000.; //Nominal resistance of hot side thermistor
int amphenolPropsR0C = 11350.; //Nominal resistance of cold side thermistor
float amphenolPropsT0 = 298.15; //Room temperature in Kelvin

void setup() {
  //Declare inputs
  pinMode(Analog0,INPUT);
  pinMode(Analog1,INPUT);
  pinMode(Analog2,INPUT);

  Serial.begin(15200);

  if(!display.begin(SSD1306_SWITCHCAPVCC,0x3C)){
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);
  }
  delay(2000);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
}

void loop() {
  //Hot side temperature readings
  int readValue0 = analogRead(Analog0);
  float VT0 = (5./1023.)*readValue0;
  float I0 = (Vs-VT0)/R;
  float Rth0 = VT0/I0;
  float TT0 = 1./((1./amphenolPropsT0)+(log(Rth0/amphenolPropsR0H)/amphenolPropsBeta));
  float TC0 = TT0-273.15;
  float TF0 = TC0*9./5.+32.;

  //Cold side temperature readings
  int readValue1 = analogRead(Analog1);
  float VT1 = (5./1023.)*readValue1;
  float I1 = (Vs-VT1)/R;
  float Rth1 = VT1/I1;
  float TT1 = 1./((1./amphenolPropsT0)+(log(Rth1/amphenolPropsR0C)/amphenolPropsBeta));
  float TC1 = TT1-273.15;
  float TF1 = TC1*9./5.+32.;

  //Peltier output voltage readings
  int readValue2 = analogRead(Analog2);
  float VP = (5./1023.)*readValue2;

  display.clearDisplay(); 
  
  //Display hot side temprature
  display.setCursor(0,10);
  display.println((String)"Hot side: "+TF0+" F");
  display.display();

  //Display cold side temperature
  display.setCursor(0,20);
  display.println((String)"Cold side: "+TF1+" F");
  display.display();

  //Display peltier device output voltage
  display.setCursor(0,30);
  display.println((String)"Peltier: "+VP+" V");
  display.display();

  delay(500);
}

A handheld DMM measures the output voltage of the module to steadily sit at a value between 0.1 and 0.5V (depending on the temperature difference across the module), however the Arduino outputs randomly move around between 0 to 5V.

I will also provide schematic of how the voltage is read.

Can somebody explain why the values are like this?

No ground (-) connection to the Arduino ground (GND)

Thanks for following up.

I tried connecting the circuit to the Arduino ground like shown in the attached image. Now the output sits at a constant 5V, which is still incorrect. Did I hook it up correctly?

Probably not. The diagram is correct, except that you forgot to state the load resistor value.

Please post a link to the TEG module data sheet, and state the temperature difference across the TEG module, along with a voltage measurement.

The value of the resistor in the circuit shown in the image doesn't necessarily matter, since its only purpose is to avoid a short circuit. The analog connection is made before the voltage drop on the resistor anyways.

The "load resistor" described in the script is within the thermistor circuit, which simply calibrates the thermistors.

The following is a link to the TEG module (these are more commonly called Peltier devices). It is most similar to what I have.

That makes no sense.

The resistor depicted in the image is a 2.2k resistor. If this has an effect on the voltage read by A2, what should I add to the script to account for this?

this is Peltier-Element
grafik

Looks correct.
Try a different analog pin maybe A3

Impossible to say without knowing the temperature difference across the TEG device.

TEGs are better considered to be heat-flow-dependent current sources, rather than voltage sources.

Review Thevenin equivalent circuits to be reminded why, in order to characterize the TEG performance, it is important to measure both the open circuit voltage and short circuit current as a function of temperature difference. A multimeter is good for that.

Looks like I had the ground hooked up to the 5V splicing connector on accident which is why it read 5V. Hooked it up correctly and the values look a little low for what they should be, but they are more reasonable. Shows between 0.01 to 0.02V.

I had this same setup connected for MatLab (with the Arduino addon) and it reads about 0.53V at 40F temp difference. This is more consistent with the DMM readings. Even though that setup used a Nano (whereas this one uses an Uno) and the nominal resistance of the thermistors may have changed after excessive use, it is still far from what the IDE returns.

Overall however, connecting to Arduino ground seemed to fix the main problem. Thanks.

You might try increasing that resittor to 5K or more to give you a higher voltage but measure the voltage with a a DMM at the highest temperature differential just to make sure it's not over 5V

Re-soldered some stuff on the hat and replaced the DC-DC stepdown (which steps down a 12V supply to 5V for the Arduino to run separately from the computer) and suddenly everything works perfectly.

Thanks again.

Glad everything worked
Have a nice day!