also, definitely connecting 5v to red sensor wire, gnd to black wire, and input to yellow. I have not tried another pin on the arduino. If so, can I just declare the new pin number before void setup without a pinMode declaration?
Code: Select all
#include "DHT.h"
#include <Servo.h>
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE); //dht has 5v vcc with 10k pullup between vcc and data
Servo exhaustServo;
Servo intakeServo;
const int circFan = 5; //include tx to serial lcd on pin 1 arduino lcd has 5v vcc
const int exhaustFan=6;
const int heatLight=7;
const int photocell=A0;
float dayTempHigh=25; //high with light =77F
float dayTempLow=23;
float nightTempHigh=17;//high without light=62F
float nightTempLow=16;
int lightValue=0;
int state=LOW;
/*photocell placed on back side of chamber, third shelf from bottom, fascing high bay
lights, 10k resistor. Value is 770 with both heat lamps, 945-950 with one high bay,
965-970 with both high bays.*/
unsigned long fanStartTime=0;
unsigned long fanInterval=600000;
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
exhaustServo.attach(8);
intakeServo.attach(9);
pinMode (circFan, OUTPUT);
pinMode (exhaustFan, OUTPUT);
pinMode (heatLight, OUTPUT);
dht.begin();
}
void loop() {
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)) {
Serial.println("Failed to read from DHT");
} else {
Serial.print("Humidity: ");
Serial.print(h);
Serial.println(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
}
lightValue=analogRead(photocell);//check lights, if heat lamps only then run night
if (lightValue>800){ //day mode
if (heatLight==LOW){
if(t>dayTempHigh || h>70){
digitalWrite (exhaustFan, HIGH);
delay (15000);
exhaustServo.write(90);
intakeServo.write(90);
digitalWrite (exhaustFan,LOW);
delay(15000);
exhaustServo.write(0);
intakeServo.write(0);}
}
}
else
if (lightValue>800){ //day mode
if (t<dayTempLow){
if (exhaustFan==LOW){
digitalWrite (heatLight,HIGH);}
}
}
else
if(lightValue<900){ //night mode
if(t>nightTempHigh || h>75){
if (heatLight==LOW){
digitalWrite(exhaustFan,HIGH);
delay(15000);
exhaustServo.write(90);
intakeServo.write(90);
digitalWrite (exhaustFan,LOW);
delay(15000);
exhaustServo.write(0);
intakeServo.write(0);}
}
}
else
if (lightValue<900){ //night mode
if (t<nightTempLow){
if (exhaustFan==LOW){
digitalWrite(heatLight,LOW);}
}
}
else
if (fanStartTime+ fanInterval<millis()){
state=!state;
digitalWrite (circFan, state);
delay (10000);
digitalWrite (circFan, LOW);
fanStartTime=millis();}
delay(2000);