PLEASE NOTE: This site is no longer being actively maintained. For frequently updated BeagleBone resources please visit Beaglebone.org.

Wednesday, November 26, 2014

On 3:35 PM by Richard St-Pierre

Overview

Are you a programmer looking to interface your program with the outside world... but unsure about the electronic components in your Proto Parts kit? How do I connect this component? What is this? Do I need a resistor? Which way does it go? Will it blow up? Where do I start?

The BeagleBone Black is a low cost powerful computer with extensive  I/O (Input/Output) capability and is perfect to control many devices.

This tutorial will get you started with basic electronic components and how to use them.

Introduction

Important notes about circuits:
  • Current is the 'amount of electron flow' in a wire or component. 
  • Voltage is the 'pressure pushing the electrons' around the closed circuit path.  
A working circuit requires:
  1. An energy source (battery, power supply)
  2. A load or device  (light, motor, IC chip...)
  3. A complete path (closed loop) from (+) to a device and back to (-) of the power source.

You may also want to view our Introduction to basic electronics components under resources.

What You Will Need


ProtoParts Kit Includes

  • 3x LED, Red, 5mm, through hole
  • 3x LED, Green, 5mm, through hole
  • 1x LED, RGY (Red, Green, Yellow), Common Anode, 5mm, through hole
  • 10x Resistor, 330 ohms, 1/4 Watt, film type 5% axial, through hole
  • 2x switch, mini tactile push-button
  • 1x header, 2.54mm (0.1 inch) male 8-pins
  • 1x header, 2.54mm (0.1 inch) female 8-pins
  • 1x potentiometer, rotary, 10 kilohms
  • 1x terminal block, 4-positions, 2.54mm (0.1 inch), green
  • 1x header, 2.54mm (0.1 inch) male right-angle, 8-pins
  • 1x relay 5V, through hole. SPDT 1Amp
  • 1x transistor. MOSFET N-Channel, 2N7000
  • 1x diode, switching, 1N4148

Click on links for additional component information from the manufacturer datasheets.

Components

Resistor

Resistor

One of the most common components (after the wire). A resistor limits the current in a circuit.

If a battery (or voltage source) is connected directly from (+) to (-) with a wire the current flowing through the circuit would be very large (short-circuit). This is BAD. Since there is nothing in the circuit limiting the amount of current.  A wire has almost zero resistance. The current would be almost infinite.

Ohms Law V = I x R      also    I = V/R

V:= Voltage (in Volts)
I:= Current (in Amperes,  'mA' milliamp is 1/1000th of an Ampere )
R:= Resistance (in Ohms)


example:   5Volts / 0.00001Ohms = very large current.  

Using a resistor limits, the current.

I (current) = V/R = 5Volts/1000 ohms = 0.005 Amps (or 5 milliAmps) 5mA for short.

Resistor can have values from less than 1 Ohm to 22 million Ohms or more.
This presents a challenge, with such a wide range of values...how can you tell how much resistance a resistor has (and they are pretty small).

Color bands are placed on resistors to identify the resistance value.

Resistor Color Code

The resistor in the parts kits have four color bands: Orange, Orange, Brown and Gold.
So the value is [3] [3] [0]  Ohms and [5%] tolerance.

All devices have some performance limits. The physical size of the resistor determines the power rating (how much power the resistor can absorb).  The kit resistors are 1/4 Watts.

Power = V * I  = I^2 * R

So a 1/4W resistor can absorb up to 0.25Watts without 'burning up'.

I = Squareroot ( Power/Resistance) = SQRT (0.25W/330 ohms) = 0.027 Amps (27mA).

Allowing more than 27mA current through the resistor is  likely to permanently damage it.
This resistor should not be placed directly across a battery or voltage of more than 9V.

Power = V^2/R = 9V*9V/330 ohms = 0.245 Watts

Resistance adds when connected in series (end-to-end).
330 + 330 + 330 = 990 Ohms (approximately 1000 ohms).


