Pelsea

The model railroad hobby is full of gadgets that are fun to control-- motors, lights, turnout motors. It is also full of contraptions that can control them ranging from crude to sophisticated-- manual switches, detectors, computer boards. Whenever I have to connect a control contraption to a gadget, I have to pause. How do these things connect together? This is not a trivial consideration. It is often possible to damage, even destroy either or both by making the wrong choice. I am certain that this issue is the one that keeps many modelers from attempting electronics projects. Now the web is cluttered with DIY projects that deal with this problem, but most of them show how to connect one contraption to one gadget without any explanation about why that particular transistor, relay, or H-bridge is there. So this tutorial, rather than focus on a specific problem, will present the most common solutions and highlight the features that affect the choice.

I also plan to explore simple logic circuits that will allow us to combine controls in various ways.

As always, suggestions, questions and brickbats are welcome.

pqe


[Note for novices: For the purposes of this tutorial, I am going to assume there is something called electric current, that flows from a battery terminal (or other source) marked positive (+)  to a second terminal (or other sink) marked negative (-). The amount of current is measured in amperes (A), or more practically milliamperes (0.001 A = 1 mA). The force that moves the current along is measured in volts (V), and is measured between two points in the circuit. Most circuits have a designated 0V point called ground. Current is opposed by something called resistance (R), which is inherent in all materials. Resistance is measured in Ohms (Ω) or more practically kilo-ohms (k). In many cases, when current is flowing steadily, the current in amps is proportional to the voltage  divided by the resistance. A = V/R. This is known as Ohm's law.  (In science texts, current is represented by I and voltage by E, so you will also see this formula as I = E/R.) We also will need the concept of power (P) which represents heat or work done. It is measured in Watts (W) or milliwatts (1 mW = 0.001W) in our projects, although the big boys like to talk about kilowatts (1000 watts) and more. Power = voltage times current.]

Reply 0
jeffshultz

Why couldn't you be my professor...

I'm going through an apprenticeship class for a Limited Energy Apprenticeship and you just knocked about 2 hours of lecture out in one paragraph. Oh one minor addition - Power is measured in Watts.

orange70.jpg
Jeff Shultz - MRH Technical Assistant
DCC Features Matrix/My blog index
Modeling a fictional GWI shortline combining three separate areas into one freelance-ish railroad.

Reply 0
Kevin Rowbotham

EE100

Pencil sharpened!

Regards,

~Kevin

Appreciating Modeling In All Scales but majoring in HO!

Not everybody likes me, luckily not everybody matters.

Reply 0
Kevin Rowbotham

Exactly!

Quote:

you just knocked about 2 hours of lecture out in one paragraph

I thought it was very well stated too!  Going to have my son, (2nd year EE) look into this thread too.

Regards,

~Kevin

Appreciating Modeling In All Scales but majoring in HO!

Not everybody likes me, luckily not everybody matters.

Reply 0
Michael Watson

Ears Perked !

I will bring you an apple the second day !

Michael

Reply 0
pschmidt700

Refresher course always welcomed!

Thanks, Pelsea!
Reply 0
rsbodwell

Fantastic

This sounds almost too good to be true.  I am awaiting.

Roger Bodwell

La Luz, NM

Reply 0
Bernd

Fun

This'll be fun to follow. Way back when I had an interest in scratch building robots. Read a lot of books on electronics. Here's a book that was a lot of help.

ee1.jpg 

 

Bernd

New York, Vermont & Northern Rwy. - Route of the Black Diamonds - NCSWIC

Reply 0
Pelsea

A starting point

The general problem of connecting assorted devices is called interfacing. Almost every interface circuit is some variation of this:

SLC-01a.png 

The heart of the circuit is some sort of transistor. The most common transistor is a bipolar, which has three leads, collector (at the top in this drawing), base (the middle one) and the emitter (which has an arrow in the direction of current flow. We'll get to the in or out of the arrow later). The basic action of a transistor is this: if some current is allowed to flow between the base and emitter, a lot more current will flow between the collector and the emitter. (And vice versa, but that's not important right now.) Too much current cooks transistors, so there are almost always two resistors connected to it. RL is the load. It determines the total current through the transistor and represents the total resistance of the gadget hooked up (in other words there's more than a squiggly line there).

RB is the base resistor and controlling the base current sort of controls the current available to the load. I say sort of, because the ratio of b-e current to c-e current (the current gain or β) varies quite a lot in a batch of devices. But we don't care because we are going to use the thing in "saturation mode", meaning it's either full on or full off. We can ensure that by making RB less than 50x the load. In fact, all we need to worry about is making the load RB presents safe for the driving device. For instance, if the driving contraption is a CMOS chip with a 2ma output in a 5 volt world RB should be more than 2.5k. On the other hand, an Arduino will give you 40ma if you ask it to, so anything bigger than 125 ohms will do.

The wiggles at the left (input) and right (output) ends of the drawing represent voltage swings from 0 to V+. If the input is at 0 volts, the output will be nearly the supply voltage because no current is flowing through RL. If a high voltage is applied, the transistor will conduct, current will flow through the load and the voltage at the collector will be close to 0. Here is a breadboard demo:

SLC-01bb.jpg SLC-01cc.jpg 

This load is a resistor in series with an LED. It is a bit hard to see, but in the second picture, where the orange wire has been moved to the V+ bus, the LED is lit. The resistor values are 10k on the base (left) and 470 between the collector and LED (right. The transistor is a 2N3904, my goto cheap small signal transistor. Here's the pinout:

to-92.gif 

You have to be careful-- not all transistors in this package have this pinout. Only the datasheet knows for sure. (In fact, not everything in this package is a transistor.)

The 2N3904 can handle up to 200 ma of current through the collector. In addition, the collector can handle 40 volts when the base is off. (Avoid applying more than 6 volts to the base if there is no voltage at the collector.) This makes the device perfect for using a 5 volt signal to control gadgets with 12 or 24 volt power supplies. 

When we look again at the voltages of each state, we realize that when the input voltage is 0, the collector voltage is V+, and when the input is high, the collector voltage is low. This is the beginning of silicon logic. This is Boolean logic, where wires can have the states 1 or 0, occasionally called YES and NO. (Programmers call them TRUE or FALSE). In general a low voltage is 0 and a high voltage is 1, but there are exceptions. A circuit that changes 0 to 1 and vice-versa is an inverter, or NOT gate. We will explore this further in a future lesson, but first I'll show how to power some greedier devices.

pqe

Reply 0
Eugene Griffin EGRX

Late for class

Nothing changes....

except the letters... V=IR.

But I learnt something new.... "brickbats"

Great thing about this site, read all the post, and one should be able to create a 3d printer with laser cutter and paint spayer attachments all controlled by DCC that will be able to create complex train stations directly on the layout...

Eugene

Reply 0
GMO

Hi, Good idea to bring a

Hi,

Good idea to bring a little basic electronics to the user.

But please do not mix the characters for the formula and unit.

Formula:

U for voltage in volt, I for current in ampere and R in Ohm for resistance

So you should wright volt=ampere*Ohm or the correct way U=I*R

Greetings

Hardy

Reply 0
pschmidt700

'U' is not used for voltage

Hardy, Pelsea isn't changing anything. "U" may have been the symbol at one time in long-ago past, but it's been either "V" or "E" for at least the past 40 years and probably a lot longer. This is how it's taught in electronics classrooms and textbooks. Hence IC manufacturers using "VCC", etc., when indicating pin functions. Pelsea is using the correct symbols for the formulae.
Reply 0
GMO

Hi, oh, I see in English

Hi,

oh, I see in English there is a difference between German (wikipedia).

I do electronics now for nearly 40 years, but didn't know that formula in English is different.

So, forgot my post earlier.

Reply 0
George Sinos gsinos

Ohm's Law Video

The folks at Sparkfun recently posted this

on their YouTube Channel.

gs

Reply 0
pschmidt700

@Hardy

Just the opposite, I'll remember your post because I did not know "U" was used in Germany for voltage. I'll remember that. It could very well come in handy one day. Thanks for raising the point.
Reply 0
Pelsea

A digression on jargon and exploration of some basic concepts

Here comes the boring bit-- skip it if you like or read it for the laughs.

One reason many get turned off of electronics is the confusing terminology. Electronics is a wonderland, and the caterpillar is in charge: "When I use a word it means exactly what I intend it to mean and nothing else".

As near as I can tell, the terms in the formulas either come from physics definition of the effects or the units used to measure these effects. Some folks try to be consistent, using only the physics or measurement terms, but you will also see them mixed indiscriminately. (Wikipedia favors V for voltage and I for current.)

E is for Electromotive force, measured in Volts (V) and usually called voltage. Occasionally you will see the symbol U, or the full acronym EMF. It's not really a force, it's more like an urge to get a charge from one place to another. Like distance, voltage only has meaning if you know where you are measuring from. Thus a voltmeter has two leads, and displays voltage between one lead and the other. (It actually bleeds a bit of current from the circuit and measures that.) Circuit schematics always have a reference point for 0 volts called "ground" (or "earth" across the pond). This dates to the days of the telegraph, when the circuit was completed by driving a stake into the ground at the transmitter and receiver. The ground symbol is a little drawing of that:

dSymbols.png 

Over the years, ground has come to mean more than 0 volts. For one thing, it is a shorthand for a lot of wires-- you just put that symbol on everything you want connected back to the battery. It also implies a connection to a metal chassis, the only part of a circuit the end user is allowed to touch. (Note that it is not always connected to the safety ground of your three wire house power. We tend to use the earth symbol for that.) Ground is also used to connect any electromagnetic shielding the device needs-- this may be knitted wires around a cable or a big area of a circuit board (ground plane).

It is perfectly reasonable to measure a voltage of less than 0, i.e. a negative value. This just means the current will flow the other way, from the black wire on your meter toward the red one.

I is for Intensity of current, or just current, measured in Amperes (A). My guess is I is used because C was already taken. Current is the movement of charge through a circuit. The idea that electricity is some kind of fluid flowing in a wire came from Ben Franklin. All he had was some glass and silk, and had to make a guess about which way the electricity was flowing. Unfortunately, he guessed wrong, to the consternation of ee students ever since. When electrons were discovered, it turned out they move from negative to positive. Rather than correct Franklin, physicists invented negative charge, and assigned electrons a charge of -1. Even today students have to go to physics class and see diagrams of electron flow from - to +, then go to ee and see current flow from + to -. When the physics and electronics overlap, we speak of the movement of "holes", places were an electron could be but isn't.

[Just for added confusion, the electrons are not moving that much-- what moves is the net charge (balance between electrons and protons in their host atoms), and that is a wave phenomenon, like sound.]

Voltage will make current flow if it has a path to follow. Most of our voltage sources provide current from one end and accept (sink) it at the other. Attach a wire to both ends of a battery and current happens.

Circuit0.png 

You can see why we call these things circuits.

Resistance is the property of a material to oppose the flow of current. I've never seen anything but R used to symbolize resistance. The unit of resistance is an Ohm (Ω). [There is a complimentary concept called conductance, the inverse of resistance. Its symbol is σ (sigma) and its unit is the Mho (really!).] I=V/R describes the state of affairs when current is flowing steadily. If we try to change the current, calculus happens, and I'm not going into that here. Steady current calculations are all we need to keep from burning things up. Usually we need to know the current from the voltage and resistance, so I=V/R serves nicely, but when we want to pick a resistor to limit the current given a voltage we need the R=V/I form. (I'm a bit dyslexic, so I keep those formulas posted above my desk and workbench.)

The resistance of a circuit is everywhere in the circuit, but it is not distributed evenly. It usually occurs in lumps, and when we theorize about circuits we put all of the resistance in one place, represented by a wiggly line. If we break the resistance into two lumps, the voltage is distributed proportionately over the two:

Circuit1.png 

That is because Ohm's law is true for any piece of the circuit as well as the circuit as a whole. All of the current flows through both resistors, so if we calculate the V across R2, it will be the same fraction of total V as R2 is of total R. Two resistors arraigned this way is called a voltage divider and is very useful. If we had two resistors in parallel across the battery, each would follow the law and we'd pull more current, the sum of what's through each resistor.  This sort of thing leads to a couple of weeks of homework for ee students and is usually on the final. 

Flowing current produces some side effects, which is why we bother in the first place. One effect is a magnetic field, and the strength of the field is proportional to the amount of current. We can measure a current by measuring the magnetic field. Cheap meters do this by steering the current through a coil (to intensify the field), but you need to break the circuit to measure. There are meters that can measure the field around a wire directly, but they don't work well with the tiny currents we use.

The other major side effect of current flow is heat, which is good sometimes but is usually a problem. Any device will burn up if enough current is run through it. On the other hand every device needs a certain amount of power to get its work done. We are always trying to thread a needle with a hole determined by the power required for something to do its job and the power handling ability of the other parts of the circuit.

Power is measured in Watts (W), and symbolized by P. Power is voltage times current. P=E*I or W = V*A are the formulas you see. They don't include resistance, but we often need to know what power resistor to use with a given voltage. The formula P=V2/R (remember your algebra?) will tell us. If we want to put 5 volts across a 62 Ohm resistor it had better be a 1/2 watter.       P= 52 / 62 = 25/62 = 0.4.

Next lesson will be practical, I promise.

pqe

Reply 0
Ace

"conventional current flow" is positive to negative

I had electronics classes in high school with texts that strove to make the point that electrons "actually" flow from negative to positive, and "holes" flow the other way. It set my understanding of electronics back about ten years, because it was more confusing to trace "current flow" through semiconductor components with arrows pointing in the "wrong" direction.

Electronics are easier to understand if you just accept the idea of "conventional current" for the purposes of tracing out circuits.

Reply 0
Pelsea

Extra shots...

OK, back to stuff that is immediately useful.

PNDriver.png 

The simple NPN transistor driver I presented in an earlier post will cover at least half of your interface needs. It will switch a resistive load of 200 mA or so. That's 10 LEDs, which is usually plenty. On the other hand, that is a limitation I run into a lot. There are two issues-- resistive means no relays or motors, and I keep building things with LED strings. 

You'd think all I need to do to beef this circuit up is grab a bigger transistor. After all, the venerable 2N3055 can manage 15 Amps. The problem with those big bruisers is they don't have much current gain (β). That means you probably need a transistor to drive the transistor that drives the transistor! Our circuit provides 200 mA, so attaching that to something with a β of 20 can get us 4 amps (not bad), but a third stage is needed  for serious lifting. All of those transistors need resistors to adjust their gain and bias, so the whole works takes a lot of space and generates a fair amount of heat. I prefer a simpler way:

0x450(1).jpg 

Enter the TIP 120 Darlington pair. This encapsulates a big transistor with a little one to drive it. The extra components needed are there too. The package isn't much bigger than a simple transistor and it will handle 5 amps in its sleep. It drops right into our previous circuit.

rlington.png 

One thing, though. If you really want to run 5 amps through it, It's going to get hot. Heat is transferred to the metal tab, so you can bolt it to a hunk of metal called a heat sink.

heatsink.jpg    tsinkKit.png 

The tab is connected to the collector of the transistors, so you need to be careful-- if it touches something grounded, you are shorting the power supply. If that is a possibility, use a to-220 mounting kit, which has a mica wafer to transfer heat but not current. For best results, apply a bit of silicon thermal grease. (I routinely run 1 amp loads with no heat sink, and the tab only gets a little warm. I still have to worry about the tab touching things, though.)

Here's how the TIP 120 looks on the breadboard:

SLC-03a.jpg   SLC-03b.jpg 

The left pin is the base of the first transistor, the middle pin is the collector of both, and the right pin is the big emitter.

The thing about relays and motors is they have coils in them that generate something called back-emf. (We've heard of that.) This happens any time you turn off the power to a coil. When current flows through a coil, you get a magnetic field. I mean that's the point, right? However, when the current stops, the magnetic field takes a moment to collapse. The collapsing field generates a voltage opposite the one that generated the field in the first place. One quick way to kill a transistor is to hook up the collector and emitter backwards, so back-emf can be deadly. We protect against this by putting a diode backwards across the transistor (or coil). The diode shunts any back current around the transistor. Look at the equivalent circuit for the tip 120 for an example. There's a diode just where we need it. A motor can replace RL in the TIP 120 circuit with no problems. Just make sure the stall current is less than 4 to 5 amps.

So, out of all of the transistors I have in my parts drawers, I mostly use 2N3904s and TIP 120s.

Next, a different perspective on the problem.

pqe

Reply 0
pschmidt700

Thanks again, Pelsea

Your conversational style really makes it plain to me that you enjoy teaching.
Reply 0
Pelsea

Thank you for the apple...

 I'm still amazed that I used to get paid to do this.

pqe

Reply 0
Pelsea

Ps and Ns

So far, we've been playing with NPN transistors in our interface circuits. That seems to be the most popular configuration, at least in circuits I've studied (and certainly in ones I've built). However, there is one minor drawback that some people may prefer to avoid. If you are controlling something that is far from the circuit, you have to provide a pair of connections, the control wire and V+. This means your layout is laced with wires that are always energized. With 12 or 5 volts accessory power this is not a safety issue, but if something were to go wrong and short out the gadget at the end of the wires, it will take down the entire system, and probably blow a fuse. A PNP transistor circuit switches on the V+ side, so an inactive wire is powered down and the other wire is ground (which may be available nearby). 

Another situation where you will need to switch the positive side of a gadget is if you get one with LEDs that are connected at the cathodes, like some signal sets.

No, I'm not about to launch into the usual lecture with diagrams of P type and N type sandwiches and charts of carrier migration-- there are plenty of those on the web if you are curious. All I'm going to say is that for every NPN transistor there is a complimentary PNP transistor. By complimentary, I mean current flows into the emitter instead of out of it. Current through the emitter and base still controls the current through the emitter and collector. We do need to be able to recognize the schematic symbol-- there are various mnemonics (Not Pointing iN), but I just keep a note on the wall above my bench (the diagram in my earlier post, in fact). Anyway, the arrow shows current flow. Here's a basic PNP switch:

NPDriver.png 

In this circuit, the emitter is connected to V+, and the load is between the collector and ground. When the base is brought low, current flows freely through the collector to the load. This provides a circuit that is good for control over a distance. 

You will note that this circuit inverts the input with Russian logic (Upizoff). Usually, this is not a problem, as either state is probably available to us (Arduino users write 0 instead of 1), and the load is not powered if the input is not connected to anything. However, for the rare times when the input logic demands a 1 to turn the gadget on, you  can simply combine the NPN and PNP circuit like this:

PDriver3.png 

That's enough PNP to get you going-- if you need more oomph there are P-type Darlington devices too-- the TIP125 complements the TIP120.

pqe

Reply 0
emdsd9

I hope the politicians don't

I hope the politicians don't here about controlling the world with simple logic circuits!

John

Reply 0
MikeScott

Politicians ~ Simple Logic ?

Subject says it all!

Politicians ~ Simple Logic ?
 

Reply 0
Kevin Rowbotham

spam link...

Where is it when you need it?

Regards,

~Kevin

Appreciating Modeling In All Scales but majoring in HO!

Not everybody likes me, luckily not everybody matters.

Reply 0
Kevin Rowbotham

Breadboarding the circuits...

Moving along.

I've got the parts on hand so, although I didn't have the exact values for the resistors, I breadboarded the circuit to prove it. The transistor switch works.

I'm starting to get an inkling of the circuit I might need to make the solid state switch I ultimately want, but I don't want to push ahead of the class with talk of FETs and optocouplers...

I'm also now wondering if the right SSR wouldn't do the same thing...?

Polishing my apple, lol!

Regards,

~Kevin

Appreciating Modeling In All Scales but majoring in HO!

Not everybody likes me, luckily not everybody matters.

Reply 0
Reply