Advertisement
UnaClocker

Hotbox Controller

Apr 3rd, 2012
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. // Temperature Controlled Chamber
  2.  
  3. #include <LiquidCrystalFast.h> // Library for the 4x20 LCD
  4.  
  5. LiquidCrystalFast lcd(6,7,8,9,10,11,12);
  6.  
  7. #define tempSensor A0  // TMP36 Temp sensor
  8. #define lightSwitch 4  // Solid state relay controls the 120v lightbulb
  9. #define indicator 5 // LED indicator to indicate when heat is on.
  10. int readings[100];  // Array to store the last 100 ADC readings to average.
  11. byte readingNumber=0;  // Keeps track of where we're at in the array
  12. long averageMe = 0;  // temporary number, probably shouldn't be a global variable?
  13. float voltage=0; // Used in the conversion from ADC to temperature
  14. float sensor=0;  // Likewise
  15. float celsius=0;  // Ditto
  16. float fahrenheit=0; // Final temperature value
  17. float targetTemp=90.0;  // TODO: Add buttons to make this user adjustable
  18.  
  19. void setup() {
  20.   pinMode(tempSensor, INPUT);
  21.   pinMode(lightSwitch, OUTPUT);
  22.   pinMode(indicator, OUTPUT);
  23.   for (int i = 0; i<100; i++) {
  24.     readings[i] = analogRead(tempSensor); // Quickly fill the array with sane values
  25.   }
  26.   lcd.begin(20,4); // Initialize the LCD
  27.   lcd.setCursor(0,0);
  28.   lcd.print(F("Current:    F"));
  29.   lcd.setCursor(0,1);
  30.   lcd.print(F("Target:    F"));
  31. }
  32.  
  33. void loop() {
  34.   lcd.setCursor(8,1);
  35.   lcd.print(targetTemp,1);
  36.   lcd.print(" F");
  37.   lcd.setCursor(9,0);
  38.   readings[readingNumber] = analogRead(tempSensor); // Read the current temp and add it to the array
  39.   averageMe = 0;
  40.   for (int i=0; i<100; i++) {
  41.     averageMe += readings[i]; // Take the array's contents and toss it all into this single number
  42.   }
  43.   averageMe = averageMe / 100; // Divide by the total entries to get an average of them all
  44.             voltage=((averageMe*5000)/1024); // borrowed from examples online
  45.             voltage=voltage-500;  // I think this one came from Tronixstuff
  46.             celsius=voltage/10; // I thought the TMP36 was a F sensor, so why is it coming up as Celsius?
  47.             fahrenheit=((celsius*1.8)+32); // Maybe I meant to buy the TMP35
  48.   lcd.print(fahrenheit,1);
  49.   lcd.setCursor(14,0);
  50.   lcd.print('F');
  51.   if (readingNumber==99) {
  52.     readingNumber = 0; // Manual FOR loop..
  53.   } else {
  54.     readingNumber++;
  55.   }
  56.   if(fahrenheit < targetTemp) { // If it's not warm enough
  57.       digitalWrite(lightSwitch,HIGH); // Turn on the light (heater)
  58.       digitalWrite(indicator, HIGH);
  59.   }
  60.   else { // If it's too warm
  61.     digitalWrite(lightSwitch,LOW); // Turn off the light (heater)
  62.     digitalWrite(indicator, LOW);
  63.   }
  64.   delay(100); // Don't want to loop TOO fast..
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement