![]() |
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
Initial Setup Requirements: |
Components:
Photocell
Multi I/O module
Resistors
Wire
Tools:
Soldering Iron
Solder
ohmmeter
A photocell is a type of resistor. When light strikes the cell, it allows current to flow more freely. When dark, its resistance increases dramatically. Photocells need some calibration to be responsive in the exact lighting scenario you have. They can be used to detect large or small fluctuations in light levels to distinguish between one light bulb and two, direct sunlight and total darkness, or anything in between. Each scenario requires a slightly different voltage divider setup, which we'll get into below.

fig. 1: concept diagram
The circuit used is a plain voltage divider. It is used since we need to present a voltage to the Analog In device and the photocell merely changes resistance. You can see in the circuit below that the as the resistance of the photocell reduces (as a result of more light reaching it) the voltage on Ain will go up towards 5V. If the resistance of the photocell increases (as a result of less light reaching it) the voltage on Ain will fall towards Gnd (0V).
For an explanation of symbols, refer to circuit basics

fig. 2: circuit diagram
The best way to determine what resistor to use in the voltage divider for this photocell, indicated with an 'r' in figure 2, is to take the photocell and an ohmmeter to the setting where you'd like to use it. With the ohmmeter leads connected to the photocell in your given light situation, note the measured resistance. This value or one slightly higher will likely be a good value for 'r'.
We measured the photocell available
in our store to have a resistance
of about 100
in bright sunlight and 500 k
in total darkness. If you want to use the photocell to detect when something
passed in front of the sun or another bright light source, you would then want
to use a lowish value resistor in the voltage divider. Note that 100
is probably a bit too small since (by Ohm's Law) this would result in I = V / R = 5 / 200 = 25mA which is quite a lot. You might consider a minimum resistor value to be 500
- which would result in a full light current of less than 10mA.
Ambient daylight in a room produces a resistance
of about 1 k
in the photocell. Placing a finger directly over it produced a resistance of
about 3 k
.
If this set of light conditions is appropriate, then a 1 k
resistor would be a good choice for the voltage divider. Remember, the purpose
of the voltage divider is to provide a counterbalance to the resistance the
photocell will have in the light conditions you want.
The
following wiring diagram is shown with a voltage divider calibrated for ambient
indoor daylight conditions. Connect one lead of the photocell to +5V, shown
using red wire in figure 3. Connect the photocell's other lead to a 1k
resistor. Connect a piece of wire from that same end of the resistor to an analog
in, shown here with yellow wire. Then connect the other end of the resistor
to ground .

fig. 3: photocell wiring

Fig. 4: Photocell Max Patch
The above Max patch shows the simplest implementation of a photocell sensor. The boxes above the t.intro.ain object all explain the different ways you can change the way information is read from the photocell. The sample rate changes the frequency (in milliseconds) at which Teleo checks for a new value. The min and max values limit the possible vales that can be passed on from the photocell. The resolution determines the accuracy with which changes in the value can be read. The number box on the bottom passes on the value from the photocell to be used in your application.
Objective
Control Flash with analog input from the photocell sensor through an Intro Module.
How To
1. Be sure your Teleo module and the photocell sensor are properly connected.
2. Run the Teleo XML server. Check the user guide for more information.
3. Create a Flash movie.
4. Insert the code found below into the Action Window in the first frame of a new layer called "Actions". The lines following "//" symbols are comments, which are ignored when the code is run but can help the coder keep track of what certain lines of code mean.
5. Run the movie, then vary the amount of light falling on the sensor by covering it with your hand. In the Output Window, notice how the "New Analog In Value" changes in response.
Code //import the MakingThings Class Libraries import com.makingthings.*; //create a new Intro Analog In object var ain:TIntroAin = new TIntroAin( 0 ); //read the analog input value each time it is changed ain.onValue = function( value:Number) { //display the current analog in value in a separate output window trace("New Analog In Value: " + value); //now do something useful with the value }
Detection
Use a photocell to determine
when a box is open or closed.
Target Sensing
Photocells are very responsive to laser light. Mount one at a specific location
to know whether a laser pointer is striking it or not. Note: laser pointers
can be so precise that you may need to diffuse the light by placing a piece
of semi-transparent paper over the photocell. Otherwise the laser's light could
focus in between the phtocell's sensing structures and avoid detection.
Touch Keypad
Photocells can be used in place of keys on a specialized keyboard of your design.
A person's finger will block light enough to trigger a readable change in voltage
through the Teleo's analog in. The controlling software can establish voltage thresholds that signify when the keys are "pressed".
Musical Instrument
Upward pointing photocells can make a nice music controller - as the hand of the user gets closer, it blocks more light reducing the value seen by hte analog in port. Max or other software reading the Ain port can use the incoming value to alter the pitch, tempo, volume or any other quantity.
| copyright © 2002-2004 MakingThings LLC |