Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3.  
  4. // Data wire is plugged into pin 2 on the Arduino
  5. #define ONE_WIRE_BUS 2
  6.  
  7. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  8. OneWire oneWire(ONE_WIRE_BUS);
  9.  
  10. // Pass our oneWire reference to Dallas Temperature.
  11. DallasTemperature sensors(&oneWire);
  12.  
  13. void setup(void)
  14. {
  15. // start serial port
  16. Serial.begin(9600);
  17. Serial.println("Dallas Temperature IC Control Library Demo");
  18.  
  19. // Start up the library
  20. sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
  21. }
  22.  
  23.  
  24. void loop(void)
  25. {
  26. // call sensors.requestTemperatures() to issue a global temperature
  27. // request to all devices on the bus
  28. Serial.println("Requesting temperatures...");
  29. sensors.requestTemperatures(); // Send the command to get temperatures
  30. Serial.println("DONE");
  31. delay(500);
  32. Serial.print("Temperature for Device 1 is: ");
  33.  
  34. Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement