Hello all!
I am an electrical engineering student relatively new to arduinos working on an automated green house tech project.
To the point:
I have built a simple "on/off control" (heater on when too cold, fans on when too hot) but would like to have smarter control over 2-3 fans constantly running and being RPM controlled, speeding up when increasingly hot and slowing down/shutting off if temperature dips. My sensor is a DHT22 temperature/humidity sensor and I have 4 wire fans PWM control at my disposal.
Looking at some advice or links on how to do this!
You will probably need too know more about the characteristics of the fan motors.
If they are dc motors, you control the speed by the effective voltage using pwm.
If they run off a/c, this won't work. You can research how variable speed ceiling fans work.
Variable speed fans in computers now are often brushless motors with variable frequency drives.
It may be simpler to just turn them on and off, than changing the speed.
Or, if you have 2 or 3 fans, turning 1 or more of them off.
michinyon:
You will probably need too know more about the characteristics of the fan motors.
If they are dc motors, you control the speed by the effective voltage using pwm.
If they run off a/c, this won't work. You can research how variable speed ceiling fans work.
Variable speed fans in computers now are often brushless motors with variable frequency drives.
It may be simpler to just turn them on and off, than changing the speed.
Or, if you have 2 or 3 fans, turning 1 or more of them off.
I have 3, 4-wire computer fans that are 12VDC. I have a separate 12V supply powering the fan and it was my understanding that I send the PWM pulse through the 4th wire to change the speed of the fan. When everything is hooked up the fan starts up and stays a constant speed. I have been unable to change the speed of the fan.
I have been able to use the sample LED fade to ensure that my PWM is working but sending a PWM signal to the fan doesn't seem to do anything.
These are the fans I'm using:
http://www.deepcool.com/product/dcoolingaccessory/2013-12/12_639.shtml
try this
temp = dht22.getTemperature();
speedFan1 = map(temp, 18, 30, 0, 255);
analogWrite(FAN1, constrain(speedFan1 , 0, 255) );
speedFan2 = map(temp, 10, 30, 0, 255);
analogWrite(FAN2, constrain(speedFan2 , 0, 255));
etc
I have figured it out! My fans do not need a transistor on the PWM pulse and can be directly connected.
For any future searchers I used this:
void setup() {
pinMode(3, OUTPUT);
TCCR2A = 0x23;
TCCR2B = 0x09; // select clock
OCR2A = 79; // aiming for 25kHz
OCR2B = 62; // set the PWM duty cycle
}
void loop(){
analogWrite(3, HIGH); //sends PWM signal
OCR2B = 0; // min fan speed
delay(5000)
OCR2B = 79; // max fan speed
delay(5000);
}
It sets the frequency of the PWM signal and then turns the fan from minimum speed to maximum every 5 seconds. You use the OCR2B value to control the speed of the fans.
Detailed explanation here:
http://forum.arduino.cc/index.php?topic=18742.0t
Also if anyone is doing a mini greenhouse project like me, here is the start of my program (be nice, it's a work in progress):
#include "DHT.h" // include dht sensor library
#define DHTPIN 2 // temp/hum sensor pin
#define DHTTYPE DHT22 // type of DHTxx sensor = DHT 22 (AM2302)
#define fan 4 // fan on-off pin (relay)
#define fanPWM 3 // fanPWM speed control signal pin
#define heater 5 // heater pin
int setHum = 55; // humidity setpoint % 0-100
int setTemp = 15; // temperature setpoint degrees Celsius
int minHum = 50; // humidity MIN % 0-100
int maxHum = 70; // humidity MAX % 0-100
int minTemp = 10; // temperature MIN degrees Celsius
int maxTemp = 30; // temperature MAX degrees Celsius
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor for normal 16mhz Arduino
void setup() {
Serial.begin(9600); // enable serial monitor
pinMode(fan, OUTPUT); // enable fan output
pinMode(fanPWM, OUTPUT); // enable fanPWM signal output
pinMode(heater, OUTPUT); // enable heater output
dht.begin(); // begin dht sensor library
////////////////////Fan Speed 25KHz Clock Speed Setup////////////////////
TCCR2A = 0x23; // set time clock multiplier
TCCR2B = 0x09; // select clock
OCR2A = 79; // aiming for 25kHz
OCR2B = 30; // set the PWM duty cycle
}
void loop() {
////////////////////Temp/Hum Sensor Readings////////////////////
delay(2000); // Wait a few seconds between measurements.
float h = dht.readHumidity(); // read humidity
float t = dht.readTemperature(); // read temperature as Celsius
float f = dht.readTemperature(true); // read temperature as Fahrenheit
if (isnan(h) || isnan(t)) { // Check if any reads failed and exit early (to try again)
Serial.println("Failed to read from DHT sensor!");
return;
}
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float hi = dht.computeHeatIndex(f, h); // compute heat index (temp must be sent in fahrenheit)
Serial.print("Fan Speed: "); // print fanSpeed readings to serial
Serial.print(OCR2B);
Serial.print("\t Humidity: "); // print temp/hum readings to serial
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("\t Heat index: ");
Serial.print(hi);
Serial.println(" *F");
if(t < minTemp) { // if temperature falls below minTemp or minHum - turn fans OFF
digitalWrite(fan, LOW);
analogWrite(fanPWM, LOW);
digitalWrite(heater, HIGH);
OCR2B = 0; // speed of fan to 0
}
else{ // keep minimum airflow
digitalWrite(fan, HIGH);
analogWrite(fanPWM, HIGH);
digitalWrite(heater, LOW);
////////////////////Fan Logic////////////////////
if(h >= minHum || t >= minTemp) // speed level 1
OCR2B = 20; // fan = minimum
if(t >= setTemp) // speed level 2
OCR2B = 30; // fan + 10
if(t >= setTemp + 5) // speed level 3
OCR2B = 40; // fan + 20
if(t >= setTemp + 10) // speed level 4
OCR2B = 50; // fan + 30
if(t >= setTemp + 15) // speed level 5
OCR2B = 60; // fan + 40
if(h >= maxHum || t >= maxTemp) // speed level maximum
OCR2B = 79; // fan = maximum
}
}
Cheers!!!