SHARE
TWEET

Untitled

a guest Aug 27th, 2015 168 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Sensor test sketch
  2.   for more information see http://www.ladyada.net/make/logshield/lighttemp.html
  3.   */
  4.  
  5. #define aref_voltage 3.3         // we tie 3.3V to ARef and measure it with a multimeter!
  6.  
  7.  
  8.  
  9.  
  10. //TMP36 Pin Variables
  11. int tempPin = A0;        //the analog pin the TMP36's Vout (sense) pin is connected to
  12.                         //the resolution is 10 mV / degree centigrade with a
  13.                         //500 mV offset to allow for negative temperatures
  14. unsigned long tempReading;        // the analog reading from the sensor
  15.  
  16. bool flag = 0;  // For telling if we were on or off before
  17.  
  18. void setup(void) {
  19.   // We'll send debugging information via the Serial monitor
  20.   Serial.begin(115200);  
  21.   pinMode(2, OUTPUT);
  22.  
  23.   // If you want to set the aref to something other than 5v
  24.   analogReference(EXTERNAL);
  25. }
  26.  
  27.  
  28. void loop(void) {
  29.   tempReading = 0;
  30.  
  31.   for(int  i = 0; i < 1000; i++){
  32.     tempReading += analogRead(tempPin);
  33.   }
  34.  
  35.   tempReading /= 1000; // Average a few reads.
  36.  
  37.   // converting that reading to voltage, which is based off the reference voltage
  38.   float voltage = tempReading * aref_voltage;
  39.   voltage /= 1024.0;
  40.  
  41.   // now print out the temperature
  42.   float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
  43.                                                //to degrees ((volatge - 500mV) times 100)
  44.   // now convert to Fahrenheight
  45.   float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  46.   Serial.println(temperatureF);
  47.  
  48.   if (temperatureF > 95) {
  49.     digitalWrite(2, HIGH);
  50.     if (flag == 0){
  51.       flag = 1;
  52.       Serial.println("fan_turned_on");
  53.     }
  54.   } else if (temperatureF < 90) {
  55.     digitalWrite(2, LOW);
  56.     if (flag == 1){
  57.       flag = 0;
  58.       Serial.println("fan_turned_off");
  59.     }
  60.   }
  61.  
  62.   delay(5000);
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top