Advertisement
Krzyspx

Dallas

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