Hello, first of all thanks for reading this post. I'm completely stuck on a project. I am currently doing my first project with my first microcontroller.
I'm making a culture chamber with a CFL bulb, 2 relays, a DHT11 (a temperature sensor), a moisture sensor and so far everything was doing well. (i'll post the code for the entire project if needed, but it's a bit long)
However, if most of it worked i couldn't manage to set the Fan I used at the speed i wanted, with any code it would run full speed.
The Fan is a Cooler Master A14025-20RB-4CP-F1.
It functions on 12v 0,8A.
And is powered by an adaptor (the ground is connected to the adaptor and to the arduino)
- on -
+12v on red
and signal plugged correctly
When i plug the adaptor The fan runs at full speed.
I wrote this code to see if i could Set the fan's speed;
int VentPin=3;
void setup() {
pinMode(VentPin, OUTPUT);
}
void loop() {
analogWrite(VentPin, 60);
delay(5000);
analogWrite(VentPin, 60);
delay (5000);
analogWrite(VentPin, 255);
}
But the Fan just kept going 100%. So I've found that the PWM of my Arduino Uno wasn't in 25KhZ which was the frequency of my PWM's fan. (can't say if i've said in properly haha)
I Used this new code using a PWM library:
Library can be found here:
http://forum.arduino.cc/index.php?topic=117425.0
on this link:
https://code.google.com/archive/p/arduino-pwm-frequency-library/downloads
And Here's the code:
#include <PWM.h>
//use pin 11 on the Mega instead, otherwise there is a frequency cap at 31 Hz
int led = 7; // the pin that the LED is attached to
// how many points to fade the LED by
int32_t frequency = 25000; //frequency (in Hz)
void setup()
{
//initialize all timers except for 0, to save time keeping functions
InitTimersSafe();
//sets the frequency for the specified pin
bool success = SetPinFrequencySafe(led, frequency);
//if the pin frequency was set successfully, pin 13 turn on
if(success) {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
}
void loop()
{
//use this functions instead of analogWrite on 'initialized' pins
pwmWrite(led, 0);
delay(5000);
pwmWrite(led, 120);
delay(5000);
pwmWrite(led, 255);
}
And nothing happened, and now i read few posts saying that 25Khz is impossible with an arduino since the base frequencies divided by 2,4,8 etc... don't match with 25Khz.
Can I set the speed of the fan with my arduino ? Or Maybe i have made a mistake i can't see..
thank you for your time.