Go Down

Topic: temp conversion via analog input (Read 3418 times) previous topic - next topic


high guys, this is in relation to another post I made a couple weeks back about an electric radiator fan controller. being that i'm retarded lol i cant figure out how to convert the analog in to a true temp value because the higher the voltage the lower the temp and vise versa.

my pullup resistor is 300 ohms
using a temp sensor (12146312)  and in correlation to the data sheet,
5728ohms = 50 degrees F
155.6 ohms = 221 degrees F

4.75vdc at analog in = 50 degrees F
1.7vdc at analog in = 221 degrees F

any tips or tricks on how to accomplish this??? Thanks in advance.


Jan 07, 2018, 08:05 pm Last Edit: Jan 07, 2018, 08:28 pm by ieee488




ok... just verifying the formula

analogValue ie. 348 or 1.7vdc, yes?

348 * (5000/1024) =  1698  = millivoltValue

(1698 - 500) / 10 = 120c which would be 248F.   

This doesnt quite add up with what i have, based on my sensors data sheet and circuit. (its off by 27F)


so far its the closest thing that I've tried or found but 27F is a big difference in engine temp, especially when the engine is at operating temps or even a little higher.

the value of 348 I used as an example came from my voltage divider and the sensor data sheet.

I'm using 5vdc to a 300 ohm resistor (R1)  and per data sheet @ 221F the temp sensor (R2) is 155.6 ohms

just trying to give as much info as possible...


Jan 07, 2018, 09:29 pm Last Edit: Jan 07, 2018, 09:39 pm by LandonW
if I use 400 ohms for R2 (listed in data sheet as 167F) I get a analog input value of 585 or 2.86vdc

585 * (5000/1024)  2854.8

(2854.8 - 500) / 10 = 235.48C   which is alot more than the 167F in the data sheet

235C = 456F


cool, thank you, i'll try to replicate that and see what I get


Jan 08, 2018, 02:31 pm Last Edit: Jan 08, 2018, 03:28 pm by GolamMostafa
From the given two-point (A(500F, 4.75V) and B(2210F, 1.70V) responses of the sensor, we can find the following transfer function of the sensor:

T = 316.3114 - 56.0655VDT  //VDT = Sensor output as DC voltage at T0F

==> T = 316.3114 - 56.0655*(5/1024)*ADCT    //ADCT = ADC value at T0F. VREF for ADC is 5V.

==> T = 316.3114 - 56.0655*(5/1024)*analogRead(A1)  //Sensor signal is connected with Ch-1 of ADC

Serial.println(T, 2)  //temperature value will be printed with two digits after decimal point.


Thanks for the response... just so I can follow along, where did you get those numbers from? 316.3114 and 56.0655.
Also what is the sub DT stand for? And what does ADCT represent?

Like I said, I just want to have an understanding of how this works


Jan 08, 2018, 06:33 pm Last Edit: Jan 08, 2018, 07:13 pm by GolamMostafa
I would like to describe/explain the working principle of the Temperature Measurement Process with the help of the following diagram. I apologize for any inconvenience.

Figure-1: Tentative Hardware Block Diagram of Temperature Measurement System

1.  Your Temperature Sensor is given symbolic name TS, and it is connected to 5V supply via a 300 ohm (as you have said in your original post) resistor. According to data sheet of this sensor, it is a NTC (Negative Temperature Coefficient) type sensor.

2. According to your post, the TS provides:
(a) 4.75V when the Temperature is 500F ==> A(50, 4.75)
(b) 1.70V when the Temperature is 2210F ==> B(221, 1.70)
(c)  VDT when the Temperature is T0F ==> C(T, VDT)

(From where have you got these values? Have you measured these practically or got it from data sheets?)

3.  The DC voltage produced by TS is designated by the symbol VDT. Here, V stands for Voltage, D stands for DC Voltage, and T stands for T0F temperature. This means that the TS will produce a voltage VDT (0V to 5V) when the Engine Temperature is T0F.

4. The DC signal of the TS is sent to the Analog-to-Digital Converter (ADC) via Channel-1 (Ch1) of the ADC.

5. Based on the data of Step-2, we can draw the following response curve of TS:

Figure-2: Response curve of Temperature Sensor

6. Let us find the Equation for the ACB Line of Fig-2. It is of the form: y = mx +c.

(50 - 221) / (4.75 - 1.70) = (50 - T) / (4.75 - VDT)

Upon simplification, we will find:
T = 316.3114 - 56.0655*VDT

Validity Check of the above equation fo T:
With VDT = 4.75V:
T = 316.3114 - 56.0655*4.75 = 316.3114 - 266.3111 = 50.00020F (OK!)

With VDT = 1.70V:
T = 316.3114 - 56.0655*1.70 = 316.3114 -  90.3113 = 221.00000F (OK!)

7.  The DC signal of the TS sensor is sent to the Analog-to-Converter (ADC) Module via Channel-1(Ch1). The VDT is digitized by the ADC, and it produces an equivalent 10-bit binary value. Let us designate this binary value by the symbolic name ADCT (value of ADC when the Engine Temperature is T0F). There is a relationship between VDT and ADCT, and it is given by: VDT = (5/1024)*ADCT (Let us leave the derivation pending!). Using the value of VDT, we can re-write the Equation of T of Step-6 as follows:

T = 316.3114 - 56.0655*VDT
==> T = 316.3114 - 56.0655*(5/1024)*ADCT

The Arduino Command to read the ADC value (when the input signal is at Ch-1) is: analogRead(A1). Now, the Equation for T becomes as:

T = 316.3114 - 56.0655*(5/1024)*analogRead(A1)

8. Finally, the Arduino Coding:
Code: [Select]

void setup()
   Serial.begin(9600);    //Serial Monitor becomes active
   analogReference(DEFAULT);     //Vref for ADC is 5V

void loop()
   //T = 316.3114 - 56.0655*(5/1024)*analogRead(A1)
   float T;                 //T is declared as 32-bit floating point number
   T = 316.3114 - 56.0655*(5/1024)*analogRead(A1);    //read TS; convert to Temp and assign to T
   Serial.println(T, 2);    //show Temp on Serial Monitor in degree F with 2-digit after decimal point
   delay(3000);             //refresh temperature at 3-sec interval.

9. To show the temperature value on the 7-segment display unit of Fig-1, one may consult the documents of this link.


That was by far the one of the best answers I've ever gotten. Thank you. I'm currently at work, and I will apply this to my project when I get back to my project.  Karma points for you sir.

Hopefully I can post a fully operational project soon. Again, thank you.


Jan 08, 2018, 07:43 pm Last Edit: Jan 08, 2018, 07:43 pm by GolamMostafa
You are welcome! :)


