Dear all !
I am a new user of Arduino and I have this problem: my project consists on controlling a PWM DC fan ( 4-wires) with a temperature sensor the problem is that I want to turn off the FAN but I could not do that correctly:
my conxion is the following :
4-wires fan :
Black (GND) ==> GND (12 v adapter ) & GND (arduino)
yellow (12 v) ==> 12 v of the external alimentation source
Blue ( RMP ) ==> pin 9 (arduino)
green( sense ) ==> pin 2 (arduino) & both are connected to 10kohm pulpup resistor ==> 5v (arduino)
the sensor is working correctly without no problems
here is my code :
#include <PWM.h>
int pwmVal = 0;
int DEBUG = 1; // DEBUG counter; if set to 1, will write values back via serial
void setup() {
Wire.begin(); // start the I2C library // for the sensor
Serial.begin(9600); //Start serial communication at 115200 baud
InitTimersSafe(); //not sure what this is for, but I think i need it for PWM control?
bool success = SetPinFrequencySafe(9, 25000); //set frequency to 25kHz
pinMode(2,INPUT); //set RPM pin to digital input the sensor pin of the fan green color
if (DEBUG) {
Serial.begin(9600);}
}
// Main program
void loop() {
float temp =getTemp102(); // to get the temperature from the sensor
//analogWrite(pwmPin, pwmVal);
pwmWrite(9, 5); // 51=20% duty cycle, 255=100% duty cycle
if (DEBUG) { // If we want to read the output
if (temp > 19 ) {
if (pwmVal != 255) {
pwmVal += 51; // increase the speed // // 51=20% duty cycle, 255=100% duty cycle
Serial.print("indoor temperature is : ");
Serial.print("\t");
Serial.println(temp);
Serial.println ( "fan speed is: ");
Serial.print(pwmVal); // Print red value
Serial.print("\t");
pwmWrite(9, pwmVal); // 51=20% duty cycle, 255=100% duty cycle
} // Print a tab
else {
Serial.println("at max high"); // Print red value
pwmWrite(9, 255);
}
the part of code related to the sensor is working correctly so I did not mentioned it while my main
problem is how to to trun off the fan. In fact, I could do this if I write this :
pwmWrite(9, 5); but normally it must be like this : pwmWrite(9, 0); ( the correct instruction )
can any of you help me in this
Thank you in advance !