Skip to content

Instantly share code, notes, and snippets.

@biomood
Created April 30, 2011 18:54
Show Gist options
  • Save biomood/949877 to your computer and use it in GitHub Desktop.
Save biomood/949877 to your computer and use it in GitHub Desktop.
Arduino temperature sketch
#include <OneWire.h>
#include <DallasTemperature.h>
// pin connected to sensor
int tempPin = 7;
// define the onewire obj needed for connecting to onewire components
OneWire oneWire(tempPin);
// define dallas obj, makes it easier to read temp
DallasTemperature tempSens(&oneWire);
void setup() {
// set up the serial console
Serial.begin(9600);
// initialise the temp sensor
tempSens.begin();
}
void loop() {
// get the current temperature
tempSens.requestTemperatures();
// get the temperature in centigrade
// index 0 as multiple temp sensors can be connected on same bus
float t = tempSens.getTempCByIndex(0);
Serial.println(t);
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment