Skip to content

Instantly share code, notes, and snippets.

@AdamLoi
Created June 26, 2014 13:01
Show Gist options
  • Save AdamLoi/8f9fdd2e21d813e2f08b to your computer and use it in GitHub Desktop.
Save AdamLoi/8f9fdd2e21d813e2f08b to your computer and use it in GitHub Desktop.
DS18B20
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print("Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.println("DONE");
Serial.print("Temperature for the device 1 (index 0) is: ");
Serial.println(sensors.getTempCByIndex(0));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment