It's a small project about temperature monitoring. I used a DS18B20 digital device to get the temperature. The device uses OneWire protocol. You need only an Arduino board, a DS18B20 and a 4.7KOhm resistor and a breadboard. If you have a display shield for the Arduino that's a plus.

Step 1: What you have to know about DS18B20

The device is communicating on one common bus. It means that you can connect several devices. We use only two pins on the device to connect them to the Arduino board. We need two libraries in the sketch: OneWire and DallasTemperature .

So we must include these libraries.

<p>This is very helpful, but IMHO there's an error in the Step 1 diagram showing the resistor; if you simply put the 4.7K resistor on the power line as shown you also drop the voltage to the device while pulling the data line high. Putting the resistor on the data line will keep voltage to the devices nominal and pull data high as well. Works great otherwise and thank you for putting it up!</p>
<p>Hi, </p><p>This is my first Arduino project and so far have one DS18B20 working as a basic thermostat using a code I found that didn't required the Dallas Temperature Library. However I would love to use three sensors and the display as shown here, the only problem is that I don't seem to be able to find the actual variables that contain the temperature values for each sensor. I will need these to operate various hardware such as fans, actuators and heaters based on a temperature set point and the values for each of the sensors. </p><p>Can anyone help with some code to create or access these variables.</p><p>Thanks.</p>
Hi<br><br>If you want to use more sensors, then I recommend using the library. ScanSensors will do a loop and read all the sensors on the same wire. It runs from the Setup function, so let's say it collects how many sensors we have. Then we read the individual sensor temperatures from the Loop function. First we send a command to measure the temperature: sensors.requestTemperatures(); After we can re the values by an index: float f = sensors.getTempCByIndex(i);<br><br>Regards,<br>Mark
<p>Thanks Mark, </p><p>I am very new to the C programming language but after some reading I think you have created an array that contains the sensor values and to access each one individually they would be called f[0], f[1] and f[2], is this right? </p><p>Unfortunately I haven't been able to test this theory as I am getting multiple errors when I try and compile the sketch. In fact I can't even compile the examples in the onewire and Dallas Temperature library's that came from the link above. The errors from the OneWire library example are to do with &quot;WConstants.h: Nosuch file or directory&quot; and a bunch of variables that &quot;was not declared in this scope&quot; like digitalPinToBitMask and delayMicroseconds etc. The errors from your sketch are pointing to the LCD4bit_mod library file location and also mention the &quot;WConstants.h: Nosuch file or directory&quot; and a bunch of variables that &quot;was not declared in this scope&quot;. </p><p>Is there likely to be a simple fix for this?</p>
<p>Well I can now see I was a little off the mark. I have found that the individual readings can be accessed by</p><p> float temp1 = sensors.getTempCByIndex(0);</p><p> float temp2 = sensors.getTempCByIndex(1); etc....</p><p>The WConstants.h error can be resolved by removing the #include &quot;WConstants.h&quot; from the .cpp file and adding #include &quot;Arduino.h&quot; to the .h file as per <a href="https://sites.google.com/site/kingauswebpage/my-projects/cannot-find-wconstants-h" rel="nofollow">https://sites.google.com/site/kingauswebpage/my-pr...</a></p>
I found a link: <br>https://github.com/opb/DS18B20-Arduino-Library
Hi<br><br>That's cool. I found it in my project folder too :)<br>if you need it for some reasons:<br><br>http://oscomputer.hu/download/arduino/DallasTemperature_OneWire_for_Arduino_1.0.4.zip<br><br>an older version:<br>http://oscomputer.hu/download/arduino/DallasTemperature_350.zip<br><br>Regards,<br>Mark
<p>Thanks Mark,</p><p>Oddly enough I am having issues with OneWire library. Did you recieve a WConstants.h error when trying to compile? I attached an image of the error and my OneWire.h library. </p>
Hello<br><br>No I didn't get such error message when I used 1.0.4 version of IDE with this library: http://oscomputer.hu/download/arduino/DallasTemperature_OneWire_for_Arduino_1.0.4.zip<br><br>regards,<br>Mark
<p>Mark,</p><p>Thanks for the code. I get another error now, see attached, and am using it for a sous vide application. </p>
<p>I can still recommend you using Arduino 1.0.4.</p><p>That version is working and can be compiled. See attached image.</p>
<p>double checked, no compile errors at all. I used this simple source:</p><p>#include &lt;OneWire.h&gt;</p><p>#include &lt;DallasTemperature.h&gt;</p><p>#include &lt;stdio.h&gt;</p><p>#define ONE_WIRE_BUS 3</p><p>char buffer[25];</p><p>byte maxlines = 2;</p><p>char line1[16];</p><p>char line2[16];</p><p>byte x = 0;</p><p>byte y = 1;</p><p>byte maxsensors = 0;</p><p>/* DS18S20 Temperature chip i/o */</p><p>OneWire ds(ONE_WIRE_BUS);</p><p>DallasTemperature sensors(&amp;ds);</p><p>void flashled(void)</p><p>{</p><p> digitalWrite(13, HIGH);</p><p> delay(1);</p><p> digitalWrite(13, LOW);</p><p>}</p><p>void scanSensors(void)</p><p>{</p><p> byte i;</p><p> byte present = 0;</p><p> byte data[12];</p><p> byte addr[8];</p><p> while (ds.search(addr))</p><p> {</p><p> Serial.print(&quot;R=&quot;);</p><p> for( i = 0; i &lt; 8; i++) {</p><p> Serial.print(addr[i], HEX);</p><p> Serial.print(&quot; &quot;);</p><p> }</p><p> if ( OneWire::crc8( addr, 7) != addr[7]) {</p><p> Serial.print(&quot;CRC is not valid!\n&quot;);</p><p> return;</p><p> }</p><p> if ( addr[0] == 0x10) {</p><p> Serial.print(&quot;Device is a DS18S20 family device.\n&quot;);</p><p> maxsensors++;</p><p> }</p><p> else {</p><p> if (addr[0] == 0x28) {</p><p> Serial.print(&quot;Device is a DS18B20 family device.\n&quot;);</p><p> maxsensors++;</p><p> }</p><p> else {</p><p> Serial.print(&quot;Device is unknown!\n&quot;);</p><p> Serial.print(&quot;Device ID: &quot;);</p><p> Serial.print(addr[0],HEX);</p><p> Serial.println();</p><p> return;</p><p> }</p><p> }</p><p> // The DallasTemperature library can do all this work for you!</p><p> ds.reset();</p><p> ds.select(addr);</p><p> ds.write(0x44,1); // start conversion, with parasite power on at the end</p><p> delay(1000); // maybe 750ms is enough, maybe not</p><p> // we might do a ds.depower() here, but the reset will take care of it.</p><p> present = ds.reset();</p><p> ds.select(addr); </p><p> ds.write(0xBE); // Read Scratchpad</p><p> Serial.print(&quot;P=&quot;);</p><p> Serial.print(present,HEX);</p><p> Serial.print(&quot; &quot;);</p><p> for ( i = 0; i &lt; 9; i++) { // we need 9 bytes</p><p> data[i] = ds.read();</p><p> Serial.print(data[i], HEX);</p><p> Serial.print(&quot; &quot;);</p><p> }</p><p> Serial.print(&quot; CRC=&quot;);</p><p> Serial.print( OneWire::crc8( data, 8), HEX);</p><p> Serial.println();</p><p> flashled();</p><p> }</p><p> Serial.print(&quot;No more addresses.\n&quot;);</p><p> ds.reset_search();</p><p> delay(250);</p><p>}</p><p>void setup(void) {</p><p> Serial.begin(9600);</p><p> pinMode(13, OUTPUT);</p><p> byte i, j;</p><p> for (j=0;j&lt;16;j++) </p><p> { </p><p> line1[j] = 32; </p><p> line2[j] = 32;</p><p> }</p><p> line1[16] = 0;</p><p> line2[16] = 0;</p><p> x = 0;</p><p> y = 1;</p><p> sensors.begin();</p><p> scanSensors();</p><p>}</p><p>void loop(void) {</p><p> sensors.requestTemperatures(); // minden eszk&ouml;ztől k&eacute;rj&uuml;k a hőm&eacute;rs&eacute;klet m&eacute;r&eacute;st...</p><p> for (int i=0;i&lt;maxsensors;i++)</p><p> {</p><p> flashled();</p><p> float f = sensors.getTempCByIndex(i); // egyes&eacute;vel kiolvassuk a m&eacute;rt &eacute;rt&eacute;ket</p><p> Serial.print(&quot;Sensor &quot;);</p><p> Serial.print(i,DEC);</p><p> Serial.println(dtostrf(f, 6, 2, buffer));</p><p> }</p><p>}</p>
The Dallas Temperature library link shows to be offline on the download.milesburton.com site. I have looked at a few sites and they all seem to point to this broken link. Is there any other avenue to access this library?
can this project be used for different types of sensors like temp,press,humidity etc..?
Yes, sure. As it is based on Arduino, many sensors can be used easily. You can start here: http://arduino.cc/playground/Main/InterfacingWithHardware#presssens<br>

About This Instructable


59 favorites


More by mosvath: Temperature with DS18B20
Add instructable to: