Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Temperature Controlled Chamber
- #include <LiquidCrystalFast.h> // Library for the 4x20 LCD
- LiquidCrystalFast lcd(6,7,8,9,10,11,12);
- #define tempSensor A0 // TMP36 Temp sensor
- #define lightSwitch 4 // Solid state relay controls the 120v lightbulb
- #define indicator 5 // LED indicator to indicate when heat is on.
- int readings[100]; // Array to store the last 100 ADC readings to average.
- byte readingNumber=0; // Keeps track of where we're at in the array
- long averageMe = 0; // temporary number, probably shouldn't be a global variable?
- float voltage=0; // Used in the conversion from ADC to temperature
- float sensor=0; // Likewise
- float celsius=0; // Ditto
- float fahrenheit=0; // Final temperature value
- float targetTemp=90.0; // TODO: Add buttons to make this user adjustable
- void setup() {
- pinMode(tempSensor, INPUT);
- pinMode(lightSwitch, OUTPUT);
- pinMode(indicator, OUTPUT);
- for (int i = 0; i<100; i++) {
- readings[i] = analogRead(tempSensor); // Quickly fill the array with sane values
- }
- lcd.begin(20,4); // Initialize the LCD
- lcd.setCursor(0,0);
- lcd.print(F("Current: F"));
- lcd.setCursor(0,1);
- lcd.print(F("Target: F"));
- }
- void loop() {
- lcd.setCursor(8,1);
- lcd.print(targetTemp,1);
- lcd.print(" F");
- lcd.setCursor(9,0);
- readings[readingNumber] = analogRead(tempSensor); // Read the current temp and add it to the array
- averageMe = 0;
- for (int i=0; i<100; i++) {
- averageMe += readings[i]; // Take the array's contents and toss it all into this single number
- }
- averageMe = averageMe / 100; // Divide by the total entries to get an average of them all
- voltage=((averageMe*5000)/1024); // borrowed from examples online
- voltage=voltage-500; // I think this one came from Tronixstuff
- celsius=voltage/10; // I thought the TMP36 was a F sensor, so why is it coming up as Celsius?
- fahrenheit=((celsius*1.8)+32); // Maybe I meant to buy the TMP35
- lcd.print(fahrenheit,1);
- lcd.setCursor(14,0);
- lcd.print('F');
- if (readingNumber==99) {
- readingNumber = 0; // Manual FOR loop..
- } else {
- readingNumber++;
- }
- if(fahrenheit < targetTemp) { // If it's not warm enough
- digitalWrite(lightSwitch,HIGH); // Turn on the light (heater)
- digitalWrite(indicator, HIGH);
- }
- else { // If it's too warm
- digitalWrite(lightSwitch,LOW); // Turn off the light (heater)
- digitalWrite(indicator, LOW);
- }
- delay(100); // Don't want to loop TOO fast..
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement