Created
April 30, 2011 18:54
-
-
Save biomood/949877 to your computer and use it in GitHub Desktop.
Arduino temperature sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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