Guest User

Untitled

a guest
Dec 8th, 2014
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Shameless based on https://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor
  2. // Modded for http://www.instructables.com/community/solar-garage-heater/
  3.  
  4. //TMP36 Pin Variables
  5. int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
  6.                         //the resolution is 10 mV / degree centigrade with a
  7.                         //500 mV offset to allow for negative temperatures
  8. int switchPin = 2;  // On this digital 5V-pin, you connect the switch for the fan.
  9. int turnontemperature = 70; // If this temperature in deg F (no decimals!) is crossed, it will turn on the fan to draw warm air from the hotbox.
  10.  
  11. /*
  12.  * setup() - this function runs once when you turn your Arduino on
  13.  * We initialize the serial connection with the computer
  14.  */
  15. void setup()
  16. {
  17.   Serial.begin(9600);  //Start the serial connection with the computer
  18.                        //to view the result open the serial monitor
  19. }
  20.  
  21. void loop()                     // run over and over again
  22. {
  23.    //getting the voltage reading from the temperature sensor
  24.   int reading = analogRead(sensorPin);  
  25.  
  26.   // converting that reading to voltage, for 3.3v arduino use 3.3
  27.   float voltage = reading * 5.0;
  28.   voltage /= 1024.0;
  29.  
  30.   // print out the voltage
  31.   Serial.print(voltage); Serial.println(" volts");
  32.  
  33.   // now print out the temperature
  34.   float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
  35.                                                //to degrees ((voltage - 500mV) times 100)
  36.   // now convert to Fahrenheit
  37.   float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  38.   Serial.print(temperatureF); Serial.println(" degrees F");
  39.  
  40.   if(temperatureF<turnontemperature){
  41.     digitalWrite(switchPin, HIGH);   // Too cold! Turns ON the Fan
  42.   }
  43.   else{
  44.     digitalWrite(switchPin, LOW);   // Warm enough: Turn OFF the fan
  45.   }
  46.  
  47.   ; Check every 10 seconds
  48.   for (int i=0; i <= 10; i++){
  49.     delay(1000);  
  50.   }
  51.  
  52.  
  53.  
  54. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×