ok, I got a library from adafruit for the 0.56" 7 segment LED HT16K33 and i'm using a pot for my temp sensor.   I'm getting a error code and I cant test the system.

this code is pretty much what came from adaFruit, I commented out the code I didn't think I would need.

Code: [Select]

#include <Adafruit_CircuitPlayground.h>

#include <Adafruit_GFX.h>
#include <Adafruit_SPITFT.h>
#include <Adafruit_SPITFT_Macros.h>
#include <gfxfont.h>

  This is a library for our I2C LED Backpacks

  Designed specifically to work with the Adafruit LED 7-Segment backpacks
  ----> http://www.adafruit.com/products/881
  ----> http://www.adafruit.com/products/880
  ----> http://www.adafruit.com/products/879
  ----> http://www.adafruit.com/products/878

  These displays use I2C to communicate, 2 pins are required to
  interface. There are multiple selectable I2C addresses. For backpacks
  with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks
  with 3 Address Select pins: 0x70 thru 0x77

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
byte tempSensor = A2;
const byte fanA = 7;
const byte fanB = 8;
int tempSensorVolts;
float tempValue;

#include <Wire.h> // Enable this line if using Arduino Uno, Mega, etc.
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"

Adafruit_7segment matrix = Adafruit_7segment();

void setup() {
#ifndef __AVR_ATtiny85__
  Serial.println("7 Segment Backpack Test");


void loop() {

 tempValue = 316.3114 - 56.0655 * (5/1024) * analogRead(tempSensorVolts);
  // try to print a number thats too long
  matrix.print(10000, DEC);

  // print a hex number
  matrix.print(0xBEEF, HEX);
  // print a floating point

  // print with print/println
  for (uint16_t counter = 0; counter < 9999; counter++) {

  // method #2 - draw each digit
  uint16_t blinkcounter = 0;
  boolean drawDots = false;
  for (uint16_t counter = 0; counter < 9999; counter ++) {
    matrix.writeDigitNum(0, (counter / 1000), drawDots);
    matrix.writeDigitNum(1, (counter / 100) % 10, drawDots);
    matrix.writeDigitNum(3, (counter / 10) % 10, drawDots);
    matrix.writeDigitNum(4, counter % 10, drawDots);
    if (blinkcounter < 500) {
      drawDots = false;
    } else if (blinkcounter < 1000) {
      drawDots = true;
    } else {
      blinkcounter = 0;
  if (tempValue > 195){
  if (tempValue > 215){
  else {

here is my error

Code: [Select]

Arduino: 1.8.1 (Windows 10), Board: "Arduino Pro or Pro Mini, ATmega328 (5V, 16 MHz)"

C:\Users\Landon\Desktop\CAR-duino\cooling_fans2\cooling_fans2.ino:37:34: fatal error: Adafruit_LEDBackpack.h: No such file or directory

 #include "Adafruit_LEDBackpack.h"


compilation terminated.

exit status 1
Error compiling for board Arduino Pro or Pro Mini.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

would you be able to help with this?

Go Up