(The sketch that I want to use the custom library in)
//----------LIBRARIES----------//
#include <TimeLib.h> //Used by the alarm system. Might have to delete this as a duplicate?
#include <TimeAlarms.h> //Used by the alarm system. Might have to delete this as a duplicate?
#include <DHT.h>
//----------CONSTANTS----------//
#define DHTPIN 2 //Data pin from the sensor connects to Arduino pin# 2.
#define DHTTYPE DHT11 //DHT 11 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //Initializes the DHT sensor for normal 16mhz Arduinos.
//----------GLOBAL VARIABLES----------//
int temperature = 0; //Used by the temperature sensor. Real-time temperature data (F).
int chk;
float hum; //Stores humidity value.
float temp; //Stores temperature value.
const int InlineFan = 13; //Names Arduino pin# 13 Inline Fan.
const int PcFans = 12; //Names Arduino pin# 13 Inline Fan.
const int HeatingElement = 11; //Names Arduino pin# 13 Inline Fan.
//-------------------------//
//----------SETUP----------//
//-------------------------//
void setup()
{
Serial.begin(9600);
dht.begin();
setTime(8, 29, 58, 1, 1, 11); //Used by the alarm system. Sets the time to Saturday 8:29:00am Jan 1 2011
pinMode(13, OUTPUT); //Sets Arduino pin# 13 as an output.
pinMode(12, OUTPUT); //Sets Arduino pin# 12 as an output.
pinMode(11, OUTPUT); //Sets Arduino pin# 11 as an output.
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
}
//------------------------//
//----------LOOP----------//
//------------------------//
void loop()
{
digitalClockDisplay(); //Used by the alarm system. Displays the clock printout in the serial monitor.
TemperatureControl(); //Calls the TemperatureControl function.
}
//----------FUNCTIONS----------//
void TemperatureControl()
{
hum = dht.readHumidity(); //Read data and store it to variable hum
temp = dht.readTemperature(true); //Read data and store it to variable temp
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print("%, Temperature: ");
Serial.print(temp);
Serial.println("(F)");
delay(1000); //Delay 1 sec.
HighTemperature(); //Calls the HighTemperature function.
LowTemperature(); //Calls the LowTemperature function.
HighHumidity(); //Calls the HighHumidity function.
}
void HighTemperature()
{
if (temp >= 85) //If the temperature in the growing chamber rises above 85(F):
{
Serial.write(1);
digitalWrite(InlineFan, HIGH); //Turn ON the relay for the Inline Fan.
digitalWrite(PcFans, HIGH); //Turn ON the relay for the PC fans.
TempTooHighTextMessage();
}
else if (temp <= 77) //Once the temperature in the growing chamber drops to 77(F) or below:
{
Serial.write(2);
digitalWrite(InlineFan, LOW); //Turns OFF the relay for the Inline Fan.
digitalWrite(PcFans, LOW); //Turns OFF the relay for the PC fans.
TempTooHighClearedTextMessage();
}
}
void LowTemperature()
{
if (temp <= 70) //If the tempature in the growing chamber drops below 70(F):
{
Serial.write(3);
digitalWrite(HeatingElement, HIGH); //Turn ON the relay for the Heating Element.
TempTooLowTextMessage();
}
else if (temp >= 76) //Once the growing chamber temperature rises back up to 76(F) or greater:
{
Serial.write(4);
digitalWrite(HeatingElement, LOW); //Turn OFF the relay for the Heating Element.
TempTooLowClearedTextMessage();
}
}
void HighHumidity()
{
if (hum >= 75) //If the humidity in the growing chamber rises above 70%:
{
Serial.write(5);
digitalWrite(InlineFan, HIGH); //Turn ON the relay for the Inline Fan.
digitalWrite(PcFans, HIGH); //Turn ON the relay for the PC fans.
HumidTooHighTextMessage();
}
else if (hum <= 65) //Once the humidity in the growing chamber drops to 65% or below:
{
Serial.write(6);
digitalWrite(InlineFan, LOW); //Turns OFF the relay for the Inline Fan.
digitalWrite(PcFans, LOW); //Turns OFF the relay for the PC fans.
HumidTooHighClearedTextMessage();
}
}
void digitalClockDisplay()
{
//Digital clock display of the time.
Serial.print(hour());
printDigits(minute());
printDigits(second());
Serial.println();
}
void printDigits(int digits)
{
Serial.print(":");
if (digits < 10)
Serial.print('0');
Serial.print(digits);
}