marian42:
As soon as I replace 5V of the emitter (from the Arduino) with an external 5V source and connect GNDs, the LED stops blinking and stays on.
I suspect that your external 5V source is an unregulated supply and is supplying rather more than 5V under the lightly-loaded conditions in which you are using it. In which case, either use a regulated 5V supply, or drive the PNP transistor from an NPN transistor which is in turn driven from the chip output.
It's usually simpler to use an NPN transistor in Common Emitter setup, with the LED connected (with a series reistor) between Vcc and the Collector. This means you can have a power source for the LED circuit that is a different voltage to the MCU signal onto the Base. One of the other benefits is you could have the transistor switch, say, a 12V source into series LED's, meaning lower current drain.
You just need to remember that if you use multi-LED, such as RGB, you need Common Anode LED's, rather than Common Cathode, and that series LED's won't work.
Is using an NPN transistor an alternative option in your case?
You'd need an NPN for dc42's suggestion anyway, so it seems more sensible to just switch to an NPN Common Emitter circuit anyway.
The value of Rb will depend on the current you need in C-E and the DC Current Gain of the transistor. To use as a switch you want to saturate the transistor so need the base current to be more than CE/Gain, otherwise you risk not saturating the transistor and it will get warm in operation.
dc42:
I suspect that your external 5V source is an unregulated supply and is supplying rather more than 5V under the lightly-loaded conditions in which you are using it. In which case, either use a regulated 5V supply, or drive the PNP transistor from an NPN transistor which is in turn driven from the chip output.
On the wallwart it says 4.5V. I just measured 8.6V.
I didnt know this before. Does it mean that I can use this wallwart to power the Arduino (because 5V sources are not suitable)?
Is using an NPN transistor an alternative option in your case?
It is, but I already connected all of the LEDs anodes so I had to unsolder them.
I would like to power the LEDs without buying further components.
Can you post a link with a circuit for a NPN transistor?
Why does my current circuit not work? Is it possible to fix it?
The NPN Common Emitter is one of the first transistor circuits to learn.
A PNP set up like you have expects Vcc to be common, not Gnd, therefore the + rail needs to be common to the Arduino and your transistor source. By using a seperate supy for the LED circuit this isn't the case. An NPN Common Emitter arrangement would make sense IMO.
The OP would still need to common up, so the Arduino/328 would also need to take supply form that 7805. The NPN switch is a lot simpler and something like a 2N3904 will switch 200mA and they cost pennies.
tack:
The OP would still need to common up, so the Arduino/328 would also need to take supply form that 7805.
The wallpack negative and Arduino Gnd would have to be "commoned", Yes, but the Arduino 5V and the wallpack derived +5 (via 7805) can be separate - no problem.
tack:
The NPN switch is a lot simpler and something like a 2N3904 will switch 200mA and they cost pennies.
I agree, but it's too late for what ought to have been done.
Sounds like he wanted a way to stay with what he's got - and putting a 7805 into the deal will let him do that, no modification to existing circuitry required.
On the wallwart it says 4.5V. I just measured 8.6V.
I didnt know this before. Does it mean that I can use this wallwart to power the Arduino (because 5V sources are not suitable)?
Good measurement. Unregulated wallwarts always read 4-5V higher than the rated value with
no loads on them.
This one is probably NOT a good choice to run the Arduino bd, however, because the voltage
will drop too low when you start connecting loads to the Arduino. Better selection is a 6V
unregulated wall wart, 500 mA or better. The actual Vin to the Arduino bd needs 1-2V overhead
to keep the voltage regulator operating properly.
As RLoad I'm using an LED with a resistor. RB is 1k (is that correct?)
The circuit is connected to an arduino pin that changes every second.
This circuit works and the LED blinks.
As soon as I replace 5V of the emitter (from the Arduino) with an external 5V source and connect GNDs, the LED stops blinking and stays on.
I want to use the circuit to switch 7 LEDs without drawing the current from the Arduino, the LEDs' cathodes are connected to GND.
That circuit requires the emitter of the transistor to be no higher than the logic 1 value of the microcontroller.
A better circuit would be a common emitter NPN transistor. Emitter directly to ground, base to the arduino pin via about a 470 ohm resistor and the collector to control your LED's.
That circuit will allow you to have a voltage higher than the arduino supply and it will still work. That is, if you used 12 volts and a resistor for the LED's, the common emitter NPN circuit would still work properly.
The "upside-down" PNP circuit you have cannot have the LED supply voltage any higher than the Arduino VCC.
So its not possible to fix it and to keep the LED connected to ground?
Not only it is possible, I even laid it out for you in the very post you were responding to,
The circuit below is largely your set-up, with D2/D3 added to raise the drive voltage so that it will shut down that pnp even when it is powered by a 9v source.
D2/D3 are two leds with 1.8v drop so you need two of them together to shut down the pnp when the mcu's output (represented as V2) goes to 5v.