728x90
아두이노 + NTC 온도센서
온도 4개 값을 그래프로 표시합니다.
int ThermistorPin = 0;
int Vo, Vout;
float R1 = 10000;
float logR2, R2, T,VR,VRT; float T2, T3, T4;
float Temp = 0;
float c1 = 1.126260975e-03, c2 = 2.354310794e-04, c3 = 0.7596803406e-07;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
Vo = analogRead(0);
Vout = Vo; // 1023-Vo;
R2 = R1 * (1023.0 / (float)Vout - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
T = T - 273.15;
//T = (T * 9.0)/ 5.0 + 32.0; //화씨 온도 계산, 주석 처리
VRT = (5.00 / 1023.00) * Vo; //Conversion to voltage
VR = 5 - VRT;
Vo = analogRead(1);
Vout = Vo; // 1023-Vo;
R2 = R1 * (1023.0 / (float)Vout - 1.0);
logR2 = log(R2);
T2 = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
T2 = T2 - 273.15;
//T = (T * 9.0)/ 5.0 + 32.0; //화씨 온도 계산, 주석 처리
VRT = (5.00 / 1023.00) * Vo; //Conversion to voltage
VR = 5 - VRT;
Vo = analogRead(2);
Vout = Vo; // 1023-Vo;
R2 = R1 * (1023.0 / (float)Vout - 1.0);
logR2 = log(R2);
T3 = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
T3 = T3 - 273.15;
//T = (T * 9.0)/ 5.0 + 32.0; //화씨 온도 계산, 주석 처리
VRT = (5.00 / 1023.00) * Vo; //Conversion to voltage
VR = 5 - VRT;
Vo = analogRead(3);
Vout = Vo; // 1023-Vo;
R2 = R1 * (1023.0 / (float)Vout - 1.0);
logR2 = log(R2);
T4 = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
T4 = T4 - 273.15;
//T = (T * 9.0)/ 5.0 + 32.0; //화씨 온도 계산, 주석 처리
VRT = (5.00 / 1023.00) * Vo; //Conversion to voltage
VR = 5 - VRT;
Serial.print(T); Serial.print(',');
Serial.print(T2); Serial.print(',');
Serial.print(T3); Serial.print(',');
Serial.print(T4); Serial.print(',');
Serial.println();
delay(1000);
}
평균값을 이용하여 그래프로 표시합니다.
int ThermistorPin = 0;
int Vo, Vout;
float R1 = 10000;
float logR2, R2, T,VR,VRT; float T2, T3, T4;
float Temp = 0;
float c1 = 1.126260975e-03, c2 = 2.354310794e-04, c3 = 0.7596803406e-07;
#define MAX_NTC 4
#define MAX_NUM 10
float average[MAX_NTC][MAX_NUM];
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
}
int timeout = 0;
void loop() {
// put your main code here, to run repeatedly:
Vo = analogRead(0);
Vout = Vo; // 1023-Vo;
R2 = R1 * (1023.0 / (float)Vout - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
T = T - 273.15;
//T = (T * 9.0)/ 5.0 + 32.0; //화씨 온도 계산, 주석 처리
VRT = (5.00 / 1023.00) * Vo; //Conversion to voltage
VR = 5 - VRT;
Vo = analogRead(1);
Vout = Vo; // 1023-Vo;
R2 = R1 * (1023.0 / (float)Vout - 1.0);
logR2 = log(R2);
T2 = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
T2 = T2 - 273.15;
//T = (T * 9.0)/ 5.0 + 32.0; //화씨 온도 계산, 주석 처리
VRT = (5.00 / 1023.00) * Vo; //Conversion to voltage
VR = 5 - VRT;
Vo = analogRead(2);
Vout = Vo; // 1023-Vo;
R2 = R1 * (1023.0 / (float)Vout - 1.0);
logR2 = log(R2);
T3 = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
T3 = T3 - 273.15;
//T = (T * 9.0)/ 5.0 + 32.0; //화씨 온도 계산, 주석 처리
VRT = (5.00 / 1023.00) * Vo; //Conversion to voltage
VR = 5 - VRT;
Vo = analogRead(3);
Vout = Vo; // 1023-Vo;
R2 = R1 * (1023.0 / (float)Vout - 1.0);
logR2 = log(R2);
T4 = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
T4 = T4 - 273.15;
//T = (T * 9.0)/ 5.0 + 32.0; //화씨 온도 계산, 주석 처리
VRT = (5.00 / 1023.00) * Vo; //Conversion to voltage
VR = 5 - VRT;
memmove(&average[0][1], &average[0][0], (MAX_NUM-1)*sizeof(float));
memmove(&average[1][1], &average[1][0], (MAX_NUM-1)*sizeof(float));
memmove(&average[2][1], &average[2][0], (MAX_NUM-1)*sizeof(float));
memmove(&average[3][1], &average[3][0], (MAX_NUM-1)*sizeof(float));
average[0][0] = T;
average[1][0] = T2;
average[2][0] = T3;
average[3][0] = T4;
timeout += 1;
if(timeout % 10 == 0) {
float total[MAX_NUM] = { 0x00, };
for(int i = 0; i < MAX_NUM; i++)
{
total[0] += average[0][i];
total[1] += average[1][i];
total[2] += average[2][i];
total[3] += average[3][i];
}
Serial.print(total[0]/MAX_NUM); Serial.print(',');
Serial.print(total[1]/MAX_NUM); Serial.print(',');
Serial.print(total[2]/MAX_NUM); Serial.print(',');
Serial.print(total[3]/MAX_NUM); Serial.print(',');
Serial.println();
}
/*
Serial.print(T); Serial.print(',');
Serial.print(T2); Serial.print(',');
Serial.print(T3); Serial.print(',');
Serial.print(T4); Serial.print(',');
Serial.println(); */
delay(1000);
}
보드 연결
아두이노 보드와 온도센서를 연결합니다.
아날로그핀 A0, A1, A2, A3을 NTC 10K 온도센서와 연결합니다.
www.circuitbasics.com/arduino-thermistor-temperature-sensor-tutorial/
Make an Arduino Temperature Sensor (Thermistor Tutorial)
Learn how to use an analog thermistor to measure temperature on the Arduino. Output readings to an LCD or the serial monitor in Celsius or Fahrenheit.
www.circuitbasics.com
'임베디드 보드 > 아두이노' 카테고리의 다른 글
유량센서 YF-S201 테스트 (0) | 2021.05.02 |
---|---|
Arduino Nano rs485 + RELAY BOARD 제어 (0) | 2021.03.02 |
esp8266 update ai-thinker (0) | 2020.11.29 |
CH376S Arudino Disk Read-write Module USB Flash Disk (2) | 2020.11.21 |
PTC 히팅 아두이노 PWM 제어 (1) | 2020.11.05 |