2

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:

wiring diagram

Problem:

  1. The led is not blinking but shining at full power constantly.
  2. Disconnecting ledPin 6 from the Arduino (to mimic digitalWrite(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:

  1. I tried using different base resistors. I tried 2kΩ, 3kΩ, 2.5kΩ, 470Ω, 1.5kΩ. The behavior did not change.
  2. I tried using different leds. Same behavior. LEDs are shining constantly, not blinking, and are dimmed when disconnecting pin 6.
  3. I used another BC547C to see if the first one was broken. It wasn’t. I still got the same behavior.
  4. 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.

  • 5
    You need to provide common ground. Add wire connecting negative '-' connector of your battery with GND in your Arduino. – smajli Jun 8 at 20:02
  • @smajli that doesn't explain why the led stays on when the base is not connected to the gpio... – Sim Son Jun 8 at 20:19
  • @WalterBeiter could you post a picture of your setup? Are you sure that you have assigned the correct pins at the BC547? From the info you provided and the troubleshooting you already did I don't see anything that could be wrong. – Sim Son Jun 8 at 20:27
  • @Sim Son I agree, but we have to start somewhere... – smajli Jun 8 at 20:45
  • 2
6

Without a common reference (ground) between the Arduino power supply and the external power-supply, again, you have a floating base, as you can't know what the Arduino's 5v output (or local ground) looks like to the external circuit.

Connect the two grounds. That should correct the LED brightness with respect to the Arduino output pin level. Then, if you need the external circuit to behave in a specific way when the base is disconnected from the Arduino, add a 10K resistor from the transistor base to the external +5 if you want the LED to be on, or to ground, if you want it to be off. Again, I'm guessing at both the pullup/pulldown value (but 10K should be in the ballpark) and the switching sense ('On' or 'Off' for base at +5), but from the expectation state in your point (2.), I think I have it right.

Update: But see @EdgarBonet's comment to me about BJT's. I'd still avoid leaving an input floating as a matter of practice, but it seems not relevant in your circuit.

  • Re the floating base: The OP is using an BJT. Unlike a FET (which is voltage controlled), the control variable for a BJT is the current fed to its base. Leaving the base floating is a legitimate way of setting that current to zero. – Edgar Bonet Jun 9 at 8:45
  • I hadn't known that about BJTs, @EdgarBonet, so thanks for that. Fixing my answer... – JRobert Jun 9 at 11:45
  • Common reference ground fixed all the issues! – WalterBeiter Jun 9 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.