Saturday, April 16, 2016

Transistor Crash Course For Software Developer - PART I - Transistor As Switch

Overview


If you are a software developer that started making hardware experiment with an Arduino, Raspberry PI, BeagleBone or our USB device Nusbio, You probably learn by now about GPIO (General Purpose Input Ouput).
These pins with which we can programmatically send a 1 or 0 or read a 1 or 0 when connected to another device.
A 1 also called high (pulling the wire high) is materialized by sending
some voltage/current (3 or 5 volts generally) and a 0 also called a low materialized by sending no voltage/current.

Though we can turn on and off device with a GPIO, a GPIO generally can only provide a limited amount of current. An Arduino Uno GPIO can provide up to 40 mA of current (ArduinoPinCurrentLimitations).
Nusbio's GPIO are configured by default to provide 4 mA and can be configured to provide up to 16 mA.

Therefore when you want to control a device like a simple motor or an LED using 60 mA, you should not connect the GPIO directly to the positive of the device. It may work, but the motor may go very slow or the LED will not be very bright.

If the device is 5 or 12 volts, you can use a transistor. If the device is 110 volts, you need a relay.



Transistors 


Disclaimer: This is a very quick introduction to transistor to be used as switch. My goal is to get you enough information so you can turn on and off devices that require between 40 and 400 mA of current with Nusbio's GPIOS.

Usage

Transistor can be used as
  • Switch
  • Amplifier
  • Binary logic

Type

There are multiples types of transistor, if you just need to remember 2 types
  1. BJT (Bipolar junction transistor)
    • Activated by sending some current to the base (more on this later) 
    • NPN, default off, activated when current is sent to base
    • PNP, default on, de-activated when current is sent to base
  2. MOSFET (metal–oxide–semiconductor field-effect transistor)
    • Activated by sending some voltage at the gate (more on MOSFET)
    • N-Chanel, default off, activated when voltage is sent to base
    • P-Chanel default on, de-activated when voltage is sent to base

Switch Configuration

In this paragraph we are going to use a BJT transistor and configure it as a Switch. A BJT transistor has 3 pins C, B , E.

  • The C stand for Collector. Remember the following:
        In a Switch mode configuration the Collector collect the load.
    What that mean is in a electrical circuit one component is consuming current (a light or motor), that is the load. The transistor Collector should be plugged just after the component creating the load.
    The negative of the controlled device should be connected the collector and the positive of the controlled device should connected to the source of power. As a software developer I would call it the input.
  • E stands for Emitter which in a Switch mode should be connected to ground, as a software developer I would call it the output.
  • B stands for base which is connected to for example a GPIO, as a software developer I would call it the API. Don't forget to add in between the GPIO and the base a resistor (for now let's say 1k).
In short the current will flow from C to E, if a small amount of current is sent to B (for NPN transistor)

Datasheet

Double check the transistor datasheet to know the maximum voltage and current supported by the transistor.

I often use the 2N3904,  it is a BJT NPN. In datasheet I found the following

The maximum voltage supported is 40 (Vceo) and the maximum current that can flow throw the transistor is 200 mA (Ic). Nusbio power comes from the USB and is 5 volts.

Eat Big Cookie

How do I find which pin is which? Turn the flat face toward you and say out load Eat Big Cookie.



Nusbio + Transistor


Wiring a BJT to Nusbio on a breadboard should look like that (it would be the same with an Arduino or Raspberry PI)



Videos

A video from MAKE and Collin Cunningham: MAKE presents: The Transistor

1 comment:

  1. I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. kodux

    ReplyDelete