第1回 Arduinoの基礎 – 温度センサーの値を読み取る

温度センサーの値を読み取る

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define TEMP_PIN 0
 
void setup()
{
  Serial.begin(9600);
}
 
void loop()
{
  int tempVal = 0;
  int tempMilliVolt = 0;
  float temp = 0;
 
  tempVal = analogRead(TEMP_PIN);
  tempMilliVolt = (unsigned long)5000 * tempVal / 1023;
  temp = (tempMilliVolt - 600) / 10.0;
 
  Serial.println(temp);
 
  delay(1000);
}
カテゴリー: 第1回 Arduinoの基礎   パーマリンク

コメントは受け付けていません。