Created
July 29, 2013 02:59
-
-
Save boxalljohn/6101909 to your computer and use it in GitHub Desktop.
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
/* | |
example 2.1 - digital thermometer | |
Created 14/04/2010 --- By John Boxall --- http://tronixstuff.com --- CC by-sa v3.0 | |
Uses an Analog Devices TMP36 temperature sensor to measure temperature and output values to the serial connection | |
Pin 1 of TMP36 to Arduino 5V power socket | |
Pin 2 of TMP36 to Arduino analog 0 socket | |
Pin 3 of TMP36 to Arduino GND socket | |
*/ | |
void setup() | |
{ | |
Serial.begin(9600); // activate the serial output connection | |
} | |
float voltage = 0; // setup some variables | |
float sensor = 0; | |
float celsius = 0; | |
float fahrenheit = 0; | |
void loop() | |
{ // let's get measurin' | |
sensor = analogRead(0); | |
voltage = (sensor*5000)/1024; // convert raw sensor value to millivolts | |
voltage = voltage-400; // remove voltage offset | |
celsius = voltage/10; // convert millivolts to Celsius | |
fahrenheit = ((celsius * 1.8)+32); // convert celsius to fahrenheit | |
Serial.print("Temperature: "); | |
Serial.print(celsius,2); | |
Serial.println(" degrees C"); | |
Serial.print("Temperature: "); | |
Serial.print(fahrenheit,2); | |
Serial.println(" degrees F"); | |
Serial.println("_ _ _ _ _ _ _ _ _ _ _ _ _ _ "); | |
delay (1000); // wait a second, otherwise the serial monitor box will be too difficult to read | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment