public
Created

Cigar Temperature/Humidity monitor using a Teensy ( http://www.pjrc.com/teensy/ ) and a DHT11 temperature/humidity sensor ( http://www.adafruit.com/products/386 )

  • Download Gist
gistfile1.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
/*-----( Import needed libraries )-----*/
#include <dht11.h>
#include <Morse.h>
 
/*-----( Setup pins )-----*/
int ledPin = 13;
#define DHT11PIN 1
 
/*-----( Settings )-----*/
int sleepDelay = 5000;
int morseDelay = 110;
// http://en.wikipedia.org/wiki/Humidor
// and http://www.cigar.com/cs/forums/thread/611022.aspx
float fahrenheitTriggerLow = 55;
float fahrenheitTriggerHigh = 77;
float humidityTriggerLow = 62;
float humidityTriggerHigh = 75;
 
// Alert triggers
boolean alertTriggered;
boolean tempHigh;
boolean tempLow;
boolean humidityHigh;
boolean humidityLow;
 
 
// Global Variables
float fahrenheit;
float humidity;
 
// Setup Objects
Morse morse(ledPin, morseDelay);
dht11 DHT11;
 
 
void setup() {
alertTriggered = false;
tempLow = false;
tempHigh = false;
humidityHigh = false;
humidityLow = false;
Serial.begin(38400);
}
 
void alert() {
Serial.println("Alerting...");
 
if (tempHigh) {
Serial.println("\tTemp high alert...");
// TH and a pause
morse.t();
morse.h();
morse.wordPause();
}
 
if (tempLow) {
Serial.println("\tTemp low alert...");
// TL
morse.t();
morse.l();
morse.wordPause();
}
 
if (humidityHigh) {
Serial.println("\tHumidity high alert...");
// HH and a pause
morse.h();
morse.h();
morse.wordPause();
}
 
if (humidityLow) {
Serial.println("\tHumidity low alert...");
// HL
morse.h();
morse.l();
morse.wordPause();
}
 
}
 
double Fahrenheit(double celsius) {
return 1.8 * celsius + 32;
}
 
 
void loop()
{
// Get and check temperature and humidity
int chk = DHT11.read(DHT11PIN);
fahrenheit = Fahrenheit(DHT11.temperature);
humidity = DHT11.humidity;
Serial.print("Temperature: ");
Serial.print(fahrenheit);
Serial.println(" F");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
// check if we are over our threshold
if (fahrenheit > fahrenheitTriggerHigh) {
alertTriggered = true;
tempHigh = true;
Serial.print("\t");
Serial.print(fahrenheit);
Serial.print("F is over our limit of ");
Serial.print(fahrenheitTriggerHigh);
Serial.println("F. Setting alert");
}
// check if we are under our threshold
if (fahrenheit < fahrenheitTriggerLow) {
alertTriggered = true;
tempLow = true;
Serial.print("\t");
Serial.print(fahrenheit);
Serial.print("F is under our limit of ");
Serial.print(fahrenheitTriggerLow);
Serial.println("F. Setting alert");
}
 
// check if we are over our threshold
if (humidity > humidityTriggerHigh) {
alertTriggered = true;
humidityHigh = true;
Serial.print("\t");
Serial.print(humidity);
Serial.print("% is over our limit of ");
Serial.print(humidityTriggerHigh);
Serial.println("%. Setting alert");
}
// check if we are under our threshold
if (humidity < humidityTriggerLow) {
alertTriggered = true;
humidityLow = true;
Serial.print("\t");
Serial.print(humidity);
Serial.print("% is under our limit of ");
Serial.print(humidityTriggerLow);
Serial.println("F. Setting alert");
}
// Alerting
// Check if our alert has been triggered
if (alertTriggered) {
alert();
} else {
morse.dot();
}
// Reset alert status for our next round of checks
alertTriggered = false;
tempLow = false;
tempHigh = false;
humidityHigh = false;
humidityLow = false;
delay(sleepDelay);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.