電子工作77 – 冷蔵庫の冷蔵室と冷凍庫の温度を表示する温度計の製作
- Fridge Thermometer Capable
of Showing Cold-room and Freezer Temperatures -
概要
前の電子工作76で使った温度センサLM61BIZはプラスとマイナスの両方の温度領域の測定に適すので、これを2個使って冷蔵庫内の冷蔵室と冷凍庫の温度を液晶上に表示する温度計を製作した。
In this project, a fridge
thermometer capable of showing both cold-room and freezer temperatures on LCD
was made using two sensors LM61BIZ which can measure a temperature range from
–30 to +100 degree C with an accuracy of +/-3 degree C.
回路図
Circuit Diagram
下に回路図を示す。 前の電子工作76のものとほぼ同じである。ただ、今回はマイナスとプラス温度が測れる温度センサLM61BIZを2個使った。1個は冷蔵室に、もう1個は下の引き出し式の冷凍庫の中に設置して使う。
Following is the
circuit diagram of fridge thermoeter. The reference voltage used for the
in-built ADC of 16F819 is 2.50V, which is prepared from the power supply
voltage of 5.0V by using a voltage divider composed of two 10K resistors as
shown in the diagram. The connection between 16F819 and LCD is based on Manual
of PicBasic Pro. One sensor is set in the cold room while the other in the
freezer.
(Fig.1)
基板に各部品をハンダ付けしたもの。写真は冷蔵庫の冷凍庫の温度を示している。この冷凍庫の温度はー12℃くらいからー30℃近くまで変動するのが観察された。真中に18ピンの16F819が見える。基板の右端から2本のセンサ線が出ている。
The following photo shows the naked circuit board
onto which all necessary components are solded or connected. At the present,
the temperature in Freezer is –21.3 degrees C Considering the accuracy of this
sensor, it is appropriate to think that the real temperature is more likely to
exist around –21 degrees C. Sometimes this temperature drops as low as –30
degrees C.
(Photo 1)
上の基板を100円ショップのプラスチックケースに入れたもの左が冷蔵室、右が冷凍庫の温度で、交互に約3秒間隔で連続的に表示される。
The above circuit
board is housed in a plastic case (WxLxH = 12 x 15 x 5cm).
(Photo 2)
市販温度計との比較: 左が冷蔵室、右が冷凍庫の温度です。ともに割と差が小さいことが分かる
Comparison with a conventional thermometer (thermistor sensor): Differences between the two were less than 1 degree C.
(Photo 3)
温度センサLM61BIZは約50センチの長さのケーブルで基板本体に接続されている
Two temperature sensors (LM61BIZ) with a 50-cm long cable are shown above LCD.
(Photo 4)
結果&コメント
1) LM61BIZセンサを2個使ってプラスとマイナス温度を表示させることに成功した。+100℃前後(半田ごて)から-30℃(冷蔵庫の冷凍室)位までスムースに表示できた。
2) センサの精度や基準電圧の精度から表示温度の整数値2桁がほぼ正しい値と思われる。
3) 冷蔵庫の測定温度はほぼ中央で4−6℃位で安定、下の冷凍庫の温度は通常でも−12から−21℃などと結構ばらつくことが分かった。
4) 製作材料費は1500円ほど。液晶500円、センサ100円、16F819 220円、 ACアダプタ500円、三端子レギュレータ、基板、SWなど。
Results and
Comments
1) The completed
thermometer can measure a temperature range from –30 to +100 degrees C using
two temperature sensors LM61BIZ and the calculation formulas described in
Program.
2) Considering the
accuracy of the temperature sensors and reference voltage 2.50V, the first
two-digit integer value of displayed temperatures is the most likely
temperature value.
3) Temperature
values obtained with this fridge thermometer were not so different from those
obtained with a commercial thermometer (+/-1 to 2 degrees C).
4) Total cost of
components and other materials is about 1500 yen.
プログラム
前の電子工作76とほぼ同じプログラムであるが、温度センサを今回は2個に増やしたのでプログラムもその分追加されている。勿論要となる部分はプラス温度とマイナス温度を検知して分ける部分 If Vin=<246 then と、プラス温度の計算ではVin=(Vin*61)/25-600 を使い、マイナス温度の計算ではVin=600-(Vin*122)/50という式を使うことである。詳細は前回既述したのでここでは省略。
Program
In the use of LM61BIZ, there is the following
relationship between the sensor output Vo and the measuring temperature T: Vo
(mV) = 10*T (degree C) + 600. Therefore, if a sensor output is known, the corresponding
temperature can be calculated using this formula. Here, we use 2.50V as
reference voltage in this circuit. So, 2.50V corresponds to 1023 counts in
10-bit ADC (Analogue Digital Converter) of 16F819. It means that there is a
relationship between these two parameters - 0.00244V/count (=2.50V/1023counts)
= 2.44mV/count. In the program shown below, positive temperatures can be
calculated by the formula Vin=(Vin*61)/25-600. Here, Vin in (Vin*61) is the
number of counts converted from the sensor output (mV) by ADC of 16F819, while
61/25=122/50 is equal to 2.44mV/count. The total Vin in Vin=(Vin*61)/25-600 is
the voltage expressed in mV. For instance, at T=50 degrees C,
Vo=10*50+600=1100mV. 2500mV: 1023counts=1100mV: Xcount ->
Xcount=(1023*1100)/2500=450 counts that is equal to Vin in parentheses). The
total Vin=(450*61)/25-600=498 mV -> almost 500 mV. Using Lcdout
"Temp=",Dec1 Vin DIG 2,Dec1 Vin DIG 1,".", DEC1 Vin DIG
0,"C", the temperature 50.0 C (degrees C) is extracted from this 500
mV. The reason why 61/25 instead of 122/50 in Vin=(Vin*61)/25-600 is used is
based on the fact the total of Vin*122 exceeds 65535 (at high temperatures)
that is the maximum figure allowable in PicBasic Pro used this time. In fact,
if 122 are used, strange temperatures begin to appear on LCD, in the range
above about 70 degrees C. Using 61 instead of 122 allows a smooth temperature
increase up to at least 100 degrees C (proved using a soldering iron).
Meanwhile, negative temperatures can be calculated by Vin=600-(Vin*122)/50 (or
Vin=600-(Vin*61)/25). The result is displayed on LCD using Lcdout
"Temp=","-", Dec1 Vin DIG 2,Dec1 Vin DIG 1,".",
DEC1 Vin DIG 0,"C". For instance, at T= –20 degrees C, the sensor
output is Vo=10*(-20)+600=400mV. The number of counts corresponding to 400mV is
400mV/(2500mV/1023)=163 that is Vin in parentheses. Therefore, the total
Vin=600-(163*122)/50=600-398=202mV. If extracted using the above extraction
pattern, the temperature - 20.2C will be displayed on LCD. Finally, positive
and negative temperatures are handled separately with the different routines.
For that purpose, ‘If Vin=<246 then’plays the important role. Here, 246 is
the count number correspondng to the sensor output of 600mV or a temperature of
0 degree C. It is calculated as follows: 600mV/(2500mV/1023counts)=246.
'****************************************************************
'Name of program: LCDtempLm61BIZ16F819AFr.bas - 2014.11.29 worked OK
'Using Picbasic Pro V2.50A and 16F819
'Two LM61BIZ sensors are used to measure temperatures in cold room and freezer in fridge.
'As Vref+, used is 2.50V which is made by a voltage divider using two 10K Rs and connected to AN3 (RA3)
'**New LCD connection setting** See p.88 in PBP Manual
DEFINE LCD_DREG PORTB 'Set LCD Data port
DEFINE LCD_DBIT 4 'Set starting Data bit, (0 or 4) if 4-bit bus
DEFINE LCD_RSREG PORTB 'Set LCD Register Select port
DEFINE LCD_RSBIT 1 'Set LCD Register Select bit
DEFINE LCD_EREG PORTB 'Set LCD Enable port
DEFINE LCD_EBIT 0 'Set LCD Enable bit
DEFINE LCD_BITS 4 'Set LCD bus size (4 or 8 bits)
DEFINE LCD_LINES 2 'Set number of lines on LCD
DEFINE LCD_COMMANDUS 2000 'Set command delay time in us
DEFINE LCD_DATAUS 50 'Set data delay time in us
'**Setting for ADC of 16F819**
Define ADC_BITS 10 '10-bit ADC used
Define ADC_CLOCK 3 'Internal clock used
Define ADC_SAMPLEUS 50 'Sample timing
OSCCON=%01110100 'Internal OSC setting to 8MHz
ADCON1=%10000001 'Right adjusted, AN3 - Vref+
TRISA=%00101111 'RA3 - Vref+, PortA.0, 1, 2, 3 and 5 - analog input
TRISB=%00000000 'All PortBs are output
Samples var word 'Samples
Sample var byte 'Sample
Vin var Word 'Vin is variable
Ch var byte 'Ch is channel
Temp2loop:
'---Inside fridge temp routine---
Vin=0
Sample=0
Samples=0
ADCON0=%10000101 'for ADC setting of Sensor 1 (AN0)
Ch=0
For Sample=1 to 10 'Take 10 samples
ADCIN Ch, Vin 'Read ADC ch-0 and save in Vin, Range 0-1023
Samples=Samples + Vin
Pause 200 'Wait for LCD to startup, Seems to be appropriate.
Next sample
Vin=Samples/10 'Mean of 10 Vin values
If Vin=<246 then '0C - +600mV 600mV/(2500mV/1023)=246 counts(steps)
Goto NegativeTempFridge
Endif
Vin=(Vin*61)/25-600 'For positive temperatures, 61/25=122/50=244/100=2.44(mV/count)
Lcdout $fe, 1 'Clear LCD
Lcdout $fe, 2, "In Fridge"
LCDOUT $FE,$C0 'Jump to second line
Lcdout "Temp=",Dec1 Vin DIG 2,Dec1 Vin DIG 1,".", DEC1 Vin DIG 0,"C"
Pause 3000
Goto Freezer
NegativeTempFridge:
Vin=600-(Vin*122)/50 'Vin=600-(Vin*61)/25 can be used too.
Lcdout $fe, 1 'Clear LCD
Lcdout $fe, 2, "In Fridge" 'Here, Fridge means cold room.
LCDOUT $FE,$C0 'Jump to second line
Lcdout "Temp=","-", Dec1 Vin DIG 2,Dec1 Vin DIG 1,".", DEC1 Vin DIG 0,"C"
Pause 3000
'---Inside freezer temp routine---
Freezer:
Vin=0
Sample=0
Samples=0
ADCON0=%10001101 'for ADC setting of Sensor 2 (AN1)
Ch=1
For Sample=1 to 10 'Take 10 samples
ADCIN Ch, Vin 'Read ADC ch-0 and save in Vin, Range 0-1023
Samples=Samples + Vin
Pause 200 'Wait for LCD to startup, Seems to be appropriate.
Next sample
Vin=Samples/10 'Mean of 10 Vin values
If Vin=<246 then '0C - +600mV 600mV/(2500mV/1023)=246 counts(steps)
Goto NegativeTempFreezer
Endif
Vin=(Vin*61)/25-600 'For positive temperatures, 61/25=122/50=244/100=2.44(mV/count)
Lcdout $fe, 1 'Clear LCD
Lcdout $fe, 2, "In Freezer"
LCDOUT $FE,$C0 'Jump to second line
Lcdout "Temp=",Dec1 Vin DIG 2,Dec1 Vin DIG 1,".", DEC1 Vin DIG 0,"C"
Pause 3000
Goto Temp2loop
NegativeTempFreezer:
Vin=600-(Vin*122)/50 'Vin=600-(Vin*61)/25 can be used too.
Lcdout $fe, 1 'Clear LCD
Lcdout $fe, 2, "In Freezer"
LCDOUT $FE,$C0 'Jump to second line
Lcdout "Temp=","-", Dec1 Vin DIG 2,Dec1 Vin DIG 1,".", DEC1 Vin DIG 0,"C"
Pause 3000
Goto Temp2loop
'Note: melabs U2 Programmer's configuration for 16F819 (2014.10.1)
'FOSC-INTRC(INTIO2), WDTE-Enable, PWRTE-Enable, MCLRE-Reset,
'BODEN-Enable, LVP-Disable, CCP Multi With-RB2,
'Flash Pogram Meory Write Enable-All,
'Code-Not Protected, Data EEPROM-Not Protected
'**************************************************