LDRs, LEDs and the color of VEX field tiles

Part 1.

One of the long term items on my “to do” list has been to get hold of a VEX light sensor and see how suitable it is for detecting colored objects, specifically the color of the alliance starting tile. Before jumping into that I’m going to deviate a little into some basic color science that needs, at least partially, to be understood so the behavior of the light sensor is a little clearer.

As you all know from high school physics, visible light is part of the electromagnetic spectrum with wavelengths in the range of approximately 400nm to 700nm (nm = nanometer or 1/1000,000,000 meter). Wavelengths below 400nm are on the boundary of ultraviolet, wavelengths above 700nm are becoming infra red light. Color scientists talk about the “spectrum” of a light source and illustrate this using a graph that shows its spectral power density against wavelength(see note 1). That is, how much energy (or intensity) each wavelength of light has.

When light is reflected from an object, some wavelengths may be reflected more than others. If long wavelength light is reflected more than short wavelength light we may perceive that as a red object, if short wavelength more than long we may perceive blue. To illustrate how light is reflected from an object a similar graph to that which shows the spectrum of the light source is used. The graph can either show the modified spectrum of a know light source or, more commonly, the relative reflectance value at each wavelength.

The third part of the color science puzzle is the detector that “sees” the light source. The human eye is stimulated by the light entering it, different wavelengths of light stimulate cells in our retina which our brain converts into the color we perceive. Light detectors also have different sensitivity to wavelengths in the same way objects reflect light at different wavelength. The human eye has a response know as the photopic curve (unless there’s not much light then it’s different, we don’t see colors when it’s dark). The VEX light sensor also has sensitivity to different wavelength, conveniently it’s quite similar to that of our eyes.

To make many of the measurements used in color science an instrument known as a spectrometer is used, now I just happen to have access to this type of equipment so decided to make some measurements of the light sources we have available from VEX (ie. leds) and the reflectance of the blue and red field tiles.

Measuring the light sources is the easiest, here is (more or less) the spectral power graph for the three VEX leds as well as a white led flashlight I have (unfortunately I don’t have a VEX flashlight to measure).

[ATTACH]7620[/ATTACH]

The X axis of this graph is the wavelength of the light (you could think of it as the color of the light). The Y axis is the intensity of the light at that wavelength (think brightness, although that is over simplified). The green led is rather pathetic, not much light output there, yellow and red are both quite reasonable. Notice how the spectrum of an led is very narrow, only 10nm to 20nm at the 50% point. The white led has a much broader spectrum with two peaks, I would assume that two different elements/materials are used. One centered on green with a wide spectrum and then a secondary blue emitting substance used.

Contrast these to some other common light sources.
[ATTACH]7621[/ATTACH]

The black curve was captured from the window by my desk, it has a very broad spectrum centered on 500nm. The red spectrum was from a florescent light, it’s very spiky with the energy concentrated into three primary wavelengths. I’m also showing on this graph the sensitivity of a typical cadmium sulphide (CdS) light sensor. It matches quite closely the daylight spectrum, it’s most sensitive to light in the 500nm to 600nm range (greenish) and less so at the red and blue ends.

The final graph shows how the colored field tiles reflect light. To make these measurements a known light source, in this case a white led flashlight, illuminates the field tile and the reflected spectrum is captured. The reflected spectrum is processed such as to normalize the light source, that is, the spectrum is modified assuming that the light source has equal energy at all wavelengths (its spectrum would be a horizontal straight line). The processed data now has the relative reflectance for all wavelengths, we show this on a scale of 0 to 100%.

[ATTACH]7622[/ATTACH]

As you might expect, the red field tile reflects most light at the long wavelength end of the spectrum (after all, that’s why we see it as red). The blue tile reflects at the lower end but also reflects relativity less light than the red tile.

In part two, I will talk about the VEX light sensor a little more and show how we can use this data to help us use it for colored tile detection.


Note(1)
For any expert readers of this post, the graphs here do not actually show spectral power density but rather the raw output from my spectrometer. Working with spectral power density data requires a more calibrated and stable setup than I could create in the school robotics classroom yesterday. I may redo the experiments sometime in my lab at work but for illustrative purposes that’s not really needed.

4 Likes

**Part 2.
**
The VEX light sensor consists of a CdS (cadmium sulphide) photocell in series with a 100K resistor. As light falls on the CdS device (which is also called a light dependent resistor or LDR) its resistance falls, when completely dark the resistance measures at about 100K ohms, sitting in the ambient light at my desk the resistance measures at 4K ohms, shining a small led flashlight on the sensor the resistance falls to 500 to 1000 ohms.

Unfortunately, the light sensor was designed before the cortex for use with the old PIC controller. When the cortex was designed the new micro-controller used analog inputs with a range of 3.3 volts whereas (I assume) the PIC used a 5 volt device. To allow 5 volt sensors to be used with the cortex a simple voltage divider circuit was used on the cortex analog inputs to reduce the input level to the internal micro-controller. As we found with the status output of the power expander, the much lower input impedance of the cortex as compared to the PIC has caused some problems with the older sensors. Here is an equivalent circuit showing the VEX light sensor connected to the cortex.
[ATTACH]7627[/ATTACH]

The input impedance of the cortex is about 30k ohms, so why does this matter? We lets examine the two extremes of light sensor resistivity, with lots of light falling on the sensor its resistance will drop towards 0 and the analog input to the cortex will become almost 0 volts. As the light is reduced, resistance of the sensor will increase and become around 100K ohms. As there is already a 100K resistor in series with the photocell the voltage output at that time should become about 2.5 volts, however, we have the 30K input impedance in parallel with the CdS device giving a combined resistance of 23k ohms. The voltage across a 23k resister in series with a 100k resistor is only about 1 volt. What all this means is that the analog value we read in the cortex is not linear with respect to resistance of the CdS photocell.

[ATTACH]7624[/ATTACH]
light_sensor_voltage.jpg

Whether this really matters is hard to tell, the relationship between light falling on the CdS sensor and its resistance is also not linear but a log-log relationship. Log( resistance) is inversely proportional to log( lux ), you can lookup what lux is here.

So back to detecting the field tiles, what does all this information mean.

There are three parts of the color detecting system to be optimized.

The sensor is fixed, the VEX light sensor, there’s no other choice here.

The tiles are fixed, no choice here either, we know how each one reflects light.

We have a choice of several light sources.

  • Ambient light.
  • 3 VEX leds of different colors.
  • The VEX flashlight (which I am assuming is the same as my white led flashlight for this discussion)

Lets look at the choices.

  • Ambient light
    This could be used, however, the environmental conditions of the field will not be known in advance. Different light sources have very different characteristics (see the daylight and florescent light comparison), it’s therefore probably not a sensible choice.

  • leds
    The data shows that none of the leds are reflected from the blue field tile
    The red led is reflected from the red field tile, the yellow led will be reflected but at a significantly reduced level as its peak of 593nm is at the edge of the red tile spectral response.
    The red led has a spectral peak of 660nm, this is towards the upper end of the light sensor sensitivity. With the weak output from the led, low sensitivity of the light sensor and the difficulty in detecting low light levels due to non-linearity of the cortex A-D inputs, it probably will not work.

  • The vex flashlight
    A reasonable spectrum with energy at both blue and red ends, however, we have one issue using the flashlight directly. Lets look at the field tile data in a different way, here is a graph of the spectrum of reflected light from each one without the normalization I applied in the last post.

[ATTACH]7625[/ATTACH]

The amount (area under the curve) for both blue tile and red tile is similar, the red tile does reflect a little more light in absolute terms but it’s still going to be hard to discriminate between the two.

So what’s the answer.

Well, we need to add one more element into the detection system, an additional light filter that either pre filters the light to contain only energy where we want it or post filters the reflected light entering the CdS sensor. In other words we need either a red or blue filter to place over the flashlight or light sensor. The easiest way to get a selection of colored filters is to buy a filter swatch book from a company such as Lee.

http://www.shop.leefiltersusa.com/Swatch-Book-Numeric-Edition-SWBN.htm

Very inexpensive and lots of filters to choose from.

For instance, if you choose to transmit just the red light, look for a filter that matches the cutoff point for the red field tile, somewhere around 600nm. The swatch books usually give the transmission of each filter in a similar way to the graphs I have been using, for example, here is the data for Lee filter 164, flame red.

[ATTACH]7626[/ATTACH]
flame_red.jpg

It cuts off all light below 550nm and would effectively render the blue tile as black as seen by the CdS sensor.

So that was an awful lot of technical information to arrive at the conclusion that many of you probably know already.

Use the VEX flashlight with a red filter over the light sensor :slight_smile: I would also turn the flashlight on and off under software control and look for a difference in the light sensor output. This should help eliminate effects due to additional ambient light that may be present at some competition venues.

3 Likes