Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Include the libraries we need
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define ONE_WIRE_BUS 13 // Data wire is plugged into port 13 on the Arduino
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
- void setup(void)
- {
- Serial.begin(9600);
- Serial.println("Dallas Temperature IC Control Library Demo");
- sensors.begin(); // Start up the library
- }
- void loop(void)
- {
- // call sensors.requestTemperatures() to issue a global temperature request to all devices on the bus
- Serial.print("Requesting temperatures...");
- sensors.requestTemperatures(); // Send the command to get temperatures
- Serial.println("DONE");
- // After we got the temperatures, we can print them here.
- // We use the function ByIndex, and as an example get the temperature from the first sensor only.
- Serial.print("Temperature for the device 1 (index 0) is: ");
- Serial.println(sensors.getTempCByIndex(0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement