Arduino thermistor — analog PIN to temperature?

Hello,

I'm currently working on building a thermometer with the Arduino. However, I can't get the correct readings. I'm using a voltage divider. On one side, a thermistor is connected to A0 and 3.3V, and then a 1000 ohm resistor is connected to A0 and GND. I have an Arduino UNO R3 and an MF52D3950 thermistor. What's wrong with my code? The resistance of the thermistor (R2 in the code) should be around 9200 ohms, but it's always between 118 and 120. What's wrong with this? I've been working on this for 5 hours. So PLEASE help me.

Thank you in advance!

LG

 // www.elegoo.com //2016.12.9 #include <math.h> #include <LiquidCrystal.h> // BS E D4 D5 D6 D7 LiquidCrystal lcd(7, 8, 9, 10, 11, 12); void setup() { Serial.begin(9600); } // This is OK int analogPin= 0; int raw= 0; int Vin= 3.3; //volts input float Vout= 0; // unknown voltage, we have to measure float R2= 0; // Unknown resistance, we have to measure float T1 = 26 + 273.15; //reference temperature float R1 = 9040; //reference resistance float T2 = 0; //searched temperature float B = 3950; //B value resistor float R_REF = 1000; //reference resistor Spannungsteiler Wert void loop() { raw = analogRead(analogPin); //liest BIT-Wert für Spannung aus, welcher zum feststellen der Temperatur nötig ist Vout= (raw * 5)/(1024.0); R2 = R_REF / ((Vin / Vout) - 1); T2 = (B*T1*(-1))/(T1*log(R1/R2)-B)-273.15; //berechnet Temperatur Serial.print("raw:"); Serial.println(raw); Serial.print("Vout:"); Serial.println(Vout); Serial.print("R2:"); Serial.println(R2); Serial.print("T2:"); Serial.println(T2); }
1 vote, average: 1.00 out of 1 (1 rating, 1 votes, rated)
You need to be a registered member to rate this.
Loading...
Subscribe
Notify of
4 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
RareDevil
1 year ago

int Vin= 3.3; //volts input

int are integers, there are no commas… Just use mV, ie 3300 or 5000, then you don't need to take into consideration a comma.

Vout= (raw * 5)/(1024.0);

Parts by 1023, value0 corresponds to 0V at the AnalgoRead. The remaining values ​​are only 1023 to which the voltage is divided… And of course, 3300mV if you run your circuit to 3.3V…

What values ​​does Your analogue spit?

RareDevil
1 year ago
Reply to  RareDevil
 R2 = R_REF / ((Vin / Vout) - 1);

It can't fit… You want to know how much your value is from the thermistor, then you have to count it a little different…

 R2=R_REF/Vout*(Vin-Vout);
Bushmills145
1 year ago

They want to measure Vout, but do they expect it instead? Where does the 5 come from, I thought you'd go to 3.3 V? the 1024 corresponds to a 10 bit ADC resolution, or where does it come from? So yes, floats can often, almost always be avoided if you are multiplying for scaling, and then only divide.

Without wanting to dive into it now, I would choose this approach:

// Voltage via R, the 1k resistor behaves over both

// Resistances, 3.3V, like 1k resistance to the sum of both resistances:

Ur / Utot = R/Rtot

// so it is dissolved after Ur:

Ur = R*Utot/Rtot

// and thus Uth, voltage above the thermistor, equal

Uth = Utot-Ur

for control I set the values ​​0, 1000 and infinite for resistance of the thermistors:

Rth Ur = R*Utot/Rtot Uth

0 3300/1000 3.3-3.3-> 0V

1000 3300/2000 3.3-1.65 -> 1.65V

infinity 3300/infinite 3.3-0 –> 3.3V

Now instead of using Volt milliVolt for calculation, and you don't need any floats anymore.

I put this in a program. The actual calculation can be found on the line starting with ": R1". At the top, what I'm expecting is, and under it, only the control output on the right. The main thing for you should be the way up, the rest is more to confirm that this also works:

iEdik
1 year ago

Hello,

also..your NTC should have 10KOhm at 25°C

data sheet:

https://www.gotronic.fr/pj2-mf52type-1554.pdf

why do you use only 1K resistance for voltage dividers and why only 3.3V?

the arduino also has 5V tolerant pins…so…10Cohm on and to the 5V.

then try this code here:

https://www.circuitbasics.com/arduino-thermistor-temperature-sensor-tutorial/

Maybe you'll get on with it.

I myself have more PT100 or PT1000 than analogue sensors..But this requires a Wheatstone measuring bridge. It's more complex than just a simple voltage divider.