It's always nice to have a clear, digital readout of temperature, but for my latest project I am going all retro, and am building an analogue temperature indicator using a 0-5V voltmeter.

I'm having a blond moment and need some clarification on how I figure out the calibration formulae for the sensor I am using on my Arduino. Hoping someone can help!

So, I am going to use a DS18B20 temperature sensor, with my Arduino and a 0-5V analogue voltmeter. I am trying to work out the calibration factor. Here's my assumptions and calculations that I need some assistance on please...

The temperature sensor has a range of -55 to +125 °C and can be programmed to output a 9 bit through 12 bit resolution. I will use the 12 bit resolution, so -55°C = 0, 125°C = 4096.

-55°C - 0 and 125°C = 4095

The range of temperatures I want to display for my location on the analogue voltmeter (0-5V) is -5°C to +35°C and so I want to calibrate a Digital PWM out on my Arduino to output 0V when the temperature is -5°C, and 5V when the temperature is +35°C.

The range of the sensor is 180 degrees across 12 bits, and I want to use a range of 40 degrees which is

40/180*4096 = 910 bits of the 4096 bits in total, which is almost enough to use with the 10-bit range of the Arduino analogue input.

So, on the 0-4096 bits of temperature sensor output, I only want to use from bit 1365 to bit 1980 as my 0-1024 analogue input, then mapped to the 0-255 on the PWM 0-5V output.

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.Do not send technical questions via personal messaging - they will be ignored.I speak for myself, not Arduino.

(Interesting point: 24096 is an uncomfortably larger number than the number of fundamental particles in the observable universe)

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.Do not send technical questions via personal messaging - they will be ignored.I speak for myself, not Arduino.

Given earlier in my post I mentioned "-55°C - 0 and 125°C = 4095" - which suggests I am fully aware of the range of 12-bits. But thanks for pointing it out this minor indescretion which would yield in a 0.0244% error.

And surely you have more important and significantly less inane things to be getting on with?

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.Do not send technical questions via personal messaging - they will be ignored.I speak for myself, not Arduino.

PWM does not make analog voltage output. It makes pulses of VCC output.

You could probably wire an LM35 into a circuit that would give the VM 0-5V analog.

Sure, I am just playing around really in my efforts to learn coding and electronics etc, and the 0-5V analogue type meter I have does display PWM 0-5V output.

What I am wanting to do is simply read the relevant range of the the 12-bits of the sensor using the 10-bit anaolgue input of the Arduino, and then output that on one of the digital pins as a PWM 0-5V output.

This gives me the greatest accuracy in temperature readings on the scale of temperatures I want to read as instead of having the dial move in increments of 1°C, it will use the 0-255 across the entire -5 to +35 temp scale.

You need to map a range from the 12 bit DIGITAL input to the 8 bit PWM, not the 10 bit ADC.

Yep, I get that MAX VALUE thing, just didn't type it correctly.

However, what I don't get is that the Arduino input is not capable of reading the resolution of a 12-bit sensor, as it is only 10-bit, and in addition I only want to map a range of the temp sensors 0-4095 values to the full Arduino PWM 0-255, which will yield greater accuracy.

It's only the ADC which is ten bit, but with a twelve bit digital sensor, you're not using the ADC.

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.Do not send technical questions via personal messaging - they will be ignored.I speak for myself, not Arduino.

It's only the ADC which is ten bit, but with a twelve bit digital sensor, you're not using the ADC.

Ok, I understand that bit.

But... I still have to feed the output of the 12-bit sensor into the 10-bits of the Arduino analogue in, and what I want to try to do for greater accuracy in temperature measurement is to have the range of values of 1365 to 1980 from the temperature sensor mapped through to the full 0-255 PWM output - not the full 4096 values .

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.Do not send technical questions via personal messaging - they will be ignored.I speak for myself, not Arduino.