Advertisement
computermuseo

lettura sensore 18B20

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