Resistance can be reduced when connected in parallel.  Two equal value resistors in parallel with be results in half the original value.  330 Ohms in parallel with 330 Ohms results in an equivalent value of 165 Ohms.

Push-Button Switch

Here is a very common push-button switch. These are used in many electronics to select menus and control operation. A switch makes contact between two wires.

Tact Switch Push-button

Push Button Connections
Only two pins are required for a basic switch. This push-button has four. As you can see in the diagram pin 1&2 are connected directly to each other (same for pin 3&4).  When the button is pressed, pins 1&2 and 2&3 connect via the switch and close the circuit (make a connection).
This switch uses 4 pins to allow a more secure mechanical mounting to the circuit board.

A bit more about switches

PULL-UP / PULL-DOWN Resistors

When a switch is connected to a circuit, and the switch is open (not-pressed) it appears to the circuit as if nothing is connected. This can 'confuse' the circuit.  In order to prevent this condition a resistor is used to 'pull-up' or 'pull-down' the signal when the switch is open.
Pull-up / Pull-down Resistor


Switch Bounce

Computers are very fast, and can detect very short signals. When a mechanical switch is closed (button is pushed) the metal contacts snap together. This action caused the contact to meet, but also bounce apart briefly (like a ball bouncing) and eventually settling down. This happens quickly (about 0.002 to 0.010 seconds) in duration. To a computer this is a very long time, and can cause the computer to see multiple contact closures.
Mechanical Switch Bounce Signal
A solution to this is a debounce software routine, that checks, waits and then checks again after 10ms if the signal is stable.

Diode

Diode and Symbol


A diode is a semiconductor device, that acts like a one-way street for electrons. The cathode (-) is marked with a black band around the body of the diode.
Diode Characteristic Curve
A forward biased diode will conduct current, with a forward voltage 'Vf' (0.7V for a silicon diode).
When a reverse voltage is applied the diode blocks the current from flowing. The diode can block the reverse current as long as the voltage is less than the 'breakdown' rating 'Vr' (typically 100V or more).

Diodes are used to convert AC (Alternating Current) to DC (Direct Current), as detector (AM radio), protection devices and almost all power supplies. An appropriate example use is as a free-wheeling protection diode for coils and relays (see: relay section below).

LED

LED with Identified Polarity


Probably one of the most fun, the LED is a simple low-cost component. An LED is a "Light Emitting Diode".  A special diode that emits light when "forward-biased" with the correct polarity (+/-) signals. The (-) side is called the cathode and the (+) side is called the anode. The anode (+) has a longer lead wire.

How much voltage do I need for an LED? This is a very common question.

Answer: An LED requires 'current' for proper operation. Approximately 0.01 Amps (10mA) is required to provide a bright glow from the LED. Controlling the current allows the brightness to be adjusted.
Calculating Resistor Value for LED
An LED has a 'forward' voltage Vled when operating (Vf in the diode characteristic curve).
Green, Yellow and Red LEDs have a Vled of about 2.1 Volts.  (Blue and White LEDs about 3.2Volts).

The LED current affects the brightness of the LED. A safe LED current range is from 1mA (dim) to 20mA (bright). (with exceptions for ultra-bright specialty LEDs).

Note: The BeagleBone has 3.3V logic levels, and a maximum output current of 4mA (most pins).

Example:

Calculating the resistor value (Vin =3,3V, 4 mA)

R = (Vin - Vled) / I

R = (3.3V - 2.1V) / 0.004A = 300 Ohms

We should use a common value of 330 Ohms.

Re-calculating the LED current (using 330 Ohms resistor):

I = (Vin - Vled ) / R

(3.3 - 2.1)/330 Ohms = 3.6mA

This limits the BeagleBone pin current to just under 4mA.

Summary:

  • LEDs need a minimum voltage of about 2.0-2.1 Volts, and 1-20 mA in order to work.
  • Use the 330 ohms resistors with LEDs for your BeagleBone projects.  


LED RGY

