[arduino] LM35 / TMP36 Analog Sensor 연결도 : arduino IDE or VScode 설정 및 모니터링
Arduino UNO R3 : LM35 Sensor 연결도(TMP36 동일) 및 전달함수식
LM35
Analog Output이므로 A0 ~ A5에 연결 : 필자는 A0에 연결
range : 온도 / 출력(전송)전압, -55ºC ~ 150ºC : -550mV ~ 1500mV
LM35 Transfer Function
<func.1>
Arduino AO resolution : 10bit(2^10=1024)
<func.2>
V_ref : Arduino 인가 전압, 여기서는 5V
<func.1>을 <func.2>에 대입하여 T[oC]로 정리하면,
arduino.ino code에 함수식 적용
TMP36
T = (Value/1024*Vin - 0.5) * 100
[Arduino IDE 사용]
Arduino IDE 2.2.1
1. 보드메니저 : 해당보드 설치
Tools >> Board >> Boards Manager
Arduino Uno R3 or Arduino Nano : "Arduino AVR Boards" install
Arudino Uno R4 wifi : "Arduino UNO R4 Boards" install
2. 보드 선택
Tools >> Board >> Arduino AVR Boards >> 해당보드 선택
3. 포트 선택
Tools >> Port >> /dev/cu.usbmodem....
4. 코드 작성 / 코드 검증 / 업로드
코드 작성
py_ard_lm35.ino
int value;
int Vin = 5;
void setup()
{
Serial.begin(9600);
}
void loop()
{
value = analogRead(0);
// LM35
float tempC = (value/1024.0)*Vin*100;
// TMP36
// float tempC = ((value/1024.0)*Vin - 0.5)*100;
Serial.print("TEMPRATURE IS ");
Serial.print(tempC);
Serial.println("^oC");
delay(2000);
}
코드 검증 or 업로드
sketch >> Verify/Compile
sketch >> Upload
5. Serial Monitor
Tools >> Serial Monitor
아래 모니터링 창 확인
================================================
[Visual Studio Code사용]
vscode : Visual Studio Code
https://code.visualstudio.com/download
자신의 OS 선택해서 설치
# VScode Extensions 설치 참고
windows : https://jinozblog.tistory.com/206
macOS : https://jinozblog.tistory.com/176
ununtu : https://jinozblog.tistory.com/198
1. 보드메니저 : 해당보드 설치
보기 >> 명령파레트 : 단축키 cmd + shift 'p'
검색 arduino > 선택 arduino: Board Manager
Arduino Uno R3 or Arduino Nano : "Arduino AVR Boards" install
Arudino Uno R4 wifi : "Arduino UNO R4 Boards" install
2. 보드 선택
단축키 cmd + shift 'p'
검색 arduino > 선택 arduino: Board Config
3. 포트 선택
단축키 cmd + shift 'p'
검색 arduino > 선택 arduino: Select Serial Port
4. 코드 작성 / 코드 검증 / 업로드
코드 작성 : 폴더 이름과 파일.ino의 파일 이름 일치되어야함
py_ard_lm35.ino
int value;
int Vin = 5;
void setup()
{
Serial.begin(9600);
}
void loop()
{
value = analogRead(0);
// LM35
float tempC = (value/1024.0)*Vin*100;
// TMP36
// float tempC = ((value/1024.0)*Vin - 0.5)*100;
Serial.print("TEMPRATURE IS ");
Serial.print(tempC);
Serial.println("^oC");
delay(2000);
}
코드 검증 or 업로드
단축키 cmd + shift 'p'
검색 arduino > 선택 arduino: Verify
검색 arduino > 선택 arduino: Upload
5. Serial Monitor
단축키 cmd + shift 'p'
검색 arduino > 선택 arduino: Open Serial Monitor >> 9600(baud rate, "보레이트")
아래 모니터링 창 확인