Skip to content

Instantly share code, notes, and snippets.

@Ozsie
Last active January 8, 2018 09:48
Show Gist options
  • Save Ozsie/aae65115ee4856445efccb97cd9eefd3 to your computer and use it in GitHub Desktop.
Save Ozsie/aae65115ee4856445efccb97cd9eefd3 to your computer and use it in GitHub Desktop.
Read temperature
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 // DS18B20 pin
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
void setup() {
Serial.begin(115200);
Serial.println("Hello World");
}
void loop() {
int temp;
do {
DS18B20.requestTemperatures();
temp = DS18B20.getTempCByIndex(0);
Serial.print("Temperature: ");
Serial.println(temp);
delay(100);
} while ((temp != 85.0 || temp == (-127.0)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment