Photoresistor, Transistor, and LED's: Prelab Questions

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Photoresistor Laboratory PH-1

Photoresistor, Transistor, and LED’s

Prelab Questions
1. In the following circuit, L1 is a light bulb rated at 0.5 A at 5 V, and the transistor’s hfe is 100.
The light bulb L1 starts to glow when the current flow reaches 100mA, and if the current is
higher than 1A, the light bulb will burn out. If the resistance of the variable resistor VR is
gradually lowered from 10kΩ, at what value of VR will the light bulb start to glow? Is there a
value of VR for which the light bulb will burn out? If so, what is it?

L1
VR
5V

Figure PL-1 Lamp Control Circuit

Purpose
• To introduce photoresistors, LED’s, FET’s, and transistors used as power switching devices
• To become familiar with the capability of the Atmega 128 to measure the change of
resistance of a sensor using analog-to-digital conversion.
• To build and experiment with a light-controlled switch

Components
Qty. Item Qty. Item
1 10 kΩ resistor 1 22 kΩ resistor
1 solderless breadboard 1 470 Ω resistor
1 photoresistor 1 220 Ω resistor
1 2N3904, NPN transistor 1 red or green LED
1 Atmel Atmega 128, STK500 & STK 501 interface boards, and programming cable.

Introduction to the Photoresistor


A photoresistor is simply a resistor whose resistance depends on the amount of light incident
upon it. They are used to make light-sensitive switching devices. Photoresistors are often made
from cadmium sulfide (CdS). The resistance of a CdS photoresistor varies inversely to the
amount of light incident upon it. In other words, its resistance will be high in the dark and low in
the light.

©San José State University Department of Mechanical and Aerospace Engineering Spring 2005 19FEB05
Photoresistor Laboratory PH-2

Procedure
1. Measure the photo-resistor’s resistance in the ambient lighting of the lab. Once this is
recorded, repeat the measurement, only this time, cover the cell with your hand. These two
extremes will be used in calculations later on.

Introduction to the Light Emitting Diode (LED)


The LED behaves like an ordinary diode except that when it is forward biased, it emits light.
The LED’s forward voltage drop is higher than an ordinary diode. Typical LED’s require 5 to
15mA to reach full brightness, but are not designed to handle more than about 20 mA of current
(though some can handle upwards of 80 mA or more). You will therefore always need to
provide a resistor in series with an LED to limit the current to about 20 mA or less, or else you
will burn it out. Also, don’t make the mistake of trying to substitute an LED where a standard
diode is called for! Look at the schematic diagram to see which kind of component is needed.

Procedure
1. To verify the behavior of the LED, construct the circuit shown in Figure 1, and vary the
supply voltage between 1 to 8 volts at 1-volt increments. At each voltage, measure the
voltage across the LED and the 470 Ω resistor and enter the values into the following
table. The LED current can be calculated by applying Ohm’s law across the resistor.

flat or notch
top
+ + 470 Ω
- V
side
+ - LED
anode cathode

Figure 1 LED and typical circuit. Note that the anode lead is longer than the cathode. Sometimes
there may be a flat on the cathode side of the LED to help you distinguish anode from cathode.

Table 1 LED circuit measurements (Refer to Figure 1)


Current, Comment on LED
Vsupply, Volts VLED, Volts VR, Volts
mA brightness
1
2
3
4
5
6
7
8

©San José State University Department of Mechanical and Aerospace Engineering Spring 2005 19FEB05
Photoresistor Laboratory PH-3

2. Figure 2 shows a simple ‘light-controlled-LED’. The circuit should turn-off the LED as the
photo resistor is covered. Explain the theory of operation of this circuit. Based on the
information obtained above, what is a good supply voltage to use? (Hint: V should be high
enough so that enough current flows through the LED when the photo resistor has low
resistance, and yet should be low enough so that the current is not enough to turn on the LED
when the photo resistor has high resistance.) Build the circuit and check its function.
RC

CdS V CdS
V

Figure 2 Light-controlled LED Figure 3 Light-controlled using a transistor “switch”

The Light-Controlled Switch Using a Transistor


A transistor can be added to the light-controlled-switch circuit to improve its sensitivity and
to eliminate the ‘half-on-half-off’ state of the LED. A rudimentary circuit to do so is shown
above in Figure 3 (you don’t have to build this circuit). Here the photoresistor controls the
transistor’s base current, which is then amplified by the transistor. The collector current of the
transistor, in turn, controls the LED. Unfortunately, this circuit may not function properly,
because when the photoresistor is in the dark state, (and the LED is supposed to be turned off),
the base current may be large enough that the LED may stay lit! Prove this, by calculating the
collector current for the circuit in Figure 3 when V=10 V, RCdS=100 kΩ, Rc=220 Ω and
hfe=100. Figure 4 shows an improved circuit. This is the circuit that you will build and
experiment with next.
Rc

CdS
2N3904
C
V B
E
B C
R1 E

Figure 4 Improved Light-Controlled Switch Using a Transistor

With a properly selected resistor R1, the voltage at the base of the transistor in the dark state
is less than 0.7 V, and therefore the transistor is in the cut-off state. As the photoresistor’s
resistance decreases (as the result of an increase in light intensity), the base voltage increases.
Once the base voltage reaches 0.7 V, the base current starts to flow, and any further decrease in
the photoresistor’s resistance causes an increase of base current. This base current increment
will be amplified by the current gain of the transistor.

©San José State University Department of Mechanical and Aerospace Engineering Spring 2005 19FEB05
Photoresistor Laboratory PH-4

Procedure
1. Choose the supply voltage. The supply voltage is often a predetermined value rather than a
design choice. For example, if a battery is to be used, the voltage will likely be 3, 6, 9, or 12
volts. In the following calculation and in later circuit construction, use any voltage of your
choice between 6 V to 15 V.
2. Select R1. First, determine a value of the photo resistor’s resistance (call it Ron) at which you
would like the LED to be turned on. The resistance value can be that for when the
photoresistor is covered or uncovered, it’s up to you. (Just make it clear in your report). The
value of R1 should be such that 0.7 = V*R1/(R1+Ron).
A variable resistor (trim pot) can be used so that the turn-on value can be adjusted.
3. Select Rc, the current limiting resistor. With this resistor, the collector current is limited to
Imax=(V- VLED - 0.4)/RC , where VLED is the voltage drop across the LED, and 0.4 V is a
typical saturation voltage between the collector and emitter. Select RC so that the LED
current is limited to be less than 20 mA (preferably 5-10 mA). Using Rc, construct and
test the circuit.

Using the Atmega 128 to Make a Programmable Light-Controlled Switch


The circuit in Figure 4 is very simple, but it suffers from the disadvantage that once R1 is
chosen and the circuit is constructed, you’re stuck with its performance unless you physically
remove R1 and replace it with a different value. That is not too serious if we are dealing with
one circuit on a breadboard, but suppose this circuit were part of a product that you were
manufacturing, say 1000 per day. If you wanted to change the performance of the device, you
would have to modify the assembly drawings, circuit board artwork, component inventory,
rework the entire work-in-process, etc. That would be a big deal! Here we will use the Atmega
128 to make a light-controlled switch whose performance can be modified by simply
reprogramming the microcontroller.
Procedure
1. Build the part of the circuit in shown in Figure 5 below labeled A. Connect the 10k resistor
to pin PC0 on the STK500 board using a jumper from the pin to the solderless breadboard.
Don’t forget that you need to supply power to the Atmega 128. You may use the +5V from
any VTG pin on the STK500 or STK501 boards for your circuit; however, be sure to double
check the voltage on the pin you wish to use with a voltmeter before connecting it to your
circuit. Likewise, you may use a pin labeled GND for ground. The voltage on PC0 will
either be 0 or 5 V. Which of these will turn the transistor on? When the transistor turns
on, is it saturated? Based on your earlier measurements on the LED and the
characteristics of the transistor, what are ib, and ic when PC0 is at 5 V?
2. Run the following program, and see if you can make the LED blink:
// Blink test program
// This program turns on an off the PC0 output with a 500ms delay
//----- Include Files ---------------------------------------------------------
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
#include <avr/signal.h> // include "signal" names (interrupt names)
#include <avr/interrupt.h> // include interrupt support
#include "global.h" // include our global settings
©San José State University Department of Mechanical and Aerospace Engineering Spring 2005 19FEB05
Photoresistor Laboratory PH-5

