TwoPin_DS18B20.ino 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // FILE: TwoPin_DS18B20.ino
  3. // AUTHOR: Rob Tillaart
  4. // VERSION: 0.1.00
  5. // PURPOSE: two pins for two sensors demo
  6. // DATE: 2014-06-13
  7. // URL: http://forum.arduino.cc/index.php?topic=216835.msg1764333#msg1764333
  8. //
  9. // Released to the public domain
  10. //
  11. #include <OneWire.h>
  12. #include <DallasTemperature.h>
  13. #define ONE_WIRE_BUS_1 2
  14. #define ONE_WIRE_BUS_2 4
  15. OneWire oneWire_in(ONE_WIRE_BUS_1);
  16. OneWire oneWire_out(ONE_WIRE_BUS_2);
  17. DallasTemperature sensor_inhouse(&oneWire_in);
  18. DallasTemperature sensor_outhouse(&oneWire_out);
  19. void setup(void)
  20. {
  21. Serial.begin(9600);
  22. Serial.println("Dallas Temperature Control Library Demo - TwoPin_DS18B20");
  23. sensor_inhouse.begin();
  24. sensor_outhouse.begin();
  25. }
  26. void loop(void)
  27. {
  28. Serial.print("Requesting temperatures...");
  29. sensor_inhouse.requestTemperatures();
  30. sensor_outhouse.requestTemperatures();
  31. Serial.println(" done");
  32. Serial.print("Inhouse: ");
  33. Serial.println(sensor_inhouse.getTempCByIndex(0));
  34. Serial.print("Outhouse: ");
  35. Serial.println(sensor_outhouse.getTempCByIndex(0));
  36. }