Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
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.
Connect the Fan:
Transistor Setup:
Potentiometer or Sensor:
// 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
}
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.