Introduction
DC fans are widely used in various electronics projects and appliances for cooling purposes. However, manually controlling the speed of the fan can be a hassle. Fortunately, with the help of an Arduino board, we can easily automate the fan control process.
In this article, we will explore how to control a “DC fan using an Arduino” board and a few other electronic components. We will walk you through the necessary steps to set up the circuit and write the code to control the fan speed.
What is DC Fan?
A DC fan is a type of electric fan that is powered by a direct current (DC) motor. Unlike AC fans, which run on alternating current, DC fans have a simpler design and are often more energy-efficient. DC fans are commonly used in electronics, computers, and other appliances for cooling purposes.
Hardware Components
To interface DC Fan with Arduino, you’ll need the following hardware components to get started:
Components | Value | Qty |
---|---|---|
Arduino UNO | – | 1 |
USB Cable Type A to B | – | 1 |
DC Power for Arduino | – | 1 |
Battery | 9v | 1 |
MOSFET | N Channel | 1 |
DC fan | – | 1 |
Diode | 1n4007 | 1 |
Resistor | 1KΩ | 1 |
Jumper Wires | – | 1 |
DC Fan Pinout
DC Fan Arduino Circuit
Make connections according to the circuit diagram given below.
Installing Arduino IDE
First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.
Code
Now copy the following code and upload it to Arduino IDE Software.
#define Up 2 // Up button on pin 2
#define Down 3 // Down button on pin 3
int stateUp; // Variable for state of Up button
int stateDown; // Variable for state of Down button
void setup() {
pinMode(Up, INPUT_PULLUP); // Apply internal pull up for Up button
pinMode(Down, INPUT_PULLUP); // Apply internal pull up for Down button
DDRB |= (1 << DDB1) | (1 << DDB2);
// Set ports
TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM11);
// Fast PWM mode
TCCR1B = (1 << WGM12) | (1 << WGM13) | (1 << CS10);
// Fast PWM mode, no clock prescaling possible
OCR1A = 3240; // Start PWM just below MOSFET turn on
ICR1 = 8191; // Set the number of PWM steps
Serial.begin(9600); // Start communication with serial monitor
}
void loop() {
stateUp = digitalRead(Up); // Read Up button state
if(stateUp == LOW) { // If pressed...
OCR1A++; // Increase PWM setting
}
stateDown = digitalRead(Down); // Read Down button state
if(stateDown == LOW) { // If pressed...
OCR1A--; // Decrease PWM setting
}
delay(100);
Serial.println(OCR1A); // Print current PWM setting on serial monitor
}
Code Explanation
This Arduino code controls the speed of a DC motor using two buttons, Up and Down. The buttons are connected to digital pins 2 and 3 of the Arduino board, respectively. The code applies an internal pull-up resistor to both buttons to ensure that the pins are in a known state when the buttons are not pressed.
In the setup()
function, the code sets up the necessary hardware configurations for PWM (pulse width modulation) output on pins 9 and 10, which control the motor speed. The TCCR1A
and TCCR1B
registers are used to configure the timer and PWM settings. The OCR1A
register is set to a starting value just below the MOSFET turn-on voltage and ICR1
is set to the number of PWM steps. The Serial.begin(9600)
function is also called to initiate communication with the serial monitor.
In the loop()
function, the code reads the state of the Up and Down buttons using digitalRead()
. If either button is pressed, the code adjusts the PWM setting by increasing or decreasing the value in the OCR1A
register, which in turn adjusts the motor speed. The Serial.println()
function is used to print the current PWM setting on the serial monitor, which allows the user to monitor the motor speed in real time.
The delay(100)
the function is used to add a small delay between button presses to prevent rapid changes in motor speed.
Applications
Here are some applications for DC fans:
- Personal and industrial cooling systems
- Electronic devices such as computers, routers, and telecommunication equipment
- Automotive and transportation systems for cooling engines and other components
- HVAC systems in buildings for ventilation and air circulation
- Medical equipment such as MRI machines and x-ray machines for cooling purposes
- Power electronics such as inverters and power supplies to cool power transistors and other components
- Renewable energy systems such as wind turbines for cooling the generator and control systems.
Conclusion
Controlling a DC fan using an Arduino board is a simple and efficient way to automate fan control in various electronics projects. With the right components and some basic programming skills, you can easily adjust the fan speed to suit your needs and save energy in the process. We hope this article has provided you with useful information if you have any queries please describe them in the comment section.