iOT , DIY/Arduino
아두이노 NTC thermistor 온도측정기 만들기
Jason park@
2020. 5. 25. 08:53
반응형
NTC저항을 이용해 벌써 2번째 사용할곳이 생겼다
처음 사용했던곳은 보일러 배관 온도를 가지고 보일러 자동 온도 조절을 위해 사용했었고 ,
두번째는 LED 조명을 만드는데 있어 방열판 성능 시험을 위해 만들게되었다.
2년만에 다시 잡는 아두이노지만 기존에 했던 샘플 소스가 있어 빨리 만들 수 있었다.
준비물은 아래와 같다.
1. 아두이노 나노
2. NTC thermistor 10k
3. 10k 저항
4. i2c LCD 16x2
5. 브레드보드, 점퍼와이어
소스는 다음과 같다.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
#define RT0 10000 // Ω
#define B 3977 // K
#define VCC 5 //Supply voltage
#define R 10000 //R=10KΩ
float RT, VR, ln, TX, T0, VRT;
void setup()
{
Serial.begin(9600);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.print("");
T0 = 25 + 273.15;
}
void loop()
{
VRT = analogRead(A0); //Acquisition analog value of VRT
VRT = (5.00 / 1023.00) * VRT; //Conversion to voltage
VR = VCC - VRT;
RT = VRT / (VR / R); //Resistance of RT
ln = log(RT / RT0);
TX = (1 / ((ln / B) + (1 / T0))); //Temperature from thermistor
TX = TX - 273.15; //Conversion to Celsius
lcd.setCursor(0, 0);
char pChrBuffer[50];
lcd.printf("%s C", dtostrf(TX , 5, 2, pChrBuffer));
Serial.print("Temperature:");
Serial.print("\t");
Serial.print(TX);
Serial.print("C\t\t");
Serial.print(TX + 273.15); //Conversion to Kelvin
Serial.print("K\t\t");
Serial.print((TX * 1.8) + 32); //Conversion to Fahrenheit
Serial.println("F");
delay(500);
}
char * dtostrf(double __val, signed char __width, unsigned char __prec, char * __s);
printf 에 %.2f 기능이 없어 dtostrf 함수를 사용했다.
%f 를 사용하면 ? 가 나온다.
아두이노 printf() 사용하기
다른 언어에서 디버깅을 위해 printf 구문을 많이 사용한다. ex : printf(" 이거슨 : %s ", "디버그") printf 의 장점이라고 하면 짧은 문장 안에 여러 변수가 들어가야 할때, 보기 좋고 관리하기 좋다는 장
brtech.tistory.com
아두이노에 보드 셋팅을 다음과 같이 하고, 보드에 업로드를 해보자.
업로드 후, 시리얼 모니터와 LCD 창에 온도가 잘 나온다면 성공이다.
반응형