The Raspiduino Project

Articles, guides & links to the Raspberry Pi & Arduino.

Dallas I2C Thermometer

The digital thermometer of choice is the Dallas DS18B20. It looks like a transistor with three legs, but is a 1-wire device, which means that multiple units can be linked on one data bus wire and connected to the Arduino. This data bus is called the I2C.

If we are using one Dallas DS18B20, we just plug in and go. The I2C does allow us to connect multiple DS18B20 devices in parallel at the same time. For the Arduino to talk to the correct device, we would need to know the address of each device. To do this, we would initially run a one off code to display the addresses on the Serial monitor. We make a note of which address belongs to which device, then place the addresses in the code for each thermometer…. Errm I think that makes sense.

Dallas Single Serial_bb

So, above, you can see the DS18B20 connected to the Arduino Mega 2560.

Simple bit of code:

/*----( Import libraries )----*/
 #include <OneWire.h> 
 #include <DallasTemperature.h>
 /*----( Declare Constants )----*/
 #define ONE_WIRE_BUS 2 /*-(Connect to Pin 2 )-*/
 /*---( Declare objects )----*/
 /* Set up a oneWire instance to communicate with any OneWire device*/
 OneWire ourWire(ONE_WIRE_BUS);
 /* Instruct Dallas Temperature Library to use oneWire Library */
 DallasTemperature sensors(&ourWire);
 /*----( Declare Variables )----*/
 // No Variables

void setup() {
 /*-(start serial port [CTRL + SHIFT + M] to see results )-*/
   Serial.println("Dallas DS18B20 Thermometer");
 /*-( Start up the DallasTemperature library )-*/
 } /*--(end setup )---*/
 void loop() {
   sensors.requestTemperatures(); // Send command to Dallas to get the temp.

   Serial.print(sensors.getTempCByIndex(0)); // Print the returned temp in Deg C
   Serial.println(" Degrees C");
   Serial.print(sensors.getTempFByIndex(0)); // Print the returned temp in Deg F
   Serial.println(" Degrees F");
 }/* --(end main loop )-- */
 /* ( END ) */

Action Screenshot:
Dallas Single Serial

Leave a Reply

Your email address will not be published. Required fields are marked *

The Raspiduino Project © 2015 Frontier Theme