5
5

More than 5 years have passed since last update.

Raspberry Pi に 温度センサーをつける

Posted at

Raspberry Piで遊ぼう! 改訂第2版のとおりに試してみた。

使ったもの

  • Raspberry Pi Model B
  • 1-wire 温度センサー (DS18B20) + 2.2kΩ抵抗
  • ブレッドボード
  • ジャンパ

作業用端末

  • Mac Book Air (OSX Mavericks 10.9.4)

ブレッドボードで配線

こんな感じで配線した。

"Pin1:3.3v"  ----- "DS18B20:VSS"
               |
            "2.2kΩ"
               |
"Pin7:GPIO4" ----- "DS18B20:DQ"
"Pin6:GND"   ----- "DS18B20:GRD"

1-wire を使えるように設定する

Raspberry Pi にログインし、 /etc/modules に以下2行を追記する。(sudo vi などで)

/etc/modules
w1-gpio
w1-them

Raspberry Pi を再起動する。

Pi
$ sudo shutdown -r now

温度を読み取る

デバイス ID の確認

Pi
$ ls /sys/bus/w1/devices
28-00000xxxxxxx  w1_bus_master1

28-00000... のシンボリックリンクがデバイス ID になる。

実際に温度を読み取る

Pi
$ cat /sys/bus/w1/devices/28-00000xxxxxxx/w1_slave 
9b 01 4b 46 7f ff 05 10 6e : crc=6e YES
9b 01 4b 46 7f ff 05 10 6e t=25687

t=25687 の部分が温度を表し、25.687度ということらしい。

参考

5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5