I've made a modification to the Sparkfun CIRC-10 project. When the TMP36 temperatre sensor reaches a threshold value (an integer) an LED turns on. When the the reading goes below the threshold value, the LED goes out.
The change seem to work pretty reliably with the board connected to the USB port of my PC. I hold the sensor between my fingers and watch the temparature value increase on the serial monitor. LED lights when treshold value reached.
However, when I use a different power source - such as a 9 volt plug, the LED lights, and stays lit. Does the TMP36 sensor not like a 9 volt powersupply? Does it need more voltage?
The code modification to CIRC-10 is below.
Thanks.
/* ---------------------------------------------------------
* | Arduino Experimentation Kit Example Code |
* | tempLED .: Temperature :. (TMP36 Temperature Sensor) |
* ---------------------------------------------------------
*
* A simple rewrite of CIRC-10 to output the current temperature to the IDE's debug window.
* Changes: when the TMP36 sensor goes above a treshold value, the LED will light (voltage HIGH)
* When the sensor goes below the threshold value the LED goes out (voltage LOW)
*
* For more details on the original CIRC-10 circuit: http://tinyurl.com/c89tvd
*/
//TMP36 Pin Variables
int ledPin = 7; // digital pin of LED <--- change: added digial pin 7 for LED
int threshold = 26; // threshold value of 26 degrees centigrade <--- change
int temperaturePin = 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
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
pinMode(ledPin,OUTPUT); // set the mode of ledPin to OUTPUT
//Serial.begin(9600); //Start the serial connection with the copmuter
//to view the result open the serial monitor
//last button beneath the file bar (looks like a box with an antenae)
}
void loop() // run over and over again
{
float temperature = getVoltage(temperaturePin); //getting the voltage reading from the temperature sensor
temperature = (temperature - .5) * 100; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
//Serial.println(temperature); //printing the result
delay(1000); //waiting a second
if (temperature >= threshold){
//Serial.println("threshold reached");
digitalWrite(ledPin,HIGH);}
else {digitalWrite(ledPin,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
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.