Advertisement
Krzyspx

Dallas

Oct 9th, 2016
3,015
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. // Include the libraries we need
  2. #include <OneWire.h>
  3. #include <DallasTemperature.h>
  4. #define ONE_WIRE_BUS 13 // Data wire is plugged into port 13 on the Arduino
  5.  
  6. OneWire oneWire(ONE_WIRE_BUS);
  7. DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
  8.  
  9. void setup(void)
  10. {
  11.   Serial.begin(9600);
  12.   Serial.println("Dallas Temperature IC Control Library Demo");
  13.   sensors.begin();   // Start up the library
  14. }
  15.  
  16. void loop(void)
  17. {
  18.   // call sensors.requestTemperatures() to issue a global temperature  request to all devices on the bus
  19.   Serial.print("Requesting temperatures...");
  20.   sensors.requestTemperatures(); // Send the command to get temperatures
  21.   Serial.println("DONE");
  22.   // After we got the temperatures, we can print them here.
  23.   // We use the function ByIndex, and as an example get the temperature from the first sensor only.
  24.   Serial.print("Temperature for the device 1 (index 0) is: ");
  25.   Serial.println(sensors.getTempCByIndex(0));  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement