New code works!
Except, I do not have the sensor yet, so cannot fully test.
Can any of you just read the below code and tell me if you see any problems?
I got all the librarys from the Manage Librarys section on the Arduino IDE Program (Beta on Mac).
Thanks
int LEDTEMP = 42; // High temp at which the LED turns on
int ALARMTEMP = 42; // Overheating temp
int LED = 53; // Pin for LED "on"
int TEMPOK = 52; // LED for when temp is under LEDTEMP
int ALARMLED = 51; // Alarm LED
int ALARMPIN = 50; // Audible alarm for overheating
int HeaterPIN = 0; // Relay for heater
int HumidityPIN = 1; // Humidity PIN
int Humidity = 48; // Humidity level
#include <Servo.h>
#include <Wire.h>
#include <HDC2080.h>
#include <LiquidCrystal.h>
// For Turner
Servo myservo;
int pos = 0;
#define ADDR 0x40
HDC2080 sensor(ADDR);
// For Temp
// Readings used for average
const int numReadings = 10;
// Set variables to zero
float avetemp = 0;
float temp = 0;
float checkdelay = 0;
// For Humidity
// Set variables to zero
float aveHumid = 0;
float Humid = 0;
float temperature = 0, humidity = 0;
void setup() {
// For turner
myservo.attach(13);
// For Heater
pinMode(24, OUTPUT);// connected to S terminal of Relay
Serial.begin(9600);
Serial.println("Temp Monitor Started");
sensor.begin();
sensor.reset();
// Configure Measurements
sensor.setMeasurementMode(TEMP_AND_HUMID); // Set measurements to temperature and humidity
sensor.setRate(ONE_HZ); // Set measurement frequency to 1 Hz
sensor.setTempRes(FOURTEEN_BIT);
sensor.setHumidRes(FOURTEEN_BIT);
//begin measuring
sensor.triggerMeasurement();
pinMode(HeaterPIN,OUTPUT);
pinMode(ALARMPIN,OUTPUT);
pinMode(ALARMLED,OUTPUT);
pinMode(LED,OUTPUT);
pinMode(TEMPOK,OUTPUT);
pinMode(HumidityPIN,OUTPUT);
digitalWrite(HeaterPIN, LOW);
digitalWrite(LED, LOW);
digitalWrite(ALARMLED, LOW);
digitalWrite(TEMPOK, HIGH);
for(int x = 0; x < 5; x++){ // Test Alarm
noTone(ALARMPIN);
delay(100);
}
Serial.print("LED Test Started (5 Seconds) ");
for(int x = 0; x < 5; x++){
Serial.print(".");
delay(1000);
}
Serial.println("Done");
digitalWrite(HeaterPIN, HIGH);
digitalWrite(LED, HIGH);
digitalWrite(ALARMLED, HIGH);
digitalWrite(TEMPOK, LOW);
noTone(ALARMPIN);
//For Humidity
digitalWrite(HumidityPIN, HIGH);
digitalWrite(HumidityPIN, LOW);
Serial.print("Realtime Temp: \t");
}
void loop() {
// For Turner
for (pos = 0; pos <= 80; pos += 1) { // goes from 0 degrees to 80 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(5000); // waits 5000ms for the servo to reach the position
delay(12133333);
}
for (pos = 80; pos >= 0; pos -= 1) { // goes from 80 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(5000); // waits 5000ms for the servo to reach the position
delay(12133333);
// Wait a few seconds between measurements.
delay(100);
temp = 0;
Serial.print("Realtime Temp: \t");
for (int x = 0; x < numReadings; x++){
Serial.print("Temperature(C): "); Serial.print(sensor.readTemp());
Serial.print("\t");
delay(1000); // delay in between reads for stability
}
Serial.println();
avetemp = temp / numReadings; // calculate the average
Serial.print("Average Temp is ");
Serial.println(avetemp); // send it to the computer as ASCII digits
// Check if any reads failed and exit early (to try again).
if (isnan(temp)) {
Serial.println("Failed to read from HDC2080 sensor!");//ln
return;
}
// Set off alarm if overheating
if (avetemp>ALARMTEMP) {
digitalWrite(ALARMLED, HIGH);
Serial.print("Temperature is over ");
Serial.print(ALARMTEMP);
Serial.println(", Alarm is ON");
for(int x = 0; x < 3; x++){ // Sound the alarm for 5 seconds
noTone(ALARMPIN); // Fan should already be running from last loop, if not, it will start right after alarm sounds
delay(500);
noTone(ALARMPIN);
delay(500);
}
noTone(ALARMPIN);
checkdelay = 5000; // Switch the normal 5 min delay to 30 seconds before going through the loop again
} else {
digitalWrite(ALARMLED, LOW);
Serial.print("Temperature is under ");
Serial.print(ALARMTEMP);
Serial.println(", Alarm is OFF");
checkdelay = 5000; // Unless temp is over 120*F the fan runs for 5 minutes before temp is checked again
}
// Turn ON Heater if cabinet is COLD
if (avetemp>LEDTEMP) {
digitalWrite(HeaterPIN, HIGH);
digitalWrite(LED, HIGH);
digitalWrite(TEMPOK, LOW);
Serial.print("Temperature is over ");
Serial.print(LEDTEMP);
Serial.print(", Heater is OFF (for ");
Serial.print(checkdelay / 1000 / 60);
Serial.println(" minutes)");
delay(checkdelay); // turn on minimum of 5 min (unless alarm is going off, then it loops after 30 seconds)
} else {
digitalWrite(HeaterPIN, LOW);
digitalWrite(LED, LOW);
digitalWrite(TEMPOK, HIGH);
Serial.print("Temperature is under ");
Serial.print(LEDTEMP);
Serial.println(", Heater is ON"); // When fan is off, Temp is read every 30 seconds
}
Serial.println();
Serial.println();
//Humidity
if (aveHumid>Humidity) {
digitalWrite(HumidityPIN, HIGH);
digitalWrite(Humidity, HIGH);
} else {
digitalWrite(HumidityPIN, LOW);
digitalWrite(Humidity, LOW);
}
// LCD module connections (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
char temperature[] = "Temp = 00.0 C";
char humidity[] = "RH = 00.0 %";
// set up the LCD's number of columns and rows
lcd.begin(16, 2);
delay(1); // wait 1s between readings
// Read humidity
byte RH =("\t\tHumidity (%): "); byte (sensor.readHumidity());
//Read temperature in degree Celsius
byte Temp =("Temperature(C): "); byte (sensor.readTemp());
// Check if any reads failed and exit early (to try again)
if (isnan(RH) || isnan(Temp)) {
lcd.clear();
lcd.setCursor(5, 0);
lcd.print("Error");
return;
}
temperature[7] = Temp / 10 + 48;
temperature[8] = Temp % 10 + 48;
temperature[11] = 223;
humidity[7] = RH / 10 + 48;
humidity[8] = RH % 10 + 48;
lcd.setCursor(0, 0);
lcd.print("Temp = ");
lcd.setCursor(8, 0);
lcd.print(Temp);
lcd.setCursor(10, 0);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Hum = ");
lcd.setCursor(8, 1);
lcd.print(RH);
lcd.setCursor(10, 1);
lcd.print("%");
}
}