ADC1015 + NTC Thermistor 10k + TMP36

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ilijamt
 
Posts: 17
Joined: Mon Mar 10, 2014 7:06 am

ADC1015 + NTC Thermistor 10k + TMP36

Post by ilijamt »

Hi,

I need the following help using an ADC 1015.

I want to read the Thermistor with the ADC, but for some reason I can't seem to get it right.

If i connect it directly without the ADC I can read nearly identical temperature with the TMP36 component, but if I connect it through the ADC I get different results.

I use the TMP36 as a reference so I can compare how it is, if I'm reading correctly.

Even though when I tried reading it with a Digital Multimeter the voltage was 2.223 V

Also why do I get something on the other pins of the ADC, shouldn't they be 0, as nothing is connected to them?

Code: Select all

TMP36
0.78 volts
28.12 degrees C
82.62 degrees F

ADC 12bit Thermistor
755 ADC
1843.71 R
0.92 V
Temperature 68.62 *C

Get ADC Analog Lines
AIN0: 753
AIN1: 331
AIN2: 306
AIN3: 286
On the schematic you will see my wiring and the code bellow.

Code: Select all

#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1015 ads;

// resistance at 25 degrees C
#define THERMISTORNOMINAL 10000

// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25

// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3950

// the value of the 'other' resistor
#define SERIESRESISTOR 10000


const  double refVoltag = 5.0;
const  double adcMax = 4096.0;

void setup() {
  Serial.begin(57600);
  Serial.println();
  ads.begin();
}

void loop() {
  Serial.println();
  Serial.println("TMP36");

  uint16_t reading = analogRead(A0);

  // converting that reading to voltage, for 3.3v arduino use 3.3
  float voltage = reading * 5.0;
  voltage /= 1024.0;

  // print out the voltage
  Serial.print(voltage); Serial.println(" volts");

  // now print out the temperature
  float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
  //to degrees ((voltage - 500mV) times 100)
  Serial.print(temperatureC); Serial.println(" degrees C");

  // now convert to Fahrenheit
  float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  Serial.print(temperatureF); Serial.println(" degrees F");

  Serial.println();
  Serial.println("ADC 12bit Thermistor");

  uint16_t adcValue = ads.readADC_SingleEnded(0);
  Serial.print(adcValue);
  Serial.println(" ADC");

  double R = adcValue;
  R = (adcMax - 1) / R;
  R = 10000.0 / R;

  Serial.print(R);
  Serial.println(" R");

  double V = adcValue * 5 / (adcMax - 1) ;
  Serial.print(V);
  Serial.println(" V");

  float steinhart;
  steinhart = R / THERMISTORNOMINAL;     // (R/Ro)
  steinhart = log(steinhart);                  // ln(R/Ro)
  steinhart /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart = 1.0 / steinhart;                 // Invert
  steinhart -= 273.15;                         // convert to C

  Serial.print("Temperature ");
  Serial.print(steinhart);
  Serial.println(" *C");

  Serial.println();
  Serial.println();  
  Serial.println("Get ADC Analog Lines");
  int16_t adc0, adc1, adc2, adc3;

  adc0 = ads.readADC_SingleEnded(0);
  adc1 = ads.readADC_SingleEnded(1);
  adc2 = ads.readADC_SingleEnded(2);
  adc3 = ads.readADC_SingleEnded(3);
  Serial.print("AIN0: "); Serial.println(adc0);
  Serial.print("AIN1: "); Serial.println(adc1);
  Serial.print("AIN2: "); Serial.println(adc2);
  Serial.print("AIN3: "); Serial.println(adc3);
  Serial.println(" ");

  delay(5000);

}
Attachments
Schematic
Schematic
Untitled Sketch 2_bb.png (244.77 KiB) Viewed 629 times

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: ADC1015 + NTC Thermistor 10k + TMP36

Post by adafruit_support_bill »

Code: Select all

const  double adcMax = 4096.0;
The max scale for the ADC1015 is 2048. In differential mode, the output is a 12-bit signed integer in two's compliment binary. In single-ended mode, it is effectively an 11-bit unsigned integer.
Also why do I get something on the other pins of the ADC, shouldn't they be 0, as nothing is connected to them?
If nothing is connected, they are 'floating'. If you want them to be zero, you have to connect them to 0v (GND).

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: ADC1015 + NTC Thermistor 10k + TMP36

Post by adafruit_support_mike »

The ADS1015's default single-ended voltage range is +/-6.144v, so each LSB is 3mv.

If the ADC reads 755, the voltage is 755 * 3mV = 2.265v. You seem to be calculating the voltage some other way.

User avatar
ilijamt
 
Posts: 17
Joined: Mon Mar 10, 2014 7:06 am

Re: ADC1015 + NTC Thermistor 10k + TMP36

Post by ilijamt »

Yeah I forgot to multiply the ADC reading with 3mV.

The revised code is down, now I need to sort out the resistance it's not showing correctly.

How would I go about amplifying a range of temperatures let's say between 20 C and 50 C of a thermistor with 1% error?

Code: Select all

#include <Wire.h>
#include <Adafruit_ADS1015.h>

Adafruit_ADS1015 ads;

#define THERMISTORNOMINAL 10000
#define TEMPERATURENOMINAL 25
#define NUMSAMPLES 5
#define BCOEFFICIENT 3950
#define SERIESRESISTOR 10000

const double refMultiplier = 3.0 / 1000;
const double resistorFixed = 10000.0;
const double refVoltag = 5.0;
const double adcMax = 2 ^ 11;
const double arduinoAdcMax = 2 ^ 10;

void setup() {
  Serial.begin(57600);
  Serial.println();
  ads.begin();
}

void loop() {
  Serial.println();
  Serial.println("TMP36");

  uint16_t reading = analogRead(A0);
  char buff[10];

  float voltage = (reading * (double) refVoltag) / 1024.0;

  // print out the voltage
  Serial.print(voltage); Serial.println(" volts");

  float temperatureC = (voltage - 0.5) * 100 ;
  dtostrf(temperatureC, 1, 3, buff);  
  Serial.print(buff); Serial.println(" *C");

  Serial.println();
  Serial.println("ADC 12bit Thermistor");

  uint16_t adcValue = ads.readADC_SingleEnded(0);
  Serial.print(adcValue); Serial.println(" ADC");

  float V = adcValue * (float) refMultiplier;
  dtostrf(V, 1, 3, buff);
  Serial.print(buff); Serial.println(" V");

  float resistance =  (((float)refVoltag * (float)resistorFixed) / (float)V) - (float)resistorFixed;
  dtostrf(resistance, 1, 3, buff);
  Serial.print(buff); Serial.println( " R");

  float lnR = log((float)resistance);
  float kelvin = 1 / ( 0.001129148 + 0.000234125 * lnR + 0.0000000876741 * lnR * lnR * lnR);

  dtostrf(kelvin, 1, 3, buff);
  Serial.print(buff); Serial.println(" K");
  dtostrf(kelvin - 273.15, 1, 3, buff);
  Serial.print(buff); Serial.println(" *C [Steinhart Extended]");;

  float steinhart;
  steinhart = resistance / THERMISTORNOMINAL;     // (R/Ro)
  steinhart = log(steinhart);                  // ln(R/Ro)
  steinhart /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart = 1.0 / steinhart;                 // Invert
  steinhart -= 273.15;                         // convert to C

  dtostrf(steinhart, 1, 3, buff);
  Serial.print(buff);  Serial.println(" *C [Steinhart Simplified]");

  delay(5000);

}

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: ADC1015 + NTC Thermistor 10k + TMP36

Post by adafruit_support_mike »

The ADC has a built-in amplifier that can be set to a gain of 2/3, 1, 2, 4, 8, or 16.

Find the voltage your thermistor produces at 20C and create a voltage reference at that level. A DAC would probably be the easiest solution. Then connect the voltage reference to one ADC pin and the thermistor to another and take a differential reading at whatever gain you need.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”