Need help with 22k etc to Arduino. - Page 1
Forum section: electronics / beginners

author: MBN65
author_rank: Newbie
timestamp: June 30, 2023, 03:38:06 pm
content: I have searched all over and can't find any good parameters for reading a 22k ntc to Arduino.I'm using a 22k resistor as "R1", 5V from Arduino.Any suggestions?

author: mariush
author_rank: Super Contributor
timestamp: June 30, 2023, 03:46:49 pm
content: It's a plain resistor that changes value as it heats up.So for example, you could use the ADC functionality of your arduino and place your NTC in series with a known value resistor between voltage and ground, and now you can measure the voltage between the resistors.You know what voltage to expect, because you know your input voltage and the other resistor you can calculate what resistance the NTC had to get the voltage your measure with your ADC pin.Alternatively you use a current source (something that outputs a fixed amount of current, like for example a led driver IC, and you measure the voltage drop between the ntc pins with your arduino (and potentially you may need to amplify that voltage drop using an opamp)

author: RoGeorge
author_rank: Super Contributor
timestamp: June 30, 2023, 03:48:42 pm
content: If you know the thermistor model, download the datasheet and/or the application notes that tells the correspondence between the thermistor's R and the temperature.

author: MBN65
author_rank: Newbie
timestamp: June 30, 2023, 05:25:34 pm
content: I don't know the exact model, but naive as I am, I guessing they are all the same ( within their specs: 4.7k, 10k. 22k. 100k), maby I'm wrong.I have found a lot of examples for 100k NTC but none for 22k.I have modified code for a 100KNTC by trail end error and the following code seems to work good at 25 degrees C:R2 = R1 * (1166.8 / (float)Vo - 1.0); // R1* xxxx, higer value = lower templogR2 = log(R2);T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));Tc = T - 273.15;The original code is:R2 = R1 * (1023.0 / (float)Vo - 1.0); // R1* xxxx, higer value = lower templogR2 = log(R2);T = (1.0 / (c1 + c2 * logR2 + c3 * logR2 * logR2 * logR2));Tc = T - 273.15;I have changed the "R2 = R1 * (1023.0 .." to "R2 = R1 * (1166.8 .." .And this seems to work at 25 degrees C, but I wonder if this is correct.Anyone having a working code for 22k NTC?

author: mariush
author_rank: Super Contributor
timestamp: June 30, 2023, 06:29:46 pm
content: They're not all the same.It's enough to download a bunch of datasheets from Digikey or mouser or newark/farnell or whoever for various 22kohm NTCs and you'll notice differences between them.Also, if you change the resistor, may make sense to change the other resistor in the voltage divider or what you use, to optimize your calculations.Instead of doing so many floating point calculations you could maybe keep it to integers, divisions by 2, shifting bits left and right etc.

author: porter
author_rank: Regular Contributor
timestamp: June 30, 2023, 07:37:43 pm
content: It looks like the 1023.0 is the resolution of the ADC which is constant.I'm looking at this examplehttps://www.circuitbasics.com/arduino-thermistor-temperature-sensor-tutorial/I think the coefficients c1,c2,c3 are derived from this calculatorhttps://www.thinksrs.com/downloads/programs/therm%20calc/ntccalibrator/ntccalculator.htmlI entered values from this tablehttps://www.mouser.com/datasheet/2/418/8/ENG_DS_Series_I_Thermistor_100K6A1_A-2940504.pdfinto the calculator at -40,25,125 degrees c. It showed similar coefficients (I think A = c1 ,B = c2,C =c3)So I found table for a 22k NTC thermistor here:https://www.eaton.com/content/dam/eaton/products/electronic-components/resources/data-sheet/eaton-nrse-epoxy-sealed-radial-lead-ntc-thermistor-data-sheet-elx1227.pdfI plugged values into the tableResults are in the image.Maybe somebody will correct me. Thanks.

author: Infraviolet
author_rank: Super Contributor
timestamp: June 30, 2023, 09:15:14 pm
content: Magnus, just to check, did you wire the NTC resistor as part of a potential divider with a fixed resistor as the other part, or are you trying to measure it alone? Show a schematic perhaps? I don't know if you're new to electronics, or not, so my apologies if I'm pointing out something you've already dealt with, but remember, an analog input on a microcontroller just measures a voltage, and to easily get a varying resistot to give a varying voltage you need to wire it up as part of a potential divider. If you have an ohm-meter setting on a mutimeter to hand, check that your temperature sensitive resistor works by seeing how resistance varies when you place it in hotter or cooler environments, if you have reasoably accurate measurements of those temperatures you can use the ohm-meter readings at several different temperatures to reconstruct a temperature versus resistance curve or linear function, then you can use that to calibrate your future readings.

author: mariush
author_rank: Super Contributor
timestamp: June 30, 2023, 09:36:11 pm
content: Eh, you could just use 1024 instead of 1023 .... ffs, you're using an arduino, relying on input voltage as reference voltage, which could drift anywhere between 4.9v and 5.1v at the very least. You don't have an exact 5.0000v input voltage, so you don't get exactly 4.9mV per step or whatever you think. You also don't have a 0.1% resistor in the voltage divider to be so precise.R2 = R1 * (1023.0 / (float)Vo - 1.0);If Vo is 0, don't you get division by 0 error if your ADC reads 0?you could doint R1 = 10000; // or whatever value the resistor has.int v = analogRead(ThermistorPin)+1; // 1...1024float R2 = (R1 * (1024-v)) / v; // do whatever force conversions to float to get the result if neededIf your reading is 1023, then v = 1024 , so (1024-v) is 0, and the formula stops thereIf your reading is 0 , then v = 1 so R2 = 1023 R1 / 1 = 1023 R1because v is int (1..1024), you have only one multiplication between two integers and one division that results in a float.Whatever small error you get can be easily calibrated out.Also instead of all those logarithms you could use the beta1/ T = 1 / T0 + (1 / B ) * ln(R/R0) whereT0 = 25c in Kelvin (298.15)B = coefficient of thermistorR0 is nominal resistance of NTC at 25c (or whatever is advertised)So for example take this 22k NTC that's stocked in 100k pieces at Digikey :https://www.digikey.com/en/products/detail/vishay-beyschlag-draloric-bc-components/NTCS0402E3223HMT/1245346It's 22kohm at 25c , beta of 3590K ... so if the resistance measured is 8770.63 for example, then you can put it in formula :1 / T = 1 / T0 + (1 / B) * ln (R/R0)(T0 * B ) / T = B + T0 * (1) * ln (R/R0)=> T = T0 * B / ( B + T0 * ln(R/R0) ) = 298.15 * 3590 / ( 3590 + 298.15 * ln(8770.63 / 22000) )T = (298.15 * 3590) / (( 3590 + 298.15 * ln (0.398665 ) )= 298.15*3590 / ( 3590 + 298.15 * -0.919633 )= 298.15 * 3590 / 3,315.81 = 322.8 Kelvin or 49.65Cand if you go tohttps://www.vishay.com/en/thermistors/ntc-rt-calculator/and enter the ntc part number : NTCS0402E3223HMTYou'll find at 50c this row ... so we're close enough :50 8770.638226.2 9315.0 6.21 1.81 -3.43The same page also gives you the steinhart & hart coefficients should you want to use them : -13.14237876 4210.13465566 -50179.49398787 -10972255.57018070

author: MBN65
author_rank: Newbie
timestamp: July 01, 2023, 12:53:59 pm
content: You guy's are gold!I will look into your answers, it might take some time since I'm not so good att the math..Thank's a lot!