Using an HS1101 humidity sensor to activate a DC fan problems

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:

You didn't use code tags to post your code. It's important that you use them - if you don't, the forum software sometimes interprets sequences of characters in the code as directives to format text in some way. It won't display those sequences, and it will unexpectedly reformat the rest of the text. When that happens, and someone tries to copy your code and paste it into the IDE, it throws an error, and readers will complain that the code fails to compile.

You can learn how to use code tags by reading the sticky post, "How to use this forum - please read," shown near the top of the subject listing for most sections of the forum. Once you know how to use code tags, you can edit your post to enclose your code in code tags, and it will look just fine.

Dkbug:
... when I write the function digitalWrite(fan, HIGH); anywhere in the code, I will never get a 5v supply from pin number 6.

From what you tell us, I suspect that you're driving the relay coil directly, and that the relay coil requires more current at 5V than the pin can supply. You can clarify things by posting a schematic of your circuit. You can also help by posting a clearer statement of the results that you get when you include a digitalWrite() to the fan pin. Do you think that the pin never even tries to go high, or that it tries to go high and just can't get there?

Somewhere in your code, I'd expect you to compare the input reading to something that corresponds to 26%, and turn on the fan if it's higher. I don't see any test like that in the code.

You can also check to see that the sketch is able to determine that the humidity level is high enough to require turning on the fan by simply substituting a statement like

Serial.println("Turning on the fan.");

in place of the digitalWrite() that is intended to energize the relay. Or, you could disconnect the relay, and connect an LED and resistor to the fan pin, and see if it lights up. Or, you could substitute a digitalWrite() the the onboard LED pin, and see if that LED lights up.

If, in fact, the problem is that the fan output pin is trying to deliver too much current, continuing to try to energize it could end up damaging your Arduino. I'd recommend that you disconnect that relay, and print something or turn on a light instead, until you're sure that you aren't driving a load that's too high.

I did have a piece in the code prior to posting that ran a loop to check if the humidity was in fact greater than 26%, and if it was then it set the pinmode to high. I have a volt meter attached to the pin to see if I am getting any voltage from it. I am not getting anything with the if statement. I may or may not be putting the if statement within the code correctly. I am running the fan through a TIP120 transistor. I have that circuit 100% correct since I pulled the same circuit from a separate project. I just need the 5v from the digital output.

Hello & welcome, first thing we need to know how your fan, relay and Arduino are connected, please post a drawing of your circuit, hand drawn and photographed is OK.

Dkbug:
I am running the fan through a TIP120 transistor.

And how are you driving the relay? Your original post mentions a "relay system." If there's no relay, how are you driving the TIP120? Do you have a base resistor?

Please post a schematic. An easy way to do that, if you have no other way, is to draw the schematic with a pencil, take a photograph of the drawing, and post the photograph.

We're just going to keep asking until we see it.