#include "timer.h" // include timer function library (timing, PWM, etc)


//----- Function Declarations--------------------------------------------------
void init(void);
//----- Begin Code ------------------------------------------------------------
int main(void)
{
init(); // initialize everything
while(1)
{
PORTC ^= 0x01; // toggle output bit PC0
timerPause(500); // pause for 500ms
}
return 0;
} // end main()
void init(void)
{
// initialize our libraries
timerInit(); // initialize the timer system
// Setup Digital I/O
DDRC = 0xff; // set PORTC to all outputs
PORTC = 0xff; // set all output pins to high
} // end init()

Explain how the PORTC output is toggled by using the ‘^=’ operator.

5V
Pinout for
transistor
Atmega 128 220Ω
STK500 & STK501
CdS 2N3904

Pin PF0
P15 C E
22k 10k C
B B
Pin PC0 2N3904
E
B A

Figure 5 Light-controlled switch using the Atmega 128. The photoresistor (in B) is part of a
voltage divider, the output of which is connected to pin PF0, one of the pins that can be used for
analog-to-digital conversion. Pin PC0 is connected to the base of a transistor (in A), which is used
as a switch for illuminating the LED when the light level on the photoresistor is beyond a certain
threshold value.

3. When you have successfully completed step 2, build the circuit in B shown in Figure 5, and
run the following program:
// Photoresistor and A/D test program
// This program reads the voltage associated with a voltage divider
// that contains a photoresistor and continuously prints the output
©San José State University Department of Mechanical and Aerospace Engineering Spring 2005 19FEB05
Photoresistor Laboratory PH-6
// to the Atmega 128 Serial Port
//----- Include Files ---------------------------------------------------------
#include <avr/io.h> // include I/O definitions (port names, pin names, etc)
#include <avr/signal.h> // include "signal" names (interrupt names)
#include <avr/interrupt.h> // include interrupt support
#include "global.h" // include our global settings
#include "uart.h" // include uart function library
#include "rprintf.h" // include printf function library
#include "timer.h" // include timer function library (timing, PWM, etc)
#include "a2d.h" // include A/D converter function library
#include "vt100.h" // include VT100 terminal support
//----- Function Declarations--------------------------------------------------
void init(void);
//----- Begin Code ------------------------------------------------------------
int main(void)
{
u08 level; // declare unsigned 8-bit integer
init(); // initialize everything
// print a little intro message so we know things are working
vt100ClearScreen();
vt100SetCursorPos(1,1);
rprintf("Welcome to the Photoresistor Laboratory!\r\n");

while(1)
{
// sample a2d channel and print them to the terminal
vt100SetCursorPos(2,1);
level = a2dConvert8bit(0);
// use a2dConvert10bit(channel#) to get a 10bit a2d reading
rprintf("Light Level: %d \r\n", level);
}
return 0;
} // end main()
void init(void)
{
// initialize our libraries
uartInit(); // initialize the UART (serial port)
uartSetBaudRate(9600); // set the baud rate of the UART
rprintfInit(uartSendByte); // make all rprintf statements use uart for output
timerInit(); // initialize the timer system
// Setup Digital I/O
DDRC = 0xff; // set PORTC to all outputs
PORTC = 0xff; // turn off all outputs
DDRF = 0x00; // configure a2d port (PORTF) as input
PORTF = 0x00; // turn off pull-up resistors on PORTF
a2dInit(); // turn on and initialize A/D converter
// set the a2d prescaler (clock division ratio)
// - a lower prescale setting will make the a2d converter go faster
// - a higher setting will make it go slower but the measurements
// will be more accurate
// - other allowed prescale values can be found in a2d.h
a2dSetPrescaler(ADC_PRESCALE_DIV32);
// set the a2d reference
// - the reference is the voltage against which a2d measurements are made
// - other allowed reference values can be found in a2d.h
a2dSetReference(ADC_REFERENCE_AVCC);
} // end init()

©San José State University Department of Mechanical and Aerospace Engineering Spring 2005 19FEB05
Photoresistor Laboratory PH-7

