How to connect DS18B20 to RaspberryPI GPIO
How to view what is the ID of the Device?
In terminal
pi@raspberrypi /sys/bus/w1/devices $ cd /sys/bus/w1/devices/
pi@raspberrypi /sys/bus/w1/devices $ ls
28-000004d13e6d w1_bus_master1
28-000004d13e6d This is a my ID
How to test DS18B20
cat /sys/bus/w1/devices/28-000004d13e6d/w1_slave
t=26500 = 26.5 C
PHP Script
<?php
//File to read
$file = '/sys/bus/w1/devices/28-000004d13e6d/w1_slave';
//Read the file line by line
$lines = file($file);
//Get the temp from second line
$temp = explode('=', $lines[1]);
//Setup some nice formatting (i.e. 21,3)
$temp = number_format($temp[1] / 1000, 1, ',', '');
//And echo that temp
echo $temp . "C";
?>
Download PHP Script - DOWNLOAD