Modulated Colour Sensors
In order to have reliable line following, we at Team Robocon realized that calibration is one of the most important (and unreliable) aspects (fresh batteries aside :p ). So, we (Anirudh and I) started working on fool-proof line sensors that work unaffected by ambient light. Here is what we planned, what we did, and the problems we faced.
What we planned
Our plan was this: the intensity of ambient light is generally a constant, and if it varies, does so really REALLY slowly ( if one keeps switching a light on and off as fast as one can, one JUST ABOUT MIGHT be able to achieve a frequency of… *gasp* 10Hz (I tried. I reached 2Hz :P). So, we planned to give an LED a sinusoidally varying voltage as its source, and, so that it doesn’t get reverse biased, the source would have a DC voltage superimposed on it so hat the net voltage never goes below 0V, the LED is always on, and only its brightness varies. The light from this LED, if in contact with white, gets reflected, and if in contact with black, absorbed. In presence of ambient light, the light sensor always detects light, and the micro-controller ends up being tricked into thinking that the particular sensor is above white, even though it may be above black. So, this reflected LED light shines onto a photo-detector/LDR (in series with a resistor), and a voltage is dropped across the combo as usual. Since the received light’s amplitude is modulated, the resistance of the LDR, and hence the net voltage dropped across it, varies. Thus, the voltage across it will be a sine wave coupled with a DC voltage. In the absence of modulated light, the sine wave will not be present in the output voltage. Thus, it is this sine wave that is the solution to our long quest for ambient light-free-happy-happy-land. To detect this sine wave, we pass the output voltage through a high-pass filter, which permits ONLY this sine wave voltage through (provided of course, that the sine wave frequency is more than the minimum frequency that the filter allows). We don’t really need a band-pass filter as ambient light, being un-modulated, has no frequency (in varying amplitude, I mean) at all, let alone frequency high enough to cross the high-pass filter and mandate the use of a band-pass filter. The output from the high-pass has to now be rectified, so that only the positive half of the sine is let through. Then, we smoothen the bumpy wave with a capacitor, and voila! If there is a modulated light shining on the photodiode / LDR, we have a “high” output the capacitor, else the output is low.
All this will be interfaced with a micro-controller, right? So, here comes the million dollar question: where on earth do we get a sine wave from?
There are a number of possible (surprisingly, not-so-simple) ways:
- Use an R-C cascade:
What this does is basically keeps filtering the square wave. The Fourier’s series of a square wave consists of a number of frequencies of sine waves (refer to point 2 below). The RC cascade keeps filtering out these waves to end up giving us a sine wave. Here is the cascade that we modeled, along with the expected results:
The wave in red shows a pure sine wave, and the one in cyan is the output of this circuit, which is fairly close.
Here is the actual output we got at 30kHz, the frequency at which we input the square wave:
which is, in fact, fairly close. Here’s a pic of how the circuit looked like:
- Use TI’s UAF42 IC:
This method would involve converting one of Arduino’s PWM square wave outputs, or a the square wave output from a 555 timer IC into a sine wave of same frequency. Involving a single IC and 3 resistors, we thought it’d be a “cleaner” implementation- way more manageable (read: less pesky loose contacts). Details of how to use this can be found here, and its data sheet here. The how-to paper basically says that if used by a band-pass filter, all higher order terms in the Fourier series of the square wave get filtered out, leaving a pure sine wave. If the frequency is not among the ones specified in the paper, then the software filter42 needs to be installed, downloaded, and run… on DOS-BOX.
We tried this method, making the exact circuit given in the documentation above. However, this only made it LIKE a sine wave. We got the output as:
which isn’t exactly a sine wave, but is close to it (sort of). What we think should be done to improve this is cascade 2 resistors to get a higher order filter, but this defeats the very purpose: to keep the circuit simple.
- Use a Wien bridge Oscillator (or another of n number of oscillators that uses an op-amp):
Another method that we had in mind, but didn’t actually try, since method 1 gave us decent results.
So, with the sine wave generation done, we used a waveform generator to input a ready-made sine wave so that we could see the output in a CRO, and analyse how it plays out. Thats when we realized something we hadnt thought of before: when the LED is given an input sine wave as voltage, if the frequency is too high, the LDR doesn’t respond fast enough. We found the lower the frequency, the better the variation in voltage across the LDR looked (the LDR being connected to a voltage source through a constant series resistance, and the LED to a sine wave+DC voltage source; the LED shining directly onto the LDR). We experimented a little, and realized the LDR doesn’t respond to anything above 10kHz, and responds well to a frequency below 1kHz. But we had designed circuit 1 for 30kHz. Ahhhh!!! Back to the drawing board… (Or in this case, edx’s circuits and electronics circuit simulator). Oh well, we chose a frequency of round 620Hz, and continued with the wave generator (620Hz is one of the frequencies listed in the document above).
We had simulated the high-pass filter : diode rectifier : capacitor ‘smoothener’, and here is what we got:
Note that above, the voltage source is the voltage across the LDR.
What we observed in the circuit, though, was similar, but the output voltage was much lower ( a very sad 20mV).
Here is a video showing output across R in the above circuit:
Here is a video showing output across where the red probe is above, but without adding the capacitor:
Here is a video of the output shown by the probe, but in real life:
So, ya, its 20mV. Waaaaaaaaaayyyy too small. Even amplification isnt really helpful as any noise, if present, will be amplified too.