Once you have downloaded the program, connect a serial cable to the RS232 spare connector on
the STK500 board. Also, make sure that pins PE0 and PE1 are connected to the RS232 SPARE
header pins RXD and TXD respectively. This will make sure that the transmit and receive pins of
your Atmega 128 are connected to the serial connector on the STK500. Open a serial
communications program such as Hyperterminal that can connect to the Atmega 128 using
9600baud. Reset the microcontroller by pressing the reset button on the STK500 or by cycling the
power. What happens when you cover the photoresistor? What range of values are shown in
the communications window? What voltage do these correspond to? Now try using the 10-bit
reading instead of the 8-bit one. Remember to change the declaration of ‘level’ to an unsigned
16-bit integer so it can handle the extra bits. State the differences you observe between the two
methods.
4. When you have successfully completed step 3, write a program that will turn the LED on
when you cover the photoresistor with your hand. (Hint: add a test in the While loop that
compares the value of ‘level’ with a value slightly higher than that value for when the
photoresistor is covered. Experiment with the threshold value.) Display the state of your
LED on the terminal window.

What changes need to be made to the software (note: no need to change any hardware) if you
want to have the LED stay on under ambient light conditions and turn off when a shadow
falls on the photoresistor (i.e. the opposite function to what you programmed in step 4? Try
it.
Suppose the LED were replaced with a motor? You now have the knowledge to control devices
that require more power than the Atmega 128 can supply by itself.
Questions
Questions are those in bold type in the procedures above
Appendix – How to Solder
This section covers the fundamentals of soldering, proper care of a soldering iron, and safety
guidelines to follow when you solder. After you finish reading it, ask your TA for a protoboard,
and using it, solder up the LED and its current-limiting resistor from Figure 5. Add a couple of
wires, so that you can make a connection back to the solderless breadboard, and verify that your
LED blinks as it did before.
For more information on soldering beyond the tutorial below, check out:
http://www.kpsec.freeuk.com/solder.htm
http://www.epemag.wimborne.co.uk/solderfaq.htm
http://www.kingbass.com/soldering101.html
http://www.elecraft.com/TechNotes/N0SS_SolderNotes/N0SS_SolderNotesV6.pdf
http://www.bdmicro.com/smt/ (some tips on soldering surface mount chips)
http://www2.silabs.com/public/documents/tpub_doc/anote/Microcontrollers/en/an114.pdf (more
on soldering fine-pitched QFP devices)
Soldering Tutorial continued on the next page

©San José State University Department of Mechanical and Aerospace Engineering Spring 2005 19FEB05
Soldering Tips
for SJSU ME106 Students

Text and Illustrations


by Richard O’Balle
A1

What is soldering?
Soldering, like welding, is a method of connecting two or more pieces of metal. The
many applications of soldering include plumbing, stained glass making, and (of course)
electronics. Most soldering is basically a two-step process: 1) heat metal, and 2) apply solder.
Sounds simple enough, right? Well, like most skills getting good at it requires a bit of practice
and patience. Before we go any further, however, let’s cover some safety tips.

Safety
As you will learn later (or may already know) most solder contains lead (Pb), which is
well known to be a toxin. If you are PREGNANT or think you may be so, do NOT solder! In
fact, stay away from the area where people are soldering to avoid breathing any of the fumes
given off in the process. For those of you who are not pregnant, WEAR SAFETY GLASSES!
Solder does splatter occasionally, and you do not want a molten mixture of lead and tin in your
eye (it will ruin your week…not to mention your eye). Do not hunch over the piece you are
soldering or breathe the smoke generated while soldering. You will get a mega headache if you
huff too much of it. While soldering, you will find many awkward ways to hold your soldering
iron while trying to make connections. If (and when) you drop your iron, do NOT try to catch
it…trust me, let it fall. When you are finished soldering, WASH YOUR HANDS. Use your
common sense and if you see a dangerous situation arise, please inform the lab TA.

