In this example project we will be combining an Arduino and DS18B20 sensor. The DS18B20 is also called 1-wire digital temperature sensor
Arduino and DS18B20 Temperature Sensor The DS18B20 comes in different forms and shapes, so you have plenty of choice when deciding which one works best for you. There are 3 variations available: 8-Pin SO (150 mils), 8-Pin µSOP, and 3-Pin TO-92.
I have used waterproof version as shown below.
Note: DS18B20 is quite versatile. It can be powered through the data line (so called “parasite” mode, which requires only 2 wires versus 3 in normal mode), it operates in a 3.0V to 5.5V range, measures Temperatures from -55°C to +125°C (-67°F to +257°F) with and ±0.5°C Accuracy (from -10°C to +85°C). It converts a temperature in 750ms or less to a up to 12 bits value. Another cool feature is that you can connect up to 127 of these sensors in parallel, and read each individual temperature.
Things you need to get Arduino and DS18B20 sensor work:
- Arduino IDE to program the code and upload
- OneWire and DallasTemperatre library for the Arduino and DS18B20
- One DS18B20 digital temperature sensor
- Arduino UNO R3
- Jumper wires
- Breadboard/PC/General purpose board
- Arduino UNO cable
Below is the schematic diagram for the same.
Step 2: Installing and loading OneWire and DallasTemperature Library
Unzip the downloaded zip file. Make sure that folder name is OneWire, which contains the library. Drag it into the Library folder of Arduino IDE. Alternatively you can use Sketch-> Import Library -> Add Library option of Arduino IDE and select the Zip file.
Step3: Writing code and uploading
// Data wire is plugged into digital pin2
#define ONE_WIRE_BUS 2
Serial.print(" Fetching temperature...");
sensors.requestTemperatures(); // send command to get temperatures
Serial.println("Temperature is ");
Output will be shown as follows:
Screenshot of the above example:
We can modify this to display it in LCD display. For details on how to display the temperature on LCD display visit my post How to connect 16*2 LCD display Arduino UNO