Hello guys!!!
I made a valid effort to find someone doing a similar project as me so that I could compare codes with them, however I failed. Google only goes so far sometimes....
-Project outline-
I built a box that has an integrated humidifier inside of it. I am measuring humidity with a parallax HS1101 sensor. I have a 12v DC fan that I robbed from an XBOX to evacuate unwanted humidity levels, theoretically to be controlled by the arduino-uno once the sensor reads a certain humidity level.
I found a code on parallax's website that calculates the R-C time and humidity, and displays the value for the humidity. The thing that I am having a hard time doing is integrating the digitalWrite function into their code. I am running a relay system that will power the fan with a 12v source that will be triggered by a 5 volt signal from a digital output on the arduino.
In the code, I assigned a pin to the digital output, however when I write the function
digitalWrite(fan, HIGH); anywhere in the code, I will never get a 5v supply from pin number 6.
What I am wanting is a loop that will see if the humidity is above 26 and if it is, it will turn on pin 6.
Any help will be much appreciated!
Below I will include a picture of my circuit, as well as the code that I have.
Here is the code:
int sensorPin = 4; // RC circuit with HS1101 sesnor connected to digital pin D4
long result = 0;
int const RHconstant = 12169; // RH constant
int fan = 6;
void setup() {
Serial.begin(9600); // Use Serial Monitor window at 9600 baud
Serial.println("Humidity reading start");
Serial.print("RC delay");
Serial.print("\t");
Serial.println("Humidity");
pinMode(fan, OUTPUT); //set pin #6 as an output
}
void loop()
{
long RCdelay = RCTime(sensorPin); // Take RC time reading of sensor
Serial.print(RCdelay); // Display RC time delay
Serial.print("\t\t");
RCdelay = RCdelay * 215; // Calibation to RC time delay; experiment with literal value
int humidity = (RCdelay - RHconstant) / 24;
Serial.println(humidity / 100, DEC);
delay(1000); // Wait 1/2 second for the next read
}
// Standard RC time function
long RCTime(int sensePin)
{
long result = 0;
pinMode(sensePin, OUTPUT); // Make pin OUTPUT, and turn HIGH
digitalWrite(sensePin, HIGH);
delay(1); // Wait 1 ms delay
pinMode(sensePin, INPUT); // Make sensor INPUT
digitalWrite(sensePin, LOW); // Turn off Arduino internal pullup resistor
while(digitalRead(sensePin)){ // Loop until pin goes low
result++;
}
return result;
Here is the circuit from parallax: