 <?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://Robo.Fish/wiki/index.php?action=history&amp;feed=atom&amp;title=DS18B20</id>
	<title>DS18B20 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://Robo.Fish/wiki/index.php?action=history&amp;feed=atom&amp;title=DS18B20"/>
	<link rel="alternate" type="text/html" href="https://Robo.Fish/wiki/index.php?title=DS18B20&amp;action=history"/>
	<updated>2026-04-23T04:06:38Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://Robo.Fish/wiki/index.php?title=DS18B20&amp;diff=1446&amp;oldid=prev</id>
		<title>Kai at 2016-08-19T08:32:17</title>
		<link rel="alternate" type="text/html" href="https://Robo.Fish/wiki/index.php?title=DS18B20&amp;diff=1446&amp;oldid=prev"/>
		<updated>2016-08-19T08:32:17Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
[[File:Sensor_DS18B20_breadboard.jpg]]&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
The DS18B20 is a temperature sensor by Maxim Integrated (previously Dallas Semiconductor) with digital output suitable for directly connecting to a digital controller. There are three pins:  V&amp;lt;sub&amp;gt;DD&amp;lt;/sub&amp;gt; for connecting the supply voltage, which must be between 3 and 5.5 V, DQ for connecting a controller that programs the sensor and reads the temperature values, and finally, GND for ground. DQ must also be connected to the supply voltage via a 4.7 k&amp;amp;Omega; pull-up resistor.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
* [https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf Datasheet]&lt;br /&gt;
* [https://learn.adafruit.com/adafruits-raspberry-pi-lesson-11-ds18b20-temperature-sensing/overview Example application by Simon Monk].&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
=== Operating with an Arduino ===&lt;br /&gt;
The &amp;#039;&amp;#039;DallasTemperature&amp;#039;&amp;#039; software library by Miles Burton handles both the [http://playground.arduino.cc/Learning/OneWire 1-Wire] protocol for communicating with 1-Wire devices as well as the specifics of getting temperature data from the DS18B20. You can install the library via the Arduino IDE.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre class=&amp;quot;code&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;OneWire.h&amp;gt;&lt;br /&gt;
#include &amp;lt;DallasTemperature.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
OneWire oneWire(9); // using digital I/O #9&lt;br /&gt;
DallasTemperature sensors(&amp;amp;oneWire);&lt;br /&gt;
DeviceAddress thermometer;&lt;br /&gt;
&lt;br /&gt;
void setup()&lt;br /&gt;
{&lt;br /&gt;
  Serial.begin(9600);&lt;br /&gt;
  sensors.begin();&lt;br /&gt;
  sensors.getAddress(thermometer, 0);   &lt;br /&gt;
  sensors.setResolution(thermometer, 12);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void loop()&lt;br /&gt;
{&lt;br /&gt;
  static unsigned long sensortime = 0;&lt;br /&gt;
&lt;br /&gt;
  unsigned long now = millis();&lt;br /&gt;
  if(sensortime &amp;lt; now)&lt;br /&gt;
  {    &lt;br /&gt;
    sensortime = now + 60000l; // schedule next readout for 60 seconds later&lt;br /&gt;
    sensors.requestTemperatures();&lt;br /&gt;
    float temperature = sensors.getTempC(thermometer); // read temperature in Celsius&lt;br /&gt;
    temperature = round(10.0*temperature)/10.0;&lt;br /&gt;
    Serial.print(&amp;quot;temperature at &amp;quot;);&lt;br /&gt;
    Serial.print(now / 1000 / 60);&lt;br /&gt;
    Serial.print(&amp;quot; minutes after launch: &amp;quot;);&lt;br /&gt;
    Serial.println(temperature, 1); // show only 1 place after the decimal&lt;br /&gt;
  }&lt;br /&gt;
  else&lt;br /&gt;
  {&lt;br /&gt;
    delay(2000); // pause for 2 seconds&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Operating with a Raspberry Pi ===&lt;br /&gt;
To set up 1-Wire data communication on a certain pin you need to edit &amp;#039;&amp;#039;&amp;#039;/boot/config.txt&amp;#039;&amp;#039;&amp;#039; and add the line&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre class=&amp;quot;code&amp;quot;&amp;gt;&lt;br /&gt;
dtoverlay=w1-gpio,gpiopin=4,pullup=on&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
where we assume that the &amp;#039;&amp;#039;DQ&amp;#039;&amp;#039; pin of the sensor is connected to GPIO4, which is header pin #7. In order for the system to load the kernel modules for 1-Wire communication and for communicating with 1-Wire temperature sensors we edit &amp;#039;&amp;#039;&amp;#039;/etc/modules&amp;#039;&amp;#039;&amp;#039; by adding the following two lines:&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre class=&amp;quot;code&amp;quot;&amp;gt;&lt;br /&gt;
w1-gpio pullup=1&lt;br /&gt;
w1-therm&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
The kernel module &amp;#039;&amp;#039;w1-therm&amp;#039;&amp;#039; creates a new folder under &amp;#039;&amp;#039;&amp;#039;/sys/bus/w1/devices&amp;#039;&amp;#039;&amp;#039; and the device file &amp;#039;&amp;#039;&amp;#039;w1_slave&amp;#039;&amp;#039;&amp;#039; inside the folder. The device file contains the last reading from the sensor and the folder name is the ID of the 1-Wire device. We use this ID in the Python program below, which periodically reads the sensor data.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;pre class=&amp;quot;code&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
&lt;br /&gt;
import re, os, time, datetime&lt;br /&gt;
import RPi.GPIO as GPIO&lt;br /&gt;
pin_temp_sensor = 12 # corresponds to GPIO18 of SOC&lt;br /&gt;
sensorid = &amp;quot;28-000007351a0d&amp;quot; # This ID is specific to the device!!!&lt;br /&gt;
&lt;br /&gt;
def readTemperature(path):&lt;br /&gt;
  temperature = None&lt;br /&gt;
  try:&lt;br /&gt;
    GPIO.output(pin_temp_sensor, GPIO.LOW)&lt;br /&gt;
    f = open(path, &amp;quot;r&amp;quot;)&lt;br /&gt;
    line = f.readline()&lt;br /&gt;
    if re.match(r&amp;quot;([0-9a-f]{2} ){9}: crc=[0-9a-f]{2} YES&amp;quot;, line):&lt;br /&gt;
      line = f.readline()&lt;br /&gt;
      m = re.match(r&amp;quot;([0-9a-f]{2} ){9}t=([+-]?[0-9]+)&amp;quot;, line)&lt;br /&gt;
      if m:&lt;br /&gt;
        temperature = float(m.group(2))/1000&lt;br /&gt;
    f.close()&lt;br /&gt;
  except IOError:&lt;br /&gt;
    print(&amp;quot;sensor error&amp;quot;)&lt;br /&gt;
  return temperature&lt;br /&gt;
&lt;br /&gt;
if __name__ == &amp;#039;__main__&amp;#039;:&lt;br /&gt;
  GPIO.setwarnings(False)&lt;br /&gt;
  GPIO.setmode(GPIO.BOARD)&lt;br /&gt;
  GPIO.setup(pin_temp_sensor, GPIO.OUT)&lt;br /&gt;
  deviceFilePath = &amp;quot;/sys/bus/w1/devices/%s/w1_slave&amp;quot; % sensorid # sensorid is the folder name&lt;br /&gt;
  nextUpdateTime = datetime.datetime.min&lt;br /&gt;
  while True:&lt;br /&gt;
    now = datetime.datetime.now()&lt;br /&gt;
    if nextUpdateTime &amp;lt; now:&lt;br /&gt;
      nextUpdateTime = now + datetime.timedelta(minutes=1)&lt;br /&gt;
      t = readTemperature(deviceFilePath)&lt;br /&gt;
      if t != None:&lt;br /&gt;
        print(&amp;quot;the temperature at &amp;quot; + now.strftime(&amp;quot;%H:%M&amp;quot;) + &amp;quot; is %.1f&amp;quot; % t)&lt;br /&gt;
    time.sleep(2)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;/div&gt;</summary>
		<author><name>Kai</name></author>
	</entry>
</feed>