Diodes, Transistors and Optocouplers: what they are, some theory and simple usages examples with Arduino

In this post I’ll experience with three kind of components available in the Arduino Base Workshop KIT: diodes (model 1n4007), transistors (models BC547 Transistor and MOS Irf540) and optocouplers (model 4N35). I’ll briefly describe them and we’ll see some simple examples of circuits built upon an Arduino Duemilanove board which make use of them.

Diodes: driving current only in one way

Well, the title says it all. A diode is a two terminals electronic component that conducts electric current only in one direction.

The most common function of a diode is to allow an electric current to pass in one direction (called the diode’s forward direction) while blocking current in the opposite direction (the reverse direction). Thus, the diode can be thought of as an electronic version of a check valve. This unidirectional behavior is called rectification, and is used to convert alternating current to direct current, and to extract modulation from radio signals in radio receivers.

A simple Arduino based circuit using a diode

We can build this simple circuit to show how diodes works:

Once assembled on the Arduino board, the circuit will looks like:

What does this circuit do? Well, nothing complex or useful actually. But we can understand how diodes works with it. If we plug the diode as seen on the pictures above when we’ll push the button the LED will turn on. Cool, uh?

Instead, if we revert the diode so that current now flows in the opposite direction, we’ll se that the LED won’t turn on when we press the button. This confirms the behaviour of a diode: it lets the current flows if it’s passing in its forward direction while it blocks when it pass in the opposite direction. You can see a demo in the video below.

Transistors

transistor is a semiconductor device which can be used to amplify or switch electronic signals. In the simple Arduino based circuits transistors are usually used as switch for electronic signals.

Transistors usually have 3 connectors called collectorbase and emitter. In normal state the collector and emitter are disconnected but, when a current is applied to the base connector, the transistor change its state and the collector and emitter get connected thus current can flows between them.

This behaviour make the transistor the perfect component for interface two different circuits operating at different voltages. For example one circuit could be the one powered by Arduino: small current and low voltages. The other circuit could be the one operating a DC motor which needs a lot of voltage and current. Connecting the two circuits could be painful but with the transistor we could drive the second circuit by changing the state of the transistor trough the first circuit connected to the Arduino. Cool stuff.

The Arduino Base Workshop KIT comes with two types of transistors displayed in the picture above: a MOS Irf540 (left) and a BC547 (right). They differs from the building technique which results in different specifics. For all the details have a look at the detailed specifics linked above but they mostly work the same way: they only differ in the amount of current they are capable of deliver. For bigger currents (eg powering motors) the MOS Irf540 will be perfect. The BC547 is not capable of delivering lot of current so use it with care.

A simple Arduino based circuit using transistors

We will use a transistor controlled by the Arduino board to act as a switch on an external circuit. The transitor base will be connected to an Arduino output pin. This is the circuit:

Once plugged into the Arduino board it will looks like:

Note that the circuit coming from Vin (9V) is actually completely separated from the one coming from the Arduino board. They are two indipendent circuit. Only the transistor let them interact.

We will now use the Hello World program with a simple modification: we will use pin 2 as output (in the helloworld program we used pin 13). To get the code refer to the Hello World blog post.

What does the circuit we created do? Well, let’s see in the video below:

As you can see each time the output on pin 2 is HIGH our transistor will get a voltage on its base connector resulting in the collector and the emittor getting connected. Current coming from the +9V source can the flow down throgh the resistor and the three series LEDs lighing them on.

A similar result could have been achieved using the MOS Irf540 transistor.

UPDATE 2012-10-07: Improvement

The circuit above can be improved by using this circuit:

This is preferable against the one explained before because it won’t float when the microcontroller is shut off or when it is not actively drive the pins. Basically, the circuit explained above only works reliably when the microcontroller actively drives the pin high or low. When it is not doing so, the transistor may float randomly and close/open the circuit. The fixed circuit in this section, by using a pull-down resistor doesn’t show this effect and works reliably.

Optocouplers

An optocoupler, also called opto-isolatoroptical isolatoroptical coupling devicephotocoupler, or photoMOS, is an electronic device that usually contains both an infrared light-emitting diode (LED) and a photodetector and use them to transfer an electronic signal between element of circuits maintaining them electrically isolated.

When a voltage is applied to the LED, the LED lights and illuminate the photodetector which produces an output current on the photodetector: basically this means that now the photodetector circuit is now connected and current can flow in it.

4N35 Optocoupler DIL-6 package

The Arduino Base Workshop kit comes with two 4N35 Optocouplers packaged as a DIL-6 package.

This little component has 6 legs each of them having a different usage. It can be easealy understood while looking at the following picture from the 4N35 datasheet which shows us the inside schematics of the 4N35:

So, we have leg 1 and 2 near the printed dot on the chip (that’s visible on it if we look carefully) that acts respectly as anode and cathode. Leg 3 isn’t connected to anything: it’s just useless. We then have leg 4, 5, 6 respecly emitter, collector and base.

We already know these terms from the transistor introduction above. They do exactly the same of the legs of a transistor. The difference here is that we can leave the base unconnected and just use the LED (legs 1 and 2) to connect the collector and the base.

An Arduino based circuit using an 4N35 Optocoupler

Now that we know the theory behind optocouplers and that we know how to connect our 4N35 Optocoupler it’s now time to create a simple circuit with it. Here it is:

The circuit above once created using the Arduino board will looks like

We can use the same program used for the transistor example above. This is the result:

So, it basically do the same of the transistor example above but this time we are using an optocoupler. Not bad, uh?

Conclusions

Now, I know how to use three new electronic components: diodes, transistors and optocouplers. The simple circuits I built will be used as base for more complex stuff. I’m pretty sure these components will be pretty useful when I’ll build more complex stuff. Looking forward to it!

References

Diode on Wikipedia
Transistor on Wikipedia
BC547 Nodatasheet by Daniel Soltis
BC547 Official Datasheet
Arduino Hello World on this blog
Opto-isolator on Wikipedia
Electus Distribution Reference Data Sheet: OPTOCOUP.PDF
4N35, 4N36, 4N37 OPTOCOUPLERS Data sheet

AttachmentSize
transistors_1.jpg
574.38 KB
Scroll to Top