forked from DHTScienceGuy/Incubator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChickenIncubatorCode.txt
67 lines (51 loc) · 1.62 KB
/
ChickenIncubatorCode.txt
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
//The Chicken Incubator Code
#include "DHT.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//Alternatively, sainsmart backlit LCD with button shield uses these pins:
//LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
#define DHTPIN A2 // what pin we're connected to
#define RELAY 7
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 22 (AM2302)
//
// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor
// This is what I would use, You can choose your own pin
DHT dht(DHTPIN, DHTTYPE);
void setup() {
pinMode(RELAY, OUTPUT);
lcd.begin(16,2);
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
float t = dht.readTemperature();
// check if returns are valid, if they are NaN (not a number) then something went wrong!
if (isnan(t) || isnan(h)) {
lcd.println("Failed to read from DHT");
} else {
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print(" %\t");
lcd.setCursor(1,0);
lcd.print("Temp: ");
lcd.print(t);
lcd.println("*C ");
if (t > 37.5)//37.5C = 99.5F for Chickens. Quail, try 38.3C = 101F. Forced air temps should be lower.
{
digitalWrite(7,HIGH);
}
else
{digitalWrite(7,LOW);
}
delay(500);
}
}