Soldering irons
The lab will provide soldering irons and solder for use in the lab, however, students are
encouraged to purchase their own soldering irons for home use. They are one of many tools of
the trade and come in very handy when repairing equipment or prototyping circuits. Several
inexpensive units are available; for example the Weller WLC100 soldering iron, which is a 40-
Watt soldering station (includes iron, stand, and sponge) for under $50. The business end of a
soldering iron is the metal tip, which can reach temperatures in excess of 700 deg F (remember
do not try to catch it if it falls). These tips come in many different styles such as conical, chisel,
screwdriver, etc. for many different applications. As a courtesy to your fellow students and lab
TAs, please acknowledge the following guidelines for iron tip care.
1) An iron is used to heat the metal. The solder is then applied to the heated joint. We do
not solder by loading the tip with solder and delivering it to a cold connection, this
ruins the tip very quickly and makes for lousy joints.
2) A good joint should not require much solder. Excessive solder makes the iron tip
crusty and hard to clean. It also makes your connection look like a hack job.
3) Wipe the tip clean after every connection. Yea, it may require getting up and putting
the sponge under the sink but you will be doing everybody a huge favor by simply
wiping the excess solder off the tip after every use.
4) Only set your iron down in an iron stand. Really though, this one shouldn’t even have
to be written down but it irks me every time I see a burn mark on the lab tables.
A2

5) When finished clean then tin the tip of the iron. Tinning is when you put a light coat
of solder on something. This will protect the tip from oxidation.

Solder
In the lab we will use primarily 60-40 rosin core solder (usually yellow packaging). This
is made up of 60 percent tin (Sn) and 40 percent lead (Pb). Note: if you kept your MatE 25 book,
look up the Pb-Sn phase diagram. Do you notice anything about the 60 percent tin composition?
The rosin core of the solder contains an inorganic acid, which cleans (a little bit) the metal you
are soldering as it melts. You may notice after making a solder connection that there are yellow
pools of the rosin on you work. These can be cleaned off with flux remover, which is an awful
smelling solvent but it makes your work look much better. If using an organic solder, (usually
red packaging) you do not need to use flux remover, however, you will need to wash all solder
connections with water when finished (just don’t plug your circuit in ‘till it dries).

Desoldering
Desoldering is a skill that is conveniently developed while learning how to solder. The
two most useful desoldering tools are desoldering braids (or wick) and a solder sucker. A
desoldering braid is made of woven copper, which is placed ON the undesirable solder joint.
When heated with the soldering iron, the solder flows into the copper braid. Note: you must
remove the braid quickly after the solder joint is clean or the braid will stick to your work. A
solder sucker is just a handheld suction pump that quickly removes unwanted solder from bad
joints. Desoldering can be a time consuming practice, so it is strongly advised that you try to
make good solder joints instead of counting on the desoldering tools to clean up messy
connections.

Soldering Tutorial continued on the next page


Good vs. Poor Soldering Practice

Picture 1 shows improper


soldering practice. Not
only is this poor slob
neglecting to wear eye
protection, but he is also
going to be inhaling a lot of
vaporized lead. Will
someone please help him!

Picture 1.

Picture 2 shows much better


form. Notice the safety
glasses and upright
posture. Nice job.

Picture 2.
Sample connections

Soldering Iron

Solder

Proto Board

Resistor
Jumper

Figure 1.
Two components, a resistor and a jumper wire are
connected together and to a thru hole proto board. This is
a common connection that will be made in the lab.
Figure 2.
This shows another view of Figure 1. The component leads are
pushed thru the hole in the proto board. They are then soldered to
each other and to the copper terminal on the proto board.

Figure 3.
Here is a close up view of Figure 2.
When the terminal and the leads
are sufficiently hot, apply solder to
the joint.
Finished Connection

Figure 4.
Now we see the final connection. The solder should firmly
connect the copper terminal and the wire leads. There need
not be excessive solder for a strong joint, the solder should
have a shiny appearance to it. If you see a whitish haze form
over your connection then it may be that all of the metal did
not get hot enough or that one of the leads moved while the
joint was cooling. In that case you may want to rework the
connection. Otherwise, clip the leads close to the joint and
you are done.

1 2 3 Picture 3.
Some of the tools needed
for soldering.
4 1) Helping Hands
2) Solder
3) De-soldering Pump
4) De-soldering Braid
5) Soldering Iron
5

You might also like