18B20_Temperature_Sensor_(SKU__DFR0024) - jimaobian/DFRobotWiki GitHub Wiki
Introduction
The DS18B20 is a very small thermometer which can be easily hooked into the Arduino MCU through any digital input! It requires very little in the way of additional support, a couple of resistors and some hookup cables and you're set to go.
For more information on the DS18B20 check out http://www.maxim-ic.com/quick_view2.cfm?qv_pk=2812 Maxim-IC.
The Library
This library is derived from some good work by the Arduino community. This library is, for the most part, purely a refactor version of the existing library. I found the original to be somewhat of a pain to implement and, like most Arduino libraries, code-seperation sucks.
The intention of this Library is to build on Jim Studt work and make it quick and easy for beginners to get started.
Limitations
- The One-Wire library has a nasty look-up table for some associated commands. It isn't directly related to this library but it may cause some problems.
Benefits
- Simple and easy to use
- No software limitation to the number of devices you may use
Pin Definition
The definition of 18B20 Temperature sensor pin is
:#Input
:#Power
:#GND
Connection Diagram
Sample Code
#include <DallasTemperature.h>
DallasTemperature tempSensor;
void setup(void) {
Serial.begin(9600);
tempSensor.begin(2); // Connect DS18B20 to Digital Pin 2
}
void loop(void) {
// Check if the sensor is working correctly
switch(tempSensor.isValid())
{
case 1:
Serial.println("Invalid CRC");
tempSensor.reset(); // Reset Sensor
return;
case 2:
Serial.println("Not a valid device");
tempSensor.reset(); // Reset Sensor
return;
}
// Read Temperature from DS18B20
Serial.print(tempSensor.getTemperature());
Serial.print("C");
Serial.println();
}
Link
shopping 18b20 temerature sensor