Ok, to start from the beginning…
I’m trying to build an egg incubator, mostly for fun, but also because i soon will need one as i have quails, and to buy a nice quality incubator cost a lot of $$$… and ofc that was a good reason to buy an arduino instead and try to build it my self…
Underway while experimenting with the different sensors and stuff i bought, I found this http://forum.arduino.cc/index.php?topic=223286.0 that i think gives a great way to make many small scripts come together, and the code looks neat and clean after.
I have basically no C++ programming skills, but i have done some html and php.
But now i have a problem, because my script validates and uploads to my arduino, but nothing happens!
I even tried with other example codes to test the pins, and they work fine, the whole unit seems to work just fine… but after uploading my script, i get nothing…
so now i hope some of you can help, as i’ve stared my self blind on the problem…
Ok, here is the code:
// ----------LIBRARIES--------------
#include "DHT.h"
// --------CONSTANTS (won't change)---------------
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
const int fanHumPin = 10; // the pin numbers for humidity +
const int heaterPin = 11; // the pin numbers for heater +
const int fanExitPin = 12; // the pin numbers for hum - and heater -
const int tempMin = 37; // in celcius
const int tempMax = 38; // in celcius
const int humMin = 65; // in %RH
const int humMax = 67; // in %RH
//------------ VARIABLES (will change)---------------------
byte fanHumState = LOW; // used to record whether the unit are on or off
byte heaterState = LOW; // LOW = off
byte fanExitState = LOW;
float rhDHT = dht.readHumidity();
float tempDHT = dht.readTemperature();
//========================================
void setup() {
Serial.begin(9600);
Serial.println("starting...");
// set the Led pins as output:
pinMode(fanHumPin, OUTPUT);
pinMode(heaterPin, OUTPUT);
pinMode(fanExitPin, OUTPUT);
dht.begin();
}
//========================================
void loop() {
delay(2000);
float rhDHT = dht.readHumidity();
float tempDHT = dht.readTemperature();
humControl();
heatControl();
changeRelay();
serialPrint();
}
//============== humControl ================
void humControl() {
if(rhDHT < humMin) {
fanHumState = HIGH;
}
if(rhDHT >= humMax) {
fanHumState = LOW;
}
}
//============== heatControl ================
void heatControl() {
if(tempDHT < tempMin) {
heaterState = HIGH;
}
if(tempDHT >= tempMax) {
heaterState = LOW;
}
}
//============== exitFanControl ================
void exitFanControl() {
if(rhDHT > humMax || tempDHT > tempMax) {
fanExitState = HIGH;
}
else {
fanExitState = LOW;
}
}
//=============== change relays ===============
void changeRelay() {
digitalWrite(fanHumPin, fanHumState);
digitalWrite(heaterPin, heaterState);
digitalWrite(fanExitPin, fanExitState);
}
//============ serial.print =============
void serialPrint() {
Serial.print("Temp: ");
Serial.print(tempDHT);
Serial.println("*C");
Serial.print("RH: ");
Serial.print(rhDHT);
Serial.println("%");
Serial.println("------------------");
}
If you got any idea, please feel free to