Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Control a Fan Using Arduino

Controlling a fan using an Arduino is a practical and educational project that introduces basic electronics and programming concepts. This project involves using an Arduino board to control a fan's speed with a potentiometer or a temperature sensor. By doing so, you can create a system that adjusts the fan speed based on user input or environmental conditions.

Components Needed:

  • Arduino Uno or any compatible board
  • DC fan (5V or 12V)
  • NPN transistor (e.g., TIP120)
  • Diode (e.g., 1N4001)
  • Potentiometer (10k ohm) or a temperature sensor (e.g., LM35)
  • Resistor (1k ohm)
  • Breadboard and jumper wires
  • External power supply (if using a 12V fan)

Circuit Setup:

  1. Connect the Fan:

    • Connect the fan's positive wire to the collector of the NPN transistor.
    • Connect the fan's negative wire to the ground on the Arduino.
    • Place a diode across the fan terminals to prevent back EMF damage.
  2. Transistor Setup:

    • Connect the emitter of the transistor to the ground.
    • Connect a 1k ohm resistor to the base of the transistor, and then connect the other end of the resistor to one of the PWM pins on the Arduino (e.g., pin 9).
  3. Potentiometer or Sensor:

    • If using a potentiometer, connect one outer pin to 5V and the other outer pin to ground. Connect the middle pin to an analog input on the Arduino (e.g., A0).
    • If using a temperature sensor, connect it according to its datasheet, typically with one pin to 5V, one to ground, and the output pin to an analog input on the Arduino.

Arduino Code Example:

// Define the pin numbers
const int fanPin = 9; // PWM pin connected to the transistor
const int sensorPin = A0; // Analog pin connected to the potentiometer or temperature sensor

void setup() {
  pinMode(fanPin, OUTPUT); // Set the fan pin as an output
}

void loop() {
  int sensorValue = analogRead(sensorPin); // Read the sensor value
  int fanSpeed = map(sensorValue, 0, 1023, 0, 255); // Map the sensor value to a PWM range
  analogWrite(fanPin, fanSpeed); // Set the fan speed
  delay(100); // Short delay for stability
}

Explanation:

  • analogRead(sensorPin): Reads the voltage from the potentiometer or temperature sensor, returning a value between 0 and 1023.
  • map(sensorValue, 0, 1023, 0, 255): Maps the sensor value to a range suitable for PWM output (0-255).
  • analogWrite(fanPin, fanSpeed): Outputs a PWM signal to control the fan speed.

This setup allows the fan speed to be controlled by adjusting the potentiometer or based on the temperature reading from the sensor. It demonstrates how to interface hardware components with an Arduino and implement basic control logic in software.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.