In this lesson, we will show how to use the DS18B20 Temperature Sensor with an Osoyoo UNO, we will monitor the output of the DS18B20 Temperature Sensor. With this sensor you can get the temperature in your room, car, whatever.
Arduino IDE (version 1.6.4+)
Arduino library: OneWire.h
Arduino library: DallasTemperature.h
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. If you look at online shop, some friends have packaged the TO-92 version in a waterproof housing so you can use it directly in your fish-tank, water boiler, outside your house or even your freezer, without having to worry about water/moisture shortcutting your electronics (these have 3 wires: Black (GND), Red (Vdd) and white or yellow (Data)).
DS18b20 – Available Packages DS18B20 in a waterproof casing
The 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. Not sure what I’d do with that, but the ability to combine one or two, for example for the temperature of your fridge and freezer, is a nice option, specially when other pins of your Arduino are being used for other things …
The three pins of the Temperature Sensor are:
This is DS18B20 digital temperature sensor for Arduino -55°C~125°C
Digital signal output
Detect ambient air temperature
Compatible with Arduino DIY project and other DIY projects
Resolution adjustment range :9-12
With mounting holes for easy installation, Aperture: 2.5
Temperature measuring range: -55 ~ +125 ℃
Temperature measurement accuracy: 0.5 ℃
Working voltage: DC 5V/DC 3.3V
The connection scheme is very easier. We have only three pins to connect. Connect the temperature module to the Arduino as shown in the figure.
You’ll need to install the OneWire Library and DallasTemperature Library.
After installing the needed libraries, upload the following code to your Arduino board.
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensors.begin();
}
void loop(void){
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print(sensors.getTempCByIndex(0));
Serial.print(" - Fahrenheit temperature: ");
Serial.println(sensors.getTempFByIndex(0));
delay(1000);
}
Finally, you should open the Arduino IDE serial monitor at a 9600 baud rate and you’ll see the temperature displayed in both Celsius and Fahrenheit:
DownLoad Url osoyoo.com