空調関係の仕事をしている私は、いつかは仕事で電子工作を活かすことを夢見ながら、貴重な余暇を電子工作にあてています。
とりあえず、第一歩として温度測定にarduinoを使いたくって、小数点一桁を表示する温度計を作っていたのですが、思わぬところでつまずいていました。
「
#arduino 温度計新バージョン」の方式だと実際、気温を計る目的にもかかわらず自然に存在しない温度まで測定することになる割には温度の精度が低いというジレンマに囚われていました。
徹夜明けでボーとしているときに思いもよらぬひらめきがあり、analogReference(INTERNAL)を使用することにより解決することが出来ました。
また、ここには苦肉の策があります。
写真で見ることができるかな? 120kΩのカーボン抵抗が必要だったのですが、私が在庫していたのは最大で30kΩ、結局これを4つ連結して120kΩにしています。
今度、買いに行かなきゃ。
あと、温度表示を安定させるために33μFの電解コンデンサをつけました。
最後の仕上げに補正が必要です。
#include <LiquidCrystal.h>
//温度データ ×10です。
int data[]={3444,2760,2425,2212,2058,1939,1843,1763,1695,1635,1583,1536,1494,1456,1421,1389,1359,1331,1305,1281,1258,1236,1216,1197,1178,1161,1144,1128,1113,1098,1084,1071,1058,1045,1033,1022,1010,999,989,979,969,959,950,940,932,923,915,906,898,890,883,875,868,861,854,847,841,834,828,821,815,809,803,798,792,786,781,775,770,765,760,755,750,745,740,735,731,726,722,717,713,709,704,700,696,692,688,684,680,676,672,669,665,661,658,654,651,647,644,640,637,634,630,627,624,621,617,614,611,608,605,602,599,596,594,591,588,585,582,580,577,574,571,569,566,564,561,559,556,554,551,549,546,544,541,539,537,534,532,530,527,525,523,521,519,516,514,512,510,508,506,504,502,500,498,496,493,492,490,488,486,484,482,480,478,476,474,472,471,469,467,465,463,462,460,458,456,455,453,451,449,448,446,444,443,441,439,438,436,435,433,431,430,428,427,425,424,422,421,419,418,416,415,413,412,410,409,407,406,404,403,402,400,399,397,396,395,393,392,391,389,388,386,385,384,383,381,380,379,377,376,375,373,372,371,370,368,367,366,365,364,362,361,360,359,358,356,355,354,353,352,350,349,348,347,346,345,344,342,341,340,339,338,337,336,335,334,333,331,330,329,328,327,326,325,324,323,322,321,320,319,318,317,316,315,314,313,312,311,310,309,308,307,306,305,304,303,302,301,300,299,298,297,296,295,294,293,293,292,291,290,289,288,287,286,285,284,283,283,282,281,280,279,278,277,276,276,275,274,273,272,271,270,270,269,268,267,266,265,265,264,263,262,261,260,260,259,258,257,256,256,255,254,253,252,252,251,250,249,248,248,247,246,245,245,244,243,242,242,241,240,239,239,238,237,236,236,235,234,233,233,232,231,230,230,229,228,228,227,226,225,225,224,223,223,222,221,221,220,219,218,218,217,216,216,215,214,214,213,212,212,211,210,210,209,208,208,207,206,206,205,204,204,203,202,202,201,200,200,199,199,198,197,197,196,195,195,194,193,193,192,192,191,190,190,189,188,188,187,187,186,185,185,184,184,183,182,182,181,181,180,179,179,178,178,177,176,176,175,175,174,174,173,172,172,171,171,170,170,169,168,168,167,167,166,166,165,164,164,163,163,162,162,161,161,160,159,159,158,158,157,157,156,156,155,155,154,154,153,152,152,151,151,150,150,149,149,148,148,147,147,146,146,145,145,144,144,143,143,142,142,141,140,140,139,139,138,138,137,137,136,136,135,135,134,134,133,133,132,132,132,131,131,130,130,129,129,128,128,127,127,126,126,125,125,124,124,123,123,122,122,121,121,120,120,120,119,119,118,118,117,117,116,116,115,115,114,114,113,113,113,112,112,111,111,110,110,109,109,109,108,108,107,107,106,106,105,105,104,104,104,103,103,102,102,101,101,101,100,100,99,99,98,98,98,97,97,96,96,95,95,95,94,94,93,93,92,92,92,91,91,90,90,89,89,89,88,88,87,87,87,86,86,85,85,84,84,84,83,83,82,82,82,81,81,80,80,80,79,79,78,78,78,77,77,76,76,76,75,75,74,74,74,73,73,72,72,72,71,71,71,70,70,69,69,69,68,68,67,67,67,66,66,66,65,65,64,64,64,63,63,63,62,62,61,61,61,60,60,60,59,59,58,58,58,57,57,57,56,56,55,55,55,54,54,54,53,53,53,52,52,51,51,51,50,50,50,49,49,49,48,48,47,47,47,46,46,46,45,45,45,44,44,44,43,43,43,42,42,42,41,41,40,40,40,39,39,39,38,38,38,37,37,37,36,36,36,35,35,35,34,34,34,33,33,33,32,32,32,31,31,31,30,30,30,29,29,29,28,28,28,27,27,27,26,26,26,25,25,25,24,24,24,23,23,23,22,22,22,21,21,21,20,20,20,19,19,19,18,18,18,18,17,17,17,16,16,16,15,15,15,14,14,14,13,13,13,12,12,12,12,11,11,11,10,10,10,9,9,9,8,8,8,8,7,7,7,6,6,6,5,5,5,4,4,4,4,3,3,3,2,2,2,1,1,1,1,0,-0,-0,-1,-1,-1,-2,-2,-2,-2,-3,-3,-3,-4,-4,-4,-5,-5,-5,-5,-6,-6,-6,-7,-7,-7,-7,-8,-8,-8,-9,-9,-9,-9,-10,-10,-10,-11,-11,-11,-12,-12,-12,-12,-13,-13,-13,-14,-14,-14,-14,-15,-15,-15,-16,-16,-16,-16,-17,-17,-17,-17,-18,-18,-18,-19,-19,-19,-19,-20,-20,-20,-21,-21,-21,-21,-22,-22,-22,-23,-23,-23,-23,-24,-24,-24,-24,-25,-25,-25,-26,-26,-26,-26,-27,-27,-27,-27,-28,-28,-28,-29,-29,-29,-29,-30,-30,-30,-30,-31,-31,-31,-32,-32,-32,-32,-33,-33,-33,-33,-34,-34,-34,-34,-35,-35};
LiquidCrystal lcd(12,11,5,4,3,2);
int val = 0;
void setup(){
analogReference(INTERNAL);
}
void loop() {
val = analogRead(0);
lcd.clear();
lcd.print( data[val] / 10); // 整数
lcd.write( 0x2e); // . カンマ
lcd.print( data[val] % 10); // 小数点以下
delay(1000);
}