NPN transistor as switch

Hi,
I had a BC547 NPN transistor laying around (datasheet: https://www.sparkfun.com/datasheets/Components/BC546.pdf) .
Now I wanted to use is as a switch (following the schematic below).
This works perfectly fine for an LED (exactly like in the schematic below). But I need to switch components= an i2C screen, a DS3213 module and a rotary encoder hooked up on the breadboard.
So I just attached the emittor to ground, and attached the wire from the breadboard power rail that used to go to ground to the emitter of the transistor.

So now, all the components are in the place where the LED used to be.

But this doesn't work: but for some reason I get it to work after I(ve shorted the collector and the emitter for a second.

I've replaced the base resistor with a 220 Ohm one, which gies me 20mA base current for a 400mA current CE. That seems more than enough...

Anyone who can help me out here?

Thanks!

brammieboy007:
I've replaced the base resistor with a 220 Ohm one, which gies me 200mA base current for a 400mA current CE.

20 mA of base current.

Indeed, thanks. I adapted it.

So now, all the components are in the place where the LED used to be.

So draw a schematic of what you have, along with part numbers and any other wiring you have.

Then and only then can we hope to attempt to guess what you have done wrong.

Here is a schematic I made. The female headers are to place the DS3231 module in. The lcd has an I2C input; which isn't shown in the image.
I hope this will help!

(link to bigger image) http://oi59.tinypic.com/2j5jviu.jpg

Here is a schematic I made.

Sorry but no that is not a schematic, what it actually is, is a physical layout diagram. In order for it to be helpful then I have to try and turn that into a schematic in my head.
Physical layout diagrams convey little information once the circuit becomes none trivial.

For example I can't follow what you have done with that pot and why there seem to be capacitors across it. Also I can't see any pull up resistors on the I2C lines, 4K7 are normal.

Also I can not see any power supply decoupling on the real time clock DS3231, or is that a module that contains the chip and not the just the chip as your "diagram" would have us believe.

You seem to have no power and ground connected to the top bus lines on the bread board.

On thinking about it, this is not a very normal thing to do.

This is because the ground of your peripherals can only at the best be sitting 0.7V above the ground of the Arduino. Measure it and it might be closer to 1V. This gives a problem with the I2C devices at least. It means that they can not pull down the data line low enough to register with the Arduino.

This sort of thing is best done with a top switch using a PNP transistor.

brammieboy007:
I've replaced the base resistor with a 220 Ohm one, which gies me 20mA base current for a 400mA current CE. That seems more than enough...

Yes, four times more than enough.
The poor bugger can only handle 100mA absolute max.
10mA base current is also more than enough for this transistor.
A 1k base resistor (4mA) will fully saturate this transistor with 30mA LED current.

As Grumpy_Mike suggested, it's usually better to switch modules with a high-side switch.
That leaves the more important ground connection intact.
Leo..

Use a PNP transistor to do high side switching (its the mirror image of the NPN circuit, swap +/- basically.

Or a logic-level p-channel MOSFET can be used.

When switching power like this you have to consider the signal connections to the switched part of
the circuit - they must be brought to ground (or set as INPUT) before removing power, otherwise
you will have issues with parasitic powering of the switched circuit.

Keep any bulk decoupling (more than the normal 0.1uF ceramics) on the unswitched side, you risk
crow-barring the supply if they are in the switched part.

Let's start at the beginning:

But I need to switch components= an i2C screen, a DS3213 module and a rotary encoder hooked up on the breadboard.

WHY are you trying to switch those devices ?

What are you yelling about raschemmel?

The discussion seems to have become about switching power on/off to some peripherals. This may have merit to save power, but is flawed in that the powered-on devices will have signals applied that will be greater than Vcc of the devices, so the devices will either be damaged by current flowing thru input protection diodes, or appear to have phantom power applied to supposedly powered off devices, or may drag down the signal lines and corrupt comms with the other devices.

What are you yelling about raschemmel?

I STILL don't consider all caps yelling but I changed it to lower case anyway.

@OP,
FYI, do give you an example of what Crossroads is talking about, if you take a bench Lab power supply and set the output voltage to 5V dc, and then turn the current limit knob CW to allow maximum current and then connect a DMM in mA current mode from the bench supply to the analog input of an arduino UNO (powered up), you will read 0.01 mA (basically nothing) UNTIL you turn the arduino OFF, and then the current INTO the arduino UNO analog input pin A0 will jump to about 57 mA, (with absolutely NOTHING else connected to the arduino). The Led-13 (onboard led connected to D13) will be ON, (with the arduino power OFF) and the arduino 5V pin will have 3.88 V on it and the arduino will be running code (load the Blink Example and change the delay rate if you want ) and you will see that even with the arduino power OFF, the "sensor" input on A0 will phantom power the arduino. Will that damage it ? I don't know but it can't be good for it. Mine worked normally after turning the arduino power back on.

I STILL don't consider all caps yelling

but the rest of us do.

Atmel recommends no more then 1mA thru the input clamp diodes in an application note.

See top of page 4.
What they do specify in the datasheet tho is input signals no lower than 0.5V below Gnd and no higher than 0.5V above Vcc.
Section 29, Absolute Maximum Ratings:

Voltage on any Pin except RESET

with respect to Ground . . . . . . . . . .-0.5V to VCC+0.5V

CrossRoads:
Atmel recommends no more then 1mA thru the input clamp diodes in an application note.

What they do specify in the datasheet tho is input signals no lower than 0.5V below Gnd and no higher than 0.5V above Vcc.

?

You can't have one without the other.

Nowhere in the '328P datasheet does it have a current limit for the input clamp protection diodes. The only place I've seen a number is the application note I mentioned.

So I'd say you can indeed have one without the other.

I seriously doubt the OP has the slightest idea what you guys are saying. You would be more helpful if you said that if he wants to switch peripherals on and off, he should run all of the arduino connections through 5V relay Normally Open contacts so the arduino controls when the peripheral are "online".
Talking about input clamp diodes and absolute maximum ratings...you might as well be speaking Greek. If the OP were someone who had ever seen a datasheet before (not to mention an Application Note (AN) ) in their life then maybe it would be appropriate. At this point, that remains an unknown as I don't recall any comments about his electronics experience. You can't ignore the fact that he gave us a Fritzing, calling it a "schematic". That should tell you something. If you ask me, you guys are talking way over his head. As far as the input clamp diode current, I think the chance of implementing any kind of current limiting scheme for signals connected to the arduino or the peripherals, is probably going to be too complex. It makes more sense to lockout those signals with relay contacts .

The problem with application notes is that they are not part of the specification of the device. Application notes are ideas that is all. They are not recommendations or approved ready to go designs. Many non professional electronics hobbies do not understand that and think an application note has all the varsity of the data sheet.

Read that application note and you will see its authors are not saying that it is the limit, they are guessing that it would be under the limit.
You have no comeback on the manufacturers if the device does not survive this limit.

That is why you can have it both ways but at the end of the day it is only the data sheet that is the legal contract.

raschemmel:
I seriously doubt the OP has the slightest idea what you guys are saying. You would be more helpful if you said that if he wants to switch peripherals on and off, he should run all of the arduino connections through 5V relay Normally Open contacts so the arduino controls when the peripheral are "online".
Talking about input clamp diodes and absolute maximum ratings...you might as well be speaking Greek. If the OP were someone who had ever seen a datasheet before (not to mention an Application Note (AN) ) in their life then maybe it would be appropriate. At this point, that remains an unknown as I don't recall any comments about his electronics experience. You can't ignore the fact that he gave us a Fritzing, calling it a "schematic". That should tell you something. If you ask me, you guys are talking way over his head. As far as the input clamp diode current, I think the chance of implementing any kind of current limiting scheme for signals connected to the arduino or the peripherals, is probably going to be too complex. It makes more sense to lockout those signals with relay contacts .

Relays would be too slow. The time honoured way of interfacing multiple devices that might be independently powered on/off, is a common collector/common drain arrangement. To say that the solutions given here are over the OP's head, is to say that the problem is over the OP's head. Which may or may not be true. It is better to just offer the solutions and leave it up to the OP to struggle. The difficulty is inherent in the problem, not the solutions.

I believe that the OP already presented an open-collector solution that was rejected by Crossroads.
I never said that the solutions presented here were over the OP's head. I said the discussion about clamp diode current and datasheets was over the OP's head. The ATmega328 datasheet (complete) is over 600 pages. In Reply#12 Crossroads refers to section 29.1 (which is actually on page 299) I doubt the OP has ever laid eyes on that datasheet. If the OP knew what a datasheet was or where to find it or how to read it I seriously doubt he would be posting here , presenting Fritzings and calling them schematics. I just don't think he's ready for that level of detail.

However, that being said, the AN that Crossroads linked (AVR182/Page-2) in that post shows exactly how to do what the OP is asking but it doesn't use any diodes because those are internal to the INT0 pin (PD2 in the AN but D2 to you people out there)