thermometer diode based

How build a simple thermometer using a silicon diode

Apr 15, 2017

19875 views

9 respects

Components and supplies

1

1N4148 – General Purpose Fast Switching

1

Arduino Mega 2560

Project description

Code

Diode thermometer based code

arduino

Load this code in your arduino and in the serial plot you can see the temperature read uy the diode

Diode thermometer based code

arduino

Load this code in your arduino and in the serial plot you can see the temperature read uy the diode

Downloadable files

electric scheme

The scheme is very simple: It is needed to connect the diode directly to the pins of the Arduino board: In particular connect the anode at the pin A0 and the catode at the GND pin

electric scheme

Comments

Only logged in users can leave comments

Anonymous user

2 years ago

I changed: - t0 to be a float - vf0 to be in Volts (since vf are also calculated in Volts) - ADC uses Internal 1.1 Voltage reference - more accurate ADC to voltage calculation (https://www.gammon.com.au/adc) - dtemp calculation with 2.2mV also in Volts `some code` `const int in = A0; // used to bias the diode anode` `const int nrOfReadings = 1024;` `const float InternalReferenceVoltage = 1.098; // as measured` `// measure diode forward voltage drop vf0 at temperature t0 and fill in the values here` `const float t0 = 25.0; // measured temperature (float in degrees Celcius) at diode forward voltage drop vf0` `const float vf0 = 0.6594; // measured diode forward voltage drop (float in Volt) at t0` `float dtemp, dtemp_avg, t;` `void setup() {` ` Serial.begin(115200);` ` pinMode(in, INPUT_PULLUP); // set the pin IN with npull up to bias the diode` ` analogReference (INTERNAL);` ` analogRead (A0); // force voltage reference to be turned on` `}` `void loop() {` ` dtemp_avg = 0;` ` for (int i = 0; i < nrOfReadings; i++) {` ` float vf = ((float) analogRead(in) + 0.5) / 1024.0 * InternalReferenceVoltage; // float voltage = ((float) rawADC + 0.5 ) / 1024.0 * Vref;` ` dtemp = (vf - vf0) / 0.0022; // with K = 1 / 2,2mV` ` dtemp_avg = dtemp_avg + dtemp;` ` }` ` t = t0 - dtemp_avg / nrOfReadings;` ` Serial.print("temperature in Celcius degree = " );` ` Serial.println(t);` ` delay (1000);` `}`

Anonymous user

2 years ago

how do you set vf0 = 573.44 ??

Anonymous user

2 years ago

can I use this code with Arduino Uno and I have 3 digit screen how can I connect it to Arduino and get temp. on it https://drive.google.com/file/d/1fc2i-8JfyVXhOASGPwvQrP22Ofg2XRXc/view?usp=sharing

Anonymous user

2 years ago

Wow! it's simple and works really well. But where did you get the 4976.30 value?

Anonymous user

2 years ago

@microsat - Good thinking. But probably the wrong move. Don't do that! Here's the thing, do you know how the microcontroller in your Arduino measures voltages? It compares them against a reference voltage. There is a pin called Aref on that chip that is supposed to be connected to an exact voltage. When you check the value of an analog input pin the number you are getting is the voltage on the pin expressed as a fraction of the voltage on the Aref pin. That Aref voltage doesn't have to be 5V. say for example you wanted a very precise measurement of a single 1.5V battery. You could put some smaller voltage on that Aref pin, something just slightly higher than the maximum voltage you ever expect to have to measure. Now the number that is returned is a fraction of that voltage instead of 5. In other words you are measuring in smaller increments. Now lets say you want a precision voltage meter. For that you you would supply the Aref pin with the output of a special precision voltage regulator so you could be sure you are always measuring against an exact voltage. Precision voltage regulators are an extra cost. 99.9% of Arduino users don't need that. Instead the Aref pin is usually just tied to the 5V rail. That same 5V rail that you measured as not being a true 5V. So, TLDR; Most Arduino tutorials will tell you that when you measure the voltage on a pin you are getting the value as a fraction of 5V but you are not. You are getting a fraction of whatever precise voltage is on the 5V rail. Since that rail is also the same one that supplies the input to the diode it's ok. The inaccuracy cancels out. By "correcting" for it you are adding it back in. Yeah, I know, reply to a stale post. It's still pretty high up there on a Google search though and useful to the next person that reads it.

microst

2 years ago

Hi jo107, this value is the measured value of the 5V supply. I measured the 5V rail and inserted the real value to make accurate the temperature evaluation. If you want, you can change this value with 5V or measure the 5V rail supply in your arduino board Thank for your comment

Anonymous user

2 years ago

Great, simple and practical, I applied to STM32 Blue Pill, greetings Petr

Anonymous user

3 years ago

Great, simple and practical, I applied to STM32 Blue Pill, greetings Petr

Anonymous user

4 years ago

how to make it can display to 16x2 LCD

Anonymous user

5 years ago

I changed: - t0 to be a float - vf0 to be in Volts (since vf are also calculated in Volts) - ADC uses Internal 1.1 Voltage reference - more accurate ADC to voltage calculation (https://www.gammon.com.au/adc) - dtemp calculation with 2.2mV also in Volts `some code` `const int in = A0; // used to bias the diode anode` `const int nrOfReadings = 1024;` `const float InternalReferenceVoltage = 1.098; // as measured` `// measure diode forward voltage drop vf0 at temperature t0 and fill in the values here` `const float t0 = 25.0; // measured temperature (float in degrees Celcius) at diode forward voltage drop vf0` `const float vf0 = 0.6594; // measured diode forward voltage drop (float in Volt) at t0` `float dtemp, dtemp_avg, t;` `void setup() {` ` Serial.begin(115200);` ` pinMode(in, INPUT_PULLUP); // set the pin IN with npull up to bias the diode` ` analogReference (INTERNAL);` ` analogRead (A0); // force voltage reference to be turned on` `}` `void loop() {` ` dtemp_avg = 0;` ` for (int i = 0; i < nrOfReadings; i++) {` ` float vf = ((float) analogRead(in) + 0.5) / 1024.0 * InternalReferenceVoltage; // float voltage = ((float) rawADC + 0.5 ) / 1024.0 * Vref;` ` dtemp = (vf - vf0) / 0.0022; // with K = 1 / 2,2mV` ` dtemp_avg = dtemp_avg + dtemp;` ` }` ` t = t0 - dtemp_avg / nrOfReadings;` ` Serial.print("temperature in Celcius degree = " );` ` Serial.println(t);` ` delay (1000);` `}`

Anonymous user

6 years ago

how do you set vf0 = 573.44 ??

Anonymous user

7 years ago

can I use this code with Arduino Uno and I have 3 digit screen how can I connect it to Arduino and get temp. on it https://drive.google.com/file/d/1fc2i-8JfyVXhOASGPwvQrP22Ofg2XRXc/view?usp=sharing

jo107

8 years ago

Wow! it's simple and works really well. But where did you get the 4976.30 value?

microst

2 years ago

Hi jo107, this value is the measured value of the 5V supply. I measured the 5V rail and inserted the real value to make accurate the temperature evaluation. If you want, you can change this value with 5V or measure the 5V rail supply in your arduino board Thank for your comment

Anonymous user

2 years ago

@microsat - Good thinking. But probably the wrong move. Don't do that! Here's the thing, do you know how the microcontroller in your Arduino measures voltages? It compares them against a reference voltage. There is a pin called Aref on that chip that is supposed to be connected to an exact voltage. When you check the value of an analog input pin the number you are getting is the voltage on the pin expressed as a fraction of the voltage on the Aref pin. That Aref voltage doesn't have to be 5V. say for example you wanted a very precise measurement of a single 1.5V battery. You could put some smaller voltage on that Aref pin, something just slightly higher than the maximum voltage you ever expect to have to measure. Now the number that is returned is a fraction of that voltage instead of 5. In other words you are measuring in smaller increments. Now lets say you want a precision voltage meter. For that you you would supply the Aref pin with the output of a special precision voltage regulator so you could be sure you are always measuring against an exact voltage. Precision voltage regulators are an extra cost. 99.9% of Arduino users don't need that. Instead the Aref pin is usually just tied to the 5V rail. That same 5V rail that you measured as not being a true 5V. So, TLDR; Most Arduino tutorials will tell you that when you measure the voltage on a pin you are getting the value as a fraction of 5V but you are not. You are getting a fraction of whatever precise voltage is on the 5V rail. Since that rail is also the same one that supplies the input to the diode it's ok. The inaccuracy cancels out. By "correcting" for it you are adding it back in. Yeah, I know, reply to a stale post. It's still pretty high up there on a Google search though and useful to the next person that reads it.