RYG LED pin diagram
3 Colors in One LED
This is a compact (3-in-1) LED. It contains a RED, YELLOW and GREEN LED in a single package.
The common cathode is typically connected to GND (-) of the circuit. Each LED is connected with a series resistor to the signal source.
R-G-Y LED with Current Limiting Resistors
Use 330 Ohms resistor to each LED. The common cathode connects to ground (GND) of the circuit.

Note: It is possible to use a single resistor in the common cathode pin, if ONLY a single LED will be ON at a time(this is not suggested if you are not sure, or learning).

Potentiometer

Potentiometer and Symbol

A potentiometer is an adjustable resistor--often associated with 'volume control' for sound applications. Adding a third connection point to a resistor allows us to select a resistance value between the ends of a resistor with values ranging from minimum to maximum.  The wiper (W) position determines the output value.  The potentiometer is the parts kit is a 10K (10,000 Ohms).

For the BeagleBone Black:
Typically (H) is connected to a voltage (BeagleBone VDD_ADC P9-32), (L) is connected to GND (P9-34), and (W) is connected to one of the Analog inputs (AINx P9-33,35-40)
Reminder : The maximum input voltage on Ain is 1.8V


Max power rating (not for motor speed control).
Do NOT build this circuit

Do not use a potentiometer to control the speed of a motor. The potentiometer is not rated for the power that would be required (it will be destroyed). Motor speed control is better achieved using PWM (Pulse Width Modulation)

Relay

Relay with Pin Assignment
A relay is a switch that is activated with an electro-magnet (coil). It is used to 'relay' a small control signal to activate a switch that can transfer more energy to a device (load). Computer logic level can only drive a small amount of current. In order to turn on devices such as motor, heaters, coils and larger circuit we need to use a relay. Alarm circuit often use a relay to control bells, sirens other circuits. In addition a relay provides electrical protection to a circuit, since there is mechanical isolation between the control circuit and the output switch.  There are three contacts:
  1. NC  (normally closed)
  2. NO (normally open)
  3. COM (common)
A common contact (COM) is switched between the NO or the NC contact. With no power applied to the coil the COM is 'normally connected' to the NC and the NO is open (no connection). Once power is applied to the coil the COM is disconnected from the NC and  a new connection is made from the COM to the NO contact. A transistor is typically used to energize the coil.

Transistor

N-Channel MOSFET and Symbol
A transistor is a device that can switch or amplify signals. A control signal 'tells' the transistor what to do. The parts kit contains a MOSFET (Metal Oxide Semiconductor Field Effect Transistor).  This transistor requires a positive voltage on its Gate terminal to sign it to turn ON. The S (source) terminal is typically connected to the ground (-) of the circuit. The D (drain) terminal is connected to the load (relay, LED etc). 

Example circuit:

MOSFET Transistor Driving a Relay


Circuit Operation:

A GPIO (General Purpose Input Output) signal from the BeagleBone -- when at a logic 'one'  level 'tells' the MOSFET to turn ON. The 330 resistor provides protection for the BeagleBone in case the transistor malfunctions.  Note the [G][D][S] terminal connections for the transistor. The diode 'D1' provides protection for the transistor (when the relay is turned OFF). D1 acts as a 'free-wheeling' diode that recovers the energy stored in the coil's magnetic field. The energy in the relay coil can produce a large voltage transient pulse, that can damage sensitive devices like the transistor. The relay contacts can be wired as required to control the load (a motor, other circuit etc).  The transistor buffers or boosts the signal for the GPIO.   The Relay Plus IO is an example of a dual relay driver with convenient screw terminals.

Terminal Block

4-Position Terminal Block


A terminal block allows a convenient way to connect to wires.
The wire is held secure with a screw that presses down on the wire to maintain a solid connection.
Example of terminal block in use

Going Further

Now that you have an overview of electronic components you may want to try one of our many projects.

Additional Project Ideas 

  1. Motor speed control
  2. Traffic signal lights
  3. Model train crossing lights
  4. Light chaser 
  5. Fridge door alarm 
  6. Rain level / flood alarm
  7. Voltage Booster
  8. Create your own !

We invite you to leave a comment on any of our tutorials and projects.