Schedule‎ > ‎

03B: Electricity, Components and Analog I/O

Questions, Answers and Review

Electricity Basics 

There are two fundamental quantities in electrical systems:
  • Voltage, or electrical potential, which is the force that causes electrons to move and
  • Current which is the rate of flow of electrons

Electrons can flow through air but it takes tremendous voltage (or high voltage) to do that. Electrons flow easily through wire. Giving electrons a path allows them to flow. 

The resistor keeps the electrons from flowing too fast. If you connect the positive and negative pins of a battery directly together that's a short circuit. The rapid flow of electrons will cause the battery to heat up possibly causing it to burst and expose you to toxic chemicals. 

Ohm's Law

Ohm's Law is named after German physicist Georg Ohm. It's describes the relationship between voltage, electrical current, resistance and power. The 12 equations implied by Ohm's law are shown in the picture on the right. The most important formulas to remember are: 

Voltage (E) = Current (I) x Resistance (R) 

and 

Power (P) = Current (I) x Voltage (E) 

The others can be derived using simple algebra. Take the circuit above. The resistor has a value of 220 ohms and the battery pack delivers 3 volts. To compute the current we can use the formula:

Current (I) = Voltage (E) / Resistance (R) 
Current (I) = 3.0 volts / 220 ohms
Current (I) = 0.0136 amps (or 13.6 milliamps)

Question: How much power is this circuit using? 

Image source: Wikipedia/Matt Rider

Electrifying video: Electricity vs. Water


Schematic Symbols

Schematics are drawings that make it easy to show someone else a circuit without having to take a picture of a breadboard. In a schematic each circuit element has a symbol that's usually easy to draw by hand. 


Demonstration: Fritzing symbols and schematics in Fritzing.

Exercise 0: Draw a schematic. (10 minutes)

The Fritzing program is installed on class computers. Open it and start with a blank canvas. Add an Arduino UNO,  a resistor,
and an LED.  Connect them up with wiring.  Look at the Schematic and PCB. 
  • Save your project as resistor.fzz

Reading Resistors

Tinstruments_rescolorcode.jpghe colored bands on resistors tell you the resistors value in Ohms. The color code system was invented when it was not practical to write tiny numbers on the resistor and still exists today because it's very easy to use. The chart on the right shows what each color band means.

Some resistors have four bands and some resistors have five. You can tell which band is the "left" side because there's always a space before the last band, which tells you the precision or tolerance of the resistor. 

Questions: Color Codes

  1. Decode: Red - Red - Black
  2. Decode: Brown - Black - Red
  3. Decode: Blue - Green - Black - Brown
  4. What's the color code of a 550 Ohm resistor? 
  5. What's the color code of a 10,000 Ohm resistor?

Image Source: Make Magazine


Series and Parallel Circuits

Resistors (and other components) can be arranged in two fundamental configurations called series and parallel. Series configuration is pictured below:

When resistors are in series the resistance values add together. 

R (total) = R1 + R2 

Parallel configuration is shown in the picture below: 
When resistors are in parallel the equivalent resistance is:

R (total) = (R1 * R2) / (R1 + R2) 

Activity: What is the equivalent value if you put two identical resistors in parallel? (2 minutes)

  • Solve the parallel equation for any resistor value. 
  • R1 and R2 should be the same value 
  • Answer the following questions
    • What resistor value did you choose? 
    • What is the resistance of two of those resistors in parallel? 

Voltage Dividers 

A voltage divider is a special use of series resistors that is very handy when one of your resistors is a sensor or a knob. The picture below shows a potentiometer (which is a variable resistor) in series with another resistor. 


Notice the "Voltage" label. Controlling the knob or sensor will change the voltage on that wire. The formula for the voltage on the wire is:

eVoltage = Voltage (Battery) x R2 / (R1 + R2)

Analog Input and Output


The Arduino, like all processors, is Digital, it only understands ones and zeros. In order to make sense out of our analog world it takes special circuitry on the Arduino. In this section you'll learn how to control that circuitry using C++ commands.

Analog Input

Your Arduino has pins labeled with "A" and a number (e.g. A0, A1, etc). These pins are special pins because they are connected to an internal Analog to Digital Converter (A2D). That circuit turns a voltage into a binary number based on a reference. The reference sets the maximum allowable input voltage. An A2D gives you a coded number that represents a voltage between zero and the reference. The drawing below shows an example of how that number is generated:


The chart shows you how to interpret the output of a 3-bit A2D with a 5v reference voltage. The Arduino has a 10-bit A2D which means that the values it gives you are between zero and 1024 (way too many to draw!). The reference voltage can be set in your program but it's best to keep it at the default setting (5v). The Arduino code below reads the voltage on pin A0:


void setup() {
  // The default on Arduino UNO is 5v 
  Serial.begin(9600);
  analogReference(DEFAULT);
}

void loop() {
  // Read the voltage on pin A0
  int reading = analogRead(0);
}

How to convert from your analogRead value to a voltage:

analogRead will return values from 0 to 1023.  Since your reference voltage
is 5,  a value of 1023 means 5 volts.  A value of 0 means 0 volts.
You have a simple proportion:    5        v        where reading is
                                             1024      reading
the value you get from analogRead and v is the voltage associated
with that reading.

Example:  reading == 511:     5       v     solving for v:  5 * 511 = v * 1024
                                         1024      511
                                                                                             2555 = 1024v
                                                                                                   v = 2555/1024
                                                                                                   v = 2.5 volts!

03B Exercise 1: Read the 3.3 volt power rail. (15 minutes)

Add a cout statement to the code above to print out the reading. Connect pin A0 to the pin labeled 3.3v and read the value. 
  1. What value do you get? 
  2. Convert that to a voltage.   It might not be exactly 3.3 volts, what is it?
  3. Connect pin A1 to the pin labeled 5v and read the value using another cout.
  4. Convert that to a voltage.  what is it?
Save your program as voltmeter.ino and submit it to Canvas.  Answer the questions in your submission COMMENT area.

Analog Output

Arduino is not capable of making a true analog output. However, for many things that need an "analog" signal you can use a trick called Pulse Width Modulation. Arduino.cc has an excellent tutorial on PWM. Please read it.

Pulse Width Modulation

See the Pulse Width Modulations slides in the 03B-slides


You can use PWM to make an LED glow with different intensities. The LED blinks so fast your eye cannot see the difference. 

03B Exercise 2: Using Analog with LEDs (15 minutes)

Use your code from the 03B Pulse Width Modulation Activities.  Make sure you are using the
for loop that leads to a smoother dimming of the light. 
  1. Change the code so that the LED goes from dark to light,  then from light to dark,  smoothly!
  2. Compile and upload your code to verify it works correctly.
  3. Save your fader.ino file to submit to Canvas.
Comments