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.