University of Pennsylvania Department of Electrical and Systems Engineering ESE 111 – Intro to ESE Lab 1 – Introduction to Circuits and MATLAB Introduction: In this lab, you will learn how to build very basic circuits, use some of the lab equipment, and use powerful software to plot and analyze data measured from your circuits. The following concepts, components, and tools will be used throughout this lab. Ohm’s Law: As you may recall, the most basic relationship between voltage, current, and resistance is given by Ohm’s Law: , where V is voltage (in volts), I is current (in amperes, or amps), and R is resistance (in ohms). You are going to use this simple relationship to observe the difference between the ideal resistance and actual resistance of the resistors that you find in the lab. Resistors: Even though resistors are one of the most basic electrical components, they are the most ubiquitous. Nearly every circuit has at least one resistor, either as a discrete component or as a part of another component. A resistor’s value is labeled on it in the form of the colored bands around its body. For an explanation of how to decode a resistor’s value, ask a TA or go to http://en.wikipedia.org/wiki/Electronic_color_code. Light-emitting Diodes (LEDs): A diode is a special circuit component that only lets current pass through in one direction. As you may have guessed from the name, an LED is a diode that emits light when current flows through it. Each kind of LED takes a specific voltage to light up, usually between .5V and 2V. Digital Multimeter (DMM): A DMM is an instrument that measures various characteristics of an electrical circuit or component. You will be using a DMM to measure resistance, voltage, and current. Power Supply: Power supplies provide electrical power at either a set current or a set voltage level. We will be using it as a voltage supply, providing a set voltage to our circuits. MATLAB: MATLAB is an incredibly powerful piece of software used for everything from performing basic mathematics to analyzing and plotting large datasets to controlling complicated experimental setups. As such, it is a fundamental part of the modern engineer’s toolbox. Goals: - Learn how to prototype simple circuits on a breadboard Learn how to use the power supply and digital multimeter (DMM) Understand Ohm’s Law and how to apply it Learn how to use MATLAB to plot and analyze data Created by Nick Howarth (EE ’13) and Sam Wolfson (EE ’13) Last updated: September 9, 2012 Procedure: 1. Build a simple LED circuit - Pick out a light-emitting diode (LED) and a 1-k resistor (Brn-Blk-Red-Gld). Measure the resistance of the resistor using the Digital Multimeter (DMM). Find the appropriate cables from the red box at your station and connect them as shown in Figure 1. Turn on the HP 34401A DMM at your station. To measure resistance, press the button with the omega symbol (third button from the left in the top row). Figure 1: Measuring resistance with the HP 34401A DMM You will now build a very basic circuit on a breadboard, also called a protoboard. The breadboard that we are using, shown in Figure 2, features rows of holes (1 – 63) arranged in sets of five (a – e, f – j) on each side of the partitions. Each of the five holes in a row is electrically connected by a conducting plate running underneath. Therefore, if you were to connect a wire from 5V to a hole, anything connected to the other four holes in that row would be at a potential of 5V. The set of holes to the right of a red line are connected within that column. Likewise the set of holes to the left of a blue line are connected within that column. Figure 2: Breadboard The circuit that you will build will light up an LED. Current will pass from a 5-V source through a 1-k resistor and the LED to ground, or 0V. Two equivalent schematic representations of this circuit are shown in Figure 3. Figure 4 shows this circuit built on a breadboard, where the red wire goes to 5V and the black wire goes to ground. (By convention, red signifies connection to the positive power source and black signifies connection to ground.) Figure 3: Equivalent schematic representations of the simple LED circuit Figure 4: Simple LED circuit represented by Figure 3 - Build the circuit shown in Figure 3. Consult Figure 4 for clarification. The longer leg of the LED is the positive end (Figure 5), so make sure that end is connected to the voltage source. Figure 5: LED Schematic (Source: http://www.societyofrobots.com/electronics_led_tutorial.shtm) - You should always put a resistor in series with an LED in order to limit the current flowing through the LED (and thereby prevent it from burning out). Always make sure no bare wires are touching! Connect the banana plugs at the ends of the wire clips (from Figure 4) to the HP E3631A Triple Output DC Power Supply as shown in Figure 6. Figure 6: HP E3631A Triple Output DC Power Supply - - - Turn on the power supply by pressing the Power button. To set the voltage across the terminals on the left with the “6V” label above them, press the “Display Limit” button. Then press the “+6V” button and use the knob and arrow buttons on the right to set the voltage to 5.000V. Generally, it is also good practice to set a current limit to minimize the risk of overpowering your circuit and blowing something up (which means you’ve done something wrong). To set the current limit, press the “Voltage | Current” button on the right, and then use the knob and arrow keys to set the current to 0.500A. Once your voltage and current limit are set, press the “Output On/Off” button to turn the output on. Your LED should now be lit! Now that you have a completed circuit, you can use the DMM to measure the voltage drop across each of the components and the amount of current running through the circuit. - - Press the button labeled “DC V” (for Direct Current Voltage) on the DMM, as shown in Figure 7. To measure the voltage drop over a component, the DMM leads must be placed in parallel with that component (see Figure 8). Measure the voltage drop over the resistor by clipping the leads to the legs of the resistor, as shown in Figure 9. Now measure the voltage drop over the LED. Do these two measurements add up to 5V? Figure 7: Measuring DC voltage using the HP 34401A DMM Figure 8: Schematic showing voltage drop measurement over resistor Figure 9: Measurement of voltage drop over resistor - - - To measure current, move the red banana plug from the top-right hole to the bottom-right hole, as shown in Figure 10. Then, press the blue button labeled “Shift,” followed by the “DC V” button to select “DC I” (‘I’ represents current). The DMM must be placed in series with the component(s) through which you want to measure current (see Figure 11). Connect the DMM leads to jumper wires and connecting them in series with the resistor and LED, as shown in Figure 12. (You can avoid using extra wires by disconnecting the right lead of the resistor and the left lead of the LED from the breadboard and clipping the DMM leads to these leads to complete the circuit, ensuring that the current passes through the DMM.) Based on your measured voltage drop over the 1-k resistor, does your current measurement make sense? Use Ohm’s Law (V = IR) to verify your findings. Figure 10: Measuring current using the HP34401A DMM Figure 11: Schematic showing measurement of current through the simple LED circuit Figure 12: Current measurement through simple LED circuit 2. Adjust the brightness of the LED with a photoresistor A photoresistor, sometimes called a photocell, is a form of variable resistor whose resistance decreases with exposure to light. In effect, a photoresistor is a light sensor. Figure 13: Photoresistor - - Obtain a photoresistor, like the one shown in Figure 13. Using the DMM, measure the photocell’s resistance as you vary its exposure to light. Remember to use the DMM setup from Figure 1 to measure resistance! Approximate the maximum and minimum resistances it can achieve. Press the “Output On/Off” button to turn the output off. You should always make sure that the output of the power supply is OFF before modifying a circuit. Replace the 1-k resistor in your circuit from Figure 3/4 with the photoresistor. Press the “Output On/Off” button to turn the supply power to the circuit. Use your hand to adjust the amount of light exposed to the photoresistor, and observe the effect that it has on the LED. 3. Use MATLAB to plot voltage vs. current characteristics of a resistor MATLAB is an incredibly powerful piece of software used for everything from performing basic mathematics to analyzing and plotting large datasets to controlling complicated experimental setups. As such, it is a fundamental component of the modern engineer’s toolbox. In this section, you will measure the current through a resistor at different voltages and plot this data using MATLAB. You will then compare your experimental data to the ideal resistor model. Recording voltage and current measurements from circuit - Choose a random resistor from the component bins. Measure and record its actual value. Build the circuit represented in Figure 17. Remember that the DMM must be connected in series with the resistor to measure current, and the red banana plug must be plugged into the bottom-right hole on the DMM. Consult Figure 10 for clarification. Figure 17: Current measurement circuit schematic - Vary the voltage from the power supply by one-volt increments, recording the current through the resistor at each increment. Start at 0V and stop at 6V. Record the data in a table like Table 1. Table 1: Supply Voltage vs. Measured Current through a __- Resistor Voltage (V) Current (mA) 0 1 2 3 4 5 6 Opening and using MATLAB Like any good engineer in possession of experimental data, you must now be itching to plot it and figure out what it means. It’s time to use MATLAB to scratch that itch. - To open MATLAB: Start menu All Programs Mathematics MATLAB R2012a The MATLAB window by default contains several sections. For now, you will be working in the section labeled “Command Window” (the big window in the center of the screen). In this window, you can enter commands one line at a time. MATLAB stores data in vectors, represented as a list of numbers enclosed by brackets. For example, [1 2 3] is a vector with components 1, 2, and 3. There are two basic types of vectors: row vectors and column vectors. - Type [1 2 3] into the command window in MATLAB and hit enter. This is an example of a row vector. Now type in [1;2;3] and hit enter. This is an example of a column vector. Another way to enter a column vector into MATLAB is to add an apostrophe (‘) to the end of a row vector. Figure 18 shows the Command Window output after these row and column initializations were entered. As you can see, the components in a row vector are arranged horizontally, and the components in a column vector are arranged vertically. Figure 18: Output of MATLAB Command Window showing vector initialization Creating row vectors to store measured data - Create a vector named “V” to store your voltage data by entering “V = [0 .5 1 1.5 2...]” Create a vector named “I_exp” to store your experimental current data in the same way that you created the “V” vector. Figure 19: Example of vector initialization to store experimental data Plotting experimental data - - Enter “plot(V,I_exp)”. This will make a line graph of the points with the x-values given by the “V” vector and the y-values given by the “I_exp” vector. Enter “title(‘Voltage vs Current through a __-kOhm resistor’)”. This will add a title to your plot. You should include the value of the resistor you used in the title. Don’t forget the single quotes around your title, as these let MATLAB know that you are entering a string of letters and not a variable. Enter “xlabel(‘Voltage (V)’)” and “ylabel(‘Current (A)’)”. This will create labels for your x- and y-axes, allowing other people to interpret your graph. Figure 20 shows the commands used to create a plot of the voltage vs. current data. Figure 21 shows the plot created using data from an ideal 2-ohm resistor model. Figure 20: Commands to make plot of data Figure 21: Example plot of voltage vs. current for ideal 2-ohm resistor Calculating resistance from data Since (by Ohm’s law) , finding R given V and I is fairly straightforward: You will now use MATLAB to calculate the resistance at each voltage level, and then find the average value for resistance. - - - Enter “R = V ./ I_exp”. This creates a vector called “R” of the resistance at each voltage level. Don’t forget the period in front of the slash—this is important because it tells MATLAB to divide the entries of the vectors (first entry of V/first entry of I_exp, second entry of V/second entry of I_exp, etc) instead of just dividing the vectors. To find the average value of R, enter “mean(R)”. Note: if any of the entries of I_exp is 0, then you will have an entry in R that looks like “NaN”. This is MATLAB being upset about dividing by 0—to find the mean, you are going to have to ignore this entry. Compare the average experimental resistance to the resistance you measured using the DMM, and to the nominal (labeled) value of the resistor. Which is larger? Which do you think is most accurate? Now you are going to add lines to the plot to compare the voltage vs. current characteristics using the labeled resistance and the measured resistance to the experimentally determined line. Adding Additional Lines to a Plot - Enter “hold all”. This tells MATLAB to add more plot lines to the same figure. Enter “plot(V, {measured resistance}*V)”. Make sure that you replace {measured resistance} in the command with the actual value that you measured. Enter “plot(V, {labeled resistance}*V)”. Make sure that you replace {labeled resistance} in the command with the actual value with which the resistor is labeled. Enter “legend(‘experimental’,’measured resistance’,’labeled resistance’)”. This will create a legend on the plot so that you can tell which line is which. The commands to add example data lines to the plot are shown in sequence in Figure 22. The resulting plot should have three differently colored lines and a legend, as shown in the example plot in Figure 23. Figure 22: Commands to add lines to a plot Figure 23: Example voltage vs. current plot with multiple data lines Calculating percent difference - Calculate the percent difference between the labeled value and the measured value (from the DMM), the labeled value and the experimentally determined (calculated) value, and the measured value (DMM) and the experimentally determined value (calculated). The formula to find percent difference between two values A and B is: