WAM Chapter 7: Measuring Light

Download Report

Transcript WAM Chapter 7: Measuring Light

A Modification of Chapters 5 & 7 Slides
Presentation based on:
"What's a Microcontroller ?"
By Andy Lindsay
Parallax, Inc
Presentation developed by:
Martin A. Hebel
Southern Illinois University Carbondale
College of Applied Sciences and Arts
Electronic Systems Technologies
9/10/03
1
Use and Copyright
This presentation supplements "What's a
Microcontroller" by Andy Lindsay. (Link to text at
Parallax)
 This presentation is not a replacement for the text.
 Important concepts of the text are highlighted.
 In some cases, additional material has been added to
augment the text. Denoted by titles colored gold.
 Full program listings are generally not provided in the
presentation.
Distribution:
This presentation may be freely distributed without
modifications. Modifications are permitted by schools
and organizations for internal use only. Credits, use and
copyright slides must remain.
2
COPYRIGHTS AND TRADEMARKS
This documentation is Copyright 2003 by Parallax, Inc. By downloading or obtaining a
printed copy of this documentation or software you agree that it is to be used
exclusively with Parallax products. Any other uses are not permitted and may
represent a violation of Parallax copyrights, legally punishable according to
Federal copyright or intellectual property laws. Any duplication of this
documentation for commercial uses is expressly prohibited by Parallax, Inc. Check
with Parallax for approval prior to duplicating any of our documentation in part or
whole for any use.
BASIC Stamp is a registered trademark of Parallax, Inc. If you decide to use the name
BASIC Stamp on your web page or in printed material, you must state that "BASIC
Stamp is a registered trademark of Parallax, Inc." Other brand and product names
are trademarks or registered trademarks of their respective holders.
DISCLAIMER OF LIABILITY
Parallax, Inc. and Southern Illinois University are not responsible for special,
incidental, or consequential damages resulting from any breach of warranty, or
under any legal theory, including lost profits, downtime, goodwill, damage to or
replacement of equipment or property, or any costs of recovering, reprogramming,
or reproducing any data stored in or used with Parallax products. Parallax is also
not responsible for any personal damage, including that to life and health,
resulting from use of any of our products. You take full responsibility for your
BASIC Stamp application, no matter how life threatening it may be.
3
Devices that Contain Light Sensors
The boebot uses sensors to interact with its
environment.
There are a variety of sensors used for a variety of
purposes: Pressure, rotation, temperature,
smoke, tilt, vibration, light and so on.
Light sensors are also used in a variety of
applications:
 Automatic street lights
 TV remotes using Infrared (non-visible light).
 Camera flash and exposure controls
 Security alarms
4
Introducing the Photoresistor
While there are a variety of light sensors, a very
popular one is the photoresistor in that it is easy
to use and inexpensive.
As the name implies, it is a resistor that reacts to
light. The active ingredient Cadmium Sulfide
(CdS) allows electrons to flow more easily when
light energy hits it, thus lowering it resistance
(opposition to current flow).
The brighter the light the lower the
resistance.
5
Why?
 A photoresistor is made of a high resistance
semiconductor.
 The photons of high frequency light are
absorbed by the semiconductor giving bound
electrons enough energy to jump into the
conduction band. The resulting free electrons
(and their hole partners) conduct electricity
thereby lowering resistance.
6
Basic Circuit
As the photoresistor’s
resistance changes with light
exposure, so does the voltage at
Vo. As R gets larger, Vo gets
smaller, and as R gets smaller,
Vo gets larger.
R
Vo is what the BASIC Stamp I/O
pin is detecting when it is
functioning as an input.
If this circuit is connected to
IN6, when the voltage at Vo is
above 1.4 V, IN6 will store a 1. If
Vo falls below 1.4 V, IN6 will
store a 0.
V0
7
A Better Idea: Measuring Using Time
The photoresistor can also be used with the
BASIC Stamp in an RC circuit (ResistorCapacitor circuit) to obtain a value in
relation to the amount of resistance, or, in
this case, the amount of light hitting the
sensor.
In a RC-network, the capacitor is charged
and discharged at different rates
determined by the resistor and the
capacitor sizes.
8
Introducing the Capacitor
The capacitor is a device which can store an
electron charge. Its size is expressed typically
in microfarads (F) or millionths of Farads.
Certain types of capacitors are polarity sensitive,
that is, they can only be connected in one
direction.
Connecting a polarity sensitive
capacitor backwards can cause the
device to explode.
•Wear safety glasses.
•Ensure proper polarity when
connecting.
9
10
Polled RC Time
In the Polled RC Time circuit the following occurs:
 Button is pressed charging the capacitor.
 The button is released, the BASIC Stamp
begins timing and the capacitor begins to
discharge.
5V
11
3. The BASIC Stamp continues timing until input
P7 changes to a low (drops below 1.4V).
LOOP UNTIL IN7=0
4. Time is displayed in tenths of seconds.
V => 1.4V
Logic 1
V < 1.4V
Logic 0
12
The time to discharge the capacitor is in
proportion to the size of the resistor and
capacitor network (RC).
The larger the capacitance (C), the
greater the charge it can hold, increasing
time.
The larger the resistance (R), the
slower the capacitor will discharge,
increasing time.
13
Activity #3: Reading with BASIC Stamp
The BASIC Stamp has an instruction to
perform much of the timing operation
automatically:
RCTIME Pin, State, Variable
Where:
Pin is the pin the RC network is connected.
State is the initial state when timing begins.
Variable is the memory location to store the
results. Just like PULSOUT the time is the
number of 2uS increments.
14
Activity #1: Build & Test Light Meter
The RC Time circuits is
configured so that the
capacitor is charged
by the output (P2 in
this case) and the
time to discharge
though the resistor is
measured.
In this case, as light
level changes,
discharge time will
change.
15
What happens to the value of time as the
light level changes? When is it lowest?
Highest?
16
FLASHLIGHT BEAM FOLLOWING BOE-BOT
Activity:
Test and calibrate your Boe-Bot’s light
sensors to recognize the difference
between ambient light and a directed
flashlight beam.
Program the Boe-Bot to follow the
flashlight beam that is pointed at the
surface in front of the Boe-Bot.
17
Adjust Sensors to Search for Flashlight Beam
Position the photoresistors’ light-collecting
surfaces are pointing ahead at separate
points on the ground about 2 in (5.1 cm)
in front of the Boe-Bot.
18
Wiring Schematic
19
Difference in light
 Know the difference between light readings with and
without the flashlight beam shining in the Boe-Bot’s
path.
' {$STAMP BS2}
' {$PBASIC 2.5}
timeLeft VAR Word
timeRight VAR Word
DEBUG "PHOTORESISTOR VALUES", CR,
"timeLeft timeRight", CR,
"-------- ---------"
DO
HIGH 6
' Left RC time measurement.
PAUSE 3
RCTIME 6, 1, timeLeft
HIGH 3
' Right RC time measurement.
PAUSE 3
RCTIME 3, 1, timeRight
DEBUG CRSRXY, 0, 3, DEC5 timeLeft, " ", DEC5 timeRight
PAUSE 100
LOOP
20
Use Constants
Use constants (from your table):
LeftAmbient CON 108
RightAmbient CON 114
LeftBright CON 20
RightBright CON 22
Calculate other constants
'
Average
Scale factor
LeftThreshold CON LeftBright + LeftAmbient /2 * 5 / 8
RightThreshold CON RightBright + RightAmbient /2 * 5 / 8
21
The Program
22
The Program
23
The Program
24