Today I decided to try another schematic for measurement of the temperature this time with LM335Z low cost sensor.
LM335Z have 0V at absolute zero temperature i.e. -273.2C and it’s output increase with 10mV/C so at room temperature the sensor will output about 2.73V
to measure this temperature with Duinomite is piece of cake:
10 SETPIN 1,1 ’setup PIN(1) as analog input
20 PRINT “ROOM TEMPERATURE IS”;PIN(1)*100-273
the problem is that PIC32 Analog input can’t take more than 3.3V on it’s ADC, so maximal temperature measured will be 57C well this still is enough for some application, but why not measure the complete temperature range -40C+100C ? (if you use LM135 the range will be -55+150C)
to do this we have to add resistor ladder which to divide the output voltage, TassyJim uses 18K/27K in his project posted at TheBackShed forum, and I found his 0.6 round divider as nice so decided to use same values.
the schematic if used for industrial applications should have some protection diodes and resistors like on this picture:
but for the experiment I just used R1, R2, R3 and wired them to DuinoMite-Mini with jumper cables:
then I wrote this simple code:
10 SETPIN 1,1
20 PRINT “ROOM TEMPERATURE IS: “; PIN(1)*166.7-273
RUN
ROOM TEMPERATURE IS: 24.5645
it’s really not so hot in my office so I start thining what is wrong and I found it – I used 5% resistors as I had no preciese resistors so the voltage divider was not exactly 0.6 but something else and was mixing my result, no problem I took preciese ohm meter and measured R2 and R3 the values are:
R2 = 17 860 ohm
R3 = 26 600 ohm
aha so the voltage divider is 0.59829! and the coefficient I have to use in the formula is 100/0.59829 = 167.1
I corrected the formula:
20 PRINT “ROOM TEMPERATURE IS: “; PIN(1)*167.1-273
RUN
ROOM TEMPERATURE IS: 23.6145
so with not preciese resistors I got preciese result because DM-BASIC have no problems to work multiply real numbers
so the complete code to measure temperature in -40C+100C with LM335Z fits in one line
PRINT “ROOM TEMPERATURE IS: “; PIN(1)*167.1-273
For those who don’t know much electronics (so recognise resistors but not a lot else), please explain what the diode-like devices are and why each would be needed in an industrial (noisy) environment.
D1 is the sensor it may be connected with long cable which to pass through transformers, motors, high voltage cables etc which to inducted voltage in the cable and to be applied to the Analog input, these inducted noises can be as high as hundreds of volts for short period of time, and to damage the PIC processor
D2 is Zenner diode which do not allow inducted voltage to go over 5V
D3 and D4 protect Analog input if the voltage on this line go over 5.3 or under -0.3V these diodes will pass through to Vcc or ground
As 5V is not safe voltage for the ADC input R4 limits the input current to safe range
hope this explanation didn’t confused you further but this is very basic electronics and you can find a book and read more
This looks great. I’ll go put in these two extra resistors in and revise my formula. Thank you for the example. I can calculate every necessary step by myself now.
Does this mean that the value of R1 is not important to the formula?
R1 value is important of course but do not influence the temperature measurement formula directly
R1 value is to restrict the current through the sensor, it’s value depends on what voltage you will feed, in case of 5V 1.5K is OK
if you use too small value the current which flows through the sensor may heat it up and to bias the measurements, all this is described in the LM335 datasheet
The BAT54 schottky diodes in the schematic appear to be orientated to allow the use of a single BAT54S smd.
datasheet … http://www.nxp.com/documents/data_sheet/BAT54_SERIES.pdf
cool !