A proximity sensor insensitive to ambient light
Proximity sensors such as those described here work by emitting infrared (IR) light and measuring the amount of light that is reflected by an object in close proximity to the sensor. However, when other sources of IR light are in view (such as the sun), the sensor cannot know whether the light it is receiving actually comes from the IR LED in the sensor and has been reflected by an object, or whether it is just ambient light. This can cause the sensor to falsely believe that an object is close by, while in fact it just saw ambient light coming from the sun, an (incandescent) light bulb, or some other IR-light source (TL or fluoresent light bulbs usually don't emit enough IR light to pose this problem).
A simple solution for this problem is to measure the ambient light, and accounting for it when deciding whether an object is "in view". The sensor itself can be used for this: if the IR LED of the sensor is turned off, we know that only ambient light is reaching the phototransistor inside the sensor. Next, a second light measurement is done with the IR LED turned on, this time we'll measure both ambient and reflected light. The actual amount of reflected light can now be computed by taking the difference of both measurements. (Note that, due to non-linearity, possible clipping, etc. this will not compute the exact amount of reflected light; but for this application it's usually good enough).
To be able to turn of the IR LED in the sensor one modification needs to be made to the circuit: The positive side of the IR LED must not be connected to a fixed power source, but to a digital output of the PIC controller, so we can turn the LED on and off in software.

Example code (assumes the IR LED is connected to pin RC0, that RC0 is already set as an output using TRISCbits.PC0 = 0, and that readAnalog(channel) returns the result of an A/D-conversion of the specified channel):
#define IRLED PORTCbits.PC0 int readActualReflectedLight(int channel) { int ambient, total; IRLED = 0; // turn IR LED off to measure ambient light only ambient = readAnalog(channel); IRLED = 1; // turn IR LED on to measure ambient + reflected light total = readAnalog(channel); return ambient - total; // compute and return reflected light }
- Type:

Your shopping cart