I want to control an led using a transistor. The led gets it‘s power from an external 5v dc power supply.
For the transistor I use an 1kΩ base resistor. The transistor is a BC547C (npn). The datashet is available here. The led is red (3mm), draws 20mA of current and needs 2V.
I‘ve got a very simple Arduino sketch and wiring setup:
Code:
#define ledPin 6
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
Wiring diagram:
Problem:
- The led is not blinking but shining at full power constantly.
- Disconnecting
ledPin 6
from the Arduino (to mimicdigitalWrite(ledPin, LOW)
) still lets the led shine, just not as bright. The LED should be off in that case, not just dimmed to 50% brightness.
What I tried so far:
- I tried using different base resistors. I tried 2kΩ, 3kΩ, 2.5kΩ, 470Ω, 1.5kΩ. The behavior did not change.
- I tried using different leds. Same behavior. LEDs are shining constantly, not blinking, and are dimmed when disconnecting
pin 6
. - I used another BC547C to see if the first one was broken. It wasn’t. I still got the same behavior.
- Connecting the led directly to the Arduino without the transistor and external power supply let’s the led blink exactly how it was defined in code.
Any ideas? I several-times-checked the wiring in my setup. It should not be the problem.