Skip to content

Instantly share code, notes, and snippets.

@AtumRa
Last active January 2, 2016 07:28
Show Gist options
  • Save AtumRa/8269824 to your computer and use it in GitHub Desktop.
Save AtumRa/8269824 to your computer and use it in GitHub Desktop.
This is code I modified for an lm34 that uses Fahrenheit instead of Celsius. Get the original code from oomlout with the link below.
/* ---------------------------------------------------------
* | Arduino Experimentation Kit Example Code |
* | CIRC-10 .: Temperature :. (TMP36 Temperature Sensor) |
* ---------------------------------------------------------
*
* A simple program to output the current temperature to the IDE's debug window
*
* For more details on this circuit: http://www.oomlout.com/oom.php/products/ardx/circ-10 */
//TMP36 Pin Variables
int tempPin0 = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade
//(500 mV offset) to make negative temperatures an option
int tempPin1 = 1;
int led = 13;
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
//last button beneath the file bar (looks like a box with an antenae)
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
void loop() // run over and over again
{
float temp0 = getVoltage(tempPin0); //getting the voltage reading from the temperature sensor
temp0 = temp0 * 100; //the lm34 is already scaled to Fahrenheit
float temp1 = getVoltage(tempPin1); //getting the voltage reading from the temperature sensor
temp1 = temp1 * 100; //the lm34 is already scaled to Fahrenheit
Serial.print(temp0); //printing the result temp0
// delay(1000); //waiting 1 second
Serial.print(" - ");
Serial.println(temp1); //printing the result temp1
delay(1000); //waiting 1 second
if (temp1-temp0>10)
{
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
}
else
{
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
}
}
/*
* getVoltage() - returns the voltage on the analog input defined by
* pin
*/
float getVoltage(int pin){
return (analogRead(pin) * .004882814); //converting from a 0 to 1023 digital range
// to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment