Wednesday, January 30, 2013

Web connected outlet - Part 2

Wiring it up

Well, I breadboarded up the little circuit.  What could be easier: 4 components and some wire?  Five minutes, max.

The Raspberry Pi GPIO pins can source up to 16 milliamps, but there's no need to over do it. Just to keep the current to a minimum necessary to switch the transistor, I figured a nice, conservative 3 ma (milliamps) would be fine.  I knew the transistor could do it - I've used them before for this kind of thing. So using I=E/R (current = voltage / resistance), 3.3 V / 1000 ohms = 3.3 milliamps. Certainly close enough for government work, so I wired it up.

The only problem was the transistor wouldn't switch with anything more than about 500 ohms (about 7 ma.)  What gives? The transistor I used, a 2N2222, has been used in millions of switching applications and it should switch at a couple of ma of base current with no problem.

Turns out that the batch of transistors I bought (cheap on ebay) didn't use the "standard" lead configuration.  In most 2222's the pins are, from left to right facing the "flat" face of the transistor: EBC (emitter, base, collector.)  For some reason, this batch had it reversed (CBE!?!). Doh!

It took me a while to figure that out...  Once I flipped it around ("backwards"...) it switched just fine at less than 2 ma (using a 2K resistor.)

I guess I should learn a lesson or two from this:
- Buy cheap transistors: you may not get what you think you're getting
- Always check the spec sheet (geez - these didn't even come with one...)
- Always trust your instruments (I briefly entertained the thought my milliammeter might be off...)

Oh well, live and learn!

Next time: loading up Raspbian on the Pi.

No comments:

Post a Comment