> For the complete documentation index, see [llms.txt](https://docs.sysout.co.kr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sysout.co.kr/base-language/arduino/arduino-control/analog-input/temperature-sensor-lm35dz.md).

# 온도 센서(LM35DZ)

## 온도 센서

이 문서에서는 온도 센서를 이용하여 회로를 구성하는 내용을 다룬다.

### 온도 센서(LM35DZ)

아날로그 온도센서인 LM35DZ는 0도부터 100도까지 측정가능하며 빠른 온도 변화에는 적합하지 않은 유형의 온도센서이다.

### 결선도

![](https://4208234536-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_TNZwLuHV9ipYLbvRq%2F-Mf1pFUEjFxSSv7mwLN_%2F-Mf1pSBSTYUNuMld1j1R%2Fimage.png?alt=media\&token=57db7088-701d-4055-8a9f-740c4850ce1e)

### 샘플 코드

```
const int LM35PIN = A0;

void setup(){
  Serial.begin(9600);
}

void loop(){
  int input = analogRead(LM35PIN);
  float temperature = (5.0 * input * 100) / 1024;
  Serial.print(input);
  Serial.print(", ");
  Serial.println(temperature);
  delay(1000);
}
```

### 컴파일

`Ctrl+R` 또는 스케치 메뉴의 `확인/컴파일`을 눌러 컴파일을 진행한다.

### 업로드

`Ctrl+U` 또는 스케치 메뉴의 `업로드`를 눌러 업로드를 진행한다.

### 실행 결과

온도가 1초간격으로 측정되어 화면에 출력되는 것을 확인할 수 있다.\
손가락을 센서에 대면 온도가 상승하는 것을 확인할 수 있다.

### 코드 설명

아두이노 LM35PIN 입력핀을 A0로 설정한다.

```
const int LM35PIN = A0;
```

`setup` 함수에서는 Serial의 전송속도를 9600보드레이트로 설정한다.

```
void setup(){
  Serial.begin(9600);
}
```

`loop` 함수에서는 입력값을 읽어와 변환 공식에 의해 변환하여 출력하는 내용을 1초마다 반복한다.

```
void loop(){
  int input = analogRead(LM35PIN);//아날로그 입력
  float temperature = (5.0 * input * 100) / 1024;//변환
  Serial.print(input);//입력값 출력
  Serial.print(", ");//콤마 출력
  Serial.println(temperature);//변환값 출력
  delay(1000);//1초 딜레이
}
```

### 변환 공식

변환 공식은 공식 사이트에 설명되어 있다.\
[공식 사이트 보기](https://playground.arduino.cc/Main/LM35HigherResolution/)

$$
온도 = (5.0 \* 센서값 \* 100) / 1024
$$
