Search Suggest

How To Control LED Brightness or DC Fan Speed with Arduino, Transistor, and Potentiometer


In this tutorial, I will show you how to control the brightness of an LED or the speed of a DC fan using an Arduino board, a BC547 transistor, and a potentiometer. Follow along for a step-by-step breakdown of the circuit, the code, and useful tips on optimizing your project.

Components Required

  • Arduino Board (e.g., Arduino Uno)
  • BC547 Transistor (or BD139 for higher currents)
  • Potentiometer (10kΩ recommended)
  • LED or small DC fan (6V or 9V recommended)
  • 9V battery or suitable power supply (7V - 12V)
  • Connecting wires and breadboard

Why Use a Transistor?

The BC547 transistor acts as a switch and amplifier in this circuit. Since the Arduino cannot directly handle high-current loads like a DC fan, the transistor allows us to control higher currents with a low-power signal from the Arduino. If you need to control devices with higher currents, replace the BC547 with a BD139 transistor, which can handle more current.

Power Supply Considerations

Ensure that your power supply matches the requirements of your components. While the Arduino itself can be powered via USB, this may not provide enough current to run external devices like fans. For this project, a 9V battery or a regulated power supply between 7V and 12V is recommended to provide enough current to the fan while safely powering the Arduino board.

Circuit Diagram

The potentiometer acts as a variable resistor, allowing you to adjust the voltage applied to the base of the transistor, which in turn controls the voltage across the load (LED or fan).

 

Schematic Explanation:

  • Connect the middle pin of the potentiometer to Arduino pin A0 (analog input).
  • Connect one outer pin of the potentiometer to ground and the other to 5V.
  • The control pin (pin 9) on Arduino connects to the base of the transistor via a current-limiting resistor (1kΩ).
  • The collector of the BC547 connects to the negative terminal of the fan or LED.
  • The emitter of the transistor connects to ground.
  • The positive terminal of the fan or LED connects to the 9V battery's positive terminal.

Arduino Code


const byte POTENTIOMETER = A0;  // Pin A0 for potentiometer input
const byte CONTROL = 9;         // Pin 9 for controlling the output
int reading;                    // Variable for analog reading
int value;                      // Mapped value for PWM output

void setup() {
    pinMode(CONTROL, OUTPUT);   // Set pin 9 as an output
}

void loop() {
    reading = analogRead(POTENTIOMETER);   // Read the potentiometer value
    value = map(reading, 0, 1023, 0, 255); // Map 0-1023 to 0-255
    analogWrite(CONTROL, value);           // Output PWM signal to control brightness/speed
}

        

Code Breakdown:

  • The potentiometer is connected to pin A0 (analog input) to measure the input voltage, which is then mapped to a 0-255 range using the map() function.
  • Pin 9 (PWM output) is used to control the transistor, modulating the current flowing through the LED or fan to adjust its brightness or speed.
  • The analogWrite() function sends a Pulse Width Modulation (PWM) signal to the control pin, which creates a variable voltage output based on the potentiometer position.

Tips for Optimizing Your Project

  • Heat Dissipation: If you are using a higher current fan or motor, consider using a heat sink with the transistor to prevent overheating.
  • Power Supply Safety: Always ensure that your power supply is within the voltage range for the Arduino (7V - 12V) and that it can supply enough current for your load.
  • Component Selection: If using a different transistor, check its maximum collector current and base voltage to ensure it’s compatible with your circuit.

Conclusion

Using an Arduino, a potentiometer, and a transistor, you can easily control the brightness of an LED or adjust the speed of a DC fan. This is a simple yet effective method for managing various loads using Pulse Width Modulation (PWM). By tweaking component values, you can adapt this setup for different power requirements and applications.

Experiment with different transistors and power sources to extend this project into more advanced applications like motor speed control for robotics or home automation projects!

Rate this article

Prasun Barua is an Engineer (Electrical & Electronic) and Member of the European Energy Centre (EEC). His first published book Green Planet is all about green technologies and science. His other …

Post a Comment