SHARE
TWEET

TMP36 + RCSwitch Arduino Temperature Controller Demo

w0lfiesmith Aug 22nd, 2013 9,671 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. #include <RCSwitch.h> //only used for remote control switches, not used if you have a relay
  3.  
  4. #define aref_voltage 3.3         // we tie 3.3V to ARef and measure it with a multimeter!
  5.  
  6. //TMP36 Pin Variables
  7. int tempPin = 1;        
  8. int tempReading;
  9.  
  10. float desiredTempC = 28; // which temperature to maintain
  11.  
  12. RCSwitch mySwitch = RCSwitch();  
  13.  
  14. void setup(void) {
  15.   // We'll send debugging information via the Serial monitor
  16.   Serial.begin(9600);  
  17.   // If you want to set the aref to something other than 5v
  18.   analogReference(EXTERNAL);
  19.   //enable RC switch transmissions on pin 10.
  20.   mySwitch.enableTransmit(8);
  21. }
  22.  
  23.  
  24. void loop(void) {
  25.  
  26.   tempReading = analogRead(tempPin);  
  27.  
  28.   // converting that reading to voltage, which is based off the reference voltage
  29.   float voltage = tempReading * aref_voltage;
  30.   voltage /= 1024.0;
  31.  
  32.   // now print out the temperature
  33.   float temperatureC = (voltage - 0.5) * 100 ;  
  34.   Serial.print(temperatureC); Serial.println(" degrees C");
  35.  
  36.   /* now convert to Fahrenheight
  37.   float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  38.   Serial.print(temperatureF); Serial.println(" degrees F");
  39.    */
  40.    
  41.   if(temperatureC < desiredTempC){
  42.     mySwitch.switchOn(1,1);
  43.     Serial.println("Heater ON");
  44.   }
  45.   else{
  46.     Serial.println("Heater OFF");
  47.     mySwitch.switchOff(1,1);
  48.   }
  49.    
  50.    
  51.   delay(1000);
  52. }
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