Infra Red Distance Ranger

For a pretty long time, the sensors that I used in my micromouse robots were ready made. Initially I used the dedicated micromouse sensors from TRI, then switched on to the more general purpose Sharp IR Distance Rangers and eventually used a combo of both in one of my mice. Gradually, as my mice became more custom made than ready-made, I felt the need of designing my own infra red distance rangers and I finally decided to take up the task when I entered the final year of my engineering. But months before taking up the problem, I had a long discussion on the topic with the British Micromouse Champion, Peter Harrison, on his famous Micromouse Online Forum. Take out time to read this thread, which is perhaps the most informative and concise piece of information available on the world wide web regarding the design of sensors for Micromouse. The techniques discussed there are simple and easy to implement. When I took up the task to design my own sensors, concepts of analog electronics and op-amps were fresh in my mind and I had a theory of my own. Read the article below to see how I have progressed.

Sensor Structure →

The sensing system consisted of two major components, the Transmitter and the Receiver. The transmitter chosen was TSAL6100 from Vishay Semiconductors and the receiver was TSL262 from Texas Instruments. It should be noted at this point that it has taken me quite some time to build reliable sensors and the aforesaid components were finalized after a lot of hit and trials with the locally available stuff.

The transmitter and receiver were arranged in the following manner,

Transmitter and Receiver Considerations →

While choosing the transmitter IR diode and the receiver, one must keep in mind that their wavelengths should match. This ensures maximum sensitivity of the receiver. In our case, the photodiode spectral response curve of the TSL262 (page 3 of the datasheet) shows that the maximum relative responsivity occurs at 940nm. Thus, we must choose our transmitting IR Diode (TSAL6100) that should operate at a wavelength of 940nm to ensure maximum performance from our sensor.

The transmitting IR diode should have a high radiation intensity. Generally, this would give the sensor a longer working range. A higher dynamic range, though, hugely depends on the filter circuitry and software employed at the receiver’s end.

The beamwidth of the IR diode is also of great importance in the performance of the sensing system. A narrow beamwidth helps in detecting edge transitions (i.e. in detecting maze wall edges) but greatly suffers from maze wall’s surface imperfections. A fast mouse should be able to reliably detect maze wall edges and hence the corners in order to make accurate high speed turns. On the other hand, a broad beamwidth results in a better surface imperfection rejection but the sensor output gradually transitions from higher voltage to lower voltage when the mouse moves away from the edge and vice-versa, making detecting edges a bit difficult. This compromises mouse’s ability to take high speed turns. Thus, we see that there is a compromise in detecting edges and rejecting surface imperfections. The following diagram shows the sensor output for narrow and broad beamwidth to illustrate the concept,

Design Requirements →

Major design requirements that the sensors must comply to,

  1. The sensors should be able to successfully reject the ambient IR radiations present in the surroundings.
  2. As the unit cell dimensions of a micromouse maze are 18x18cm, the sensors should have a usable range of 15cms at least.
  3. The sensor output should be as linear as possible.
  4. Needless to say, they should be very compact.

Sensor Architecture – I →

At the transmitting end, the IR Diode was pulsed at a frequency of 10kHz with approximately 50% duty cycle. This continuous pulsing was done with the help of a 555 timer IC.

On the receiver side, the output of TSL262 was fed to a high pass sallen-key filter having a cut-off frequency of 8kHz. The sallen-key filter’s output was then fed to the ADC of the microcontroller for further processing.

The high pass filter on the receiver end ensures that the signal reaching the ADC is free from ambient IR radiations. The amplitude of the received signal is directly proportional to the distance between the maze wall and the sensor. Hence, we are only interested in the amplitude of the received signal.

Problems with Sensor Architecture – I →

After doing tests on circuit simulation software, I realized that the high pass filter outputs a square wave having a frequency of 10KHz and converting it into digital form, assuming the ADC to be sampling and converting at a frequency sufficiently higher than 20KHz (Sampling Theorem), resulted in a digital square wave. Since, we are interested in the amplitude of the received signal, the converted data was not good enough to be used directly to determine the sensor’s relative distance from the wall.

A simple solution to the problem was to introduce a Peak Detector in the signal conditioning chain. The peak detector will hold the amplitude of the input signal, which shall give direct information about the wall distance. There were now two options of either going for the digital or the analog peak detector. The choice of implementing a digital peak detector was almost immediately rejected because the microcontroller was an 8-bit 16MHz ATMega32 with 2KB RAM and 32KB Flash, certainly not powerful enough to handle more than 20,000 samples per second apart from doing a lot of other stuffs. Analog peak detection became an obvious choice now.

Sensor Architecture – II and Problems (again) →

This time, I added an analog peak detector between the high pass filter and the microcontroller’s ADC. The thought, as stated before, was that the output of the peak detector will hold the amplitude of the received signal and the amplitude will be directly proportional to the distance between the sensor and the maze wall.

The sensor architecture looked like this →

Naively, I had neglected an important aspect of the peak detector, timing of the reset switch. Looking at the circuit diagram of a basic peak detector circuit, there’s a reset switch which is used for resetting the detected levels.

from Wikipedia

If the peak detector is not being reset every time before taking a new sample, the peak detector will hold on to the previously detected peak. The output will change in only one case, if the sampled peak is higher than the previously detected peak. This is a big problem because if the micromouse starts to drift, which always happens (no mouse can go straight without taking feedback from its sensors and then correcting itself), walls will be coming closer to one side sensor and going away from the other one. Hence, one of the side sensors’ output will be decreasing all the time. In this case, the peak detector without proper resetting will output a previously recorded high peak which is definitely not the correct interpretation of the scenario. Thus, the timing of peak detector turned out to be more important than I previously thought.

Now if I wanted to make this thing work out properly, it required that the peak detector be reset before each sampling instant. Not tough, but already the circuit for a single sensor unit had become uncomfortably large. Adjusting it on a 10x10cm(max!) PCB with the microcontroller and stepper motor driver was giving me nightmares, not to mention the noise that could creep in such packed switching analog and digital circuits. ‘Noise’ has made me suffer a lot in my early days with electronics. So, I finally decided to drop this sensor architecture altogether.

Frankly speaking, I could never make this architecture function properly on bread board either. I could never get the timing right, I tried to do it with I/O pins and output compare peripheral but the readings never came out to be stable. Using the ATMega’s ADC in 8-bit mode, the values will sway from anything near 150 to around 90. Sometimes the see-saw continued even when there was no object in front of the sensor. The behavior was rather unpredictable. This made me safely assume that there was some fundamental mistake in the theory behind this architecture itself. I opted to waste no more time in this because even if the design worked, it was too bulky.

Sensor Architecture – III (Going back to the start) →

After repeated failures (and frustration) with the sensor problem, spreading over a time period of over an year, I abandoned the activity for the greater good. Just a few weeks back (August 2010), a few monotonous days on the job front and suddenly this sensor thing came into my mind again. Well, this time around, I decided to go back to that discussion with Peter Harrison (and other members of the forum as well) and decided to stick with it.

This time around, the idea was simple, very simple. I am assuming that the reader has gone through the thread and am therefore cutting short on a few details. The IR Led was now being controlled by a microcontroller through a ULN 2803 high current darlington transistor array. The receiver’s (TSL262) output was now plugged directly into the microcontroller’s ADC input. Take note that I used the now discontinued Osram’s SFH4503 IR Led for this setup (since I don’t have the TSAL6100s with me anymore).

The theory is simple, take a reading with the emitter off and then with the emitter on. Reading with emitter off is the ambient IR level and reading with emitter on is the IR level due to ambient and emitter IR both. To filter out the ambient IR, simply do the following maths

Actual Reading = Emitter ON – Emitter OFF

The get optimum range, a resistor of 10ohms was put in series with the IR led. Smaller value resistor will ensure a large amount of current which in turn will ensure a brighter and a stronger IR beam and hence, detectable reflection even at a greater distance. So, smaller the series resistor, greater the obtained range. But there’s a limit to the resistor’s value. First, let’s see how to calculate the net current flowing through the IR led,

With a 5V power supply, ideally 500mA of current should flow through the diode, but looking at ‘If vs Vf’ graph on page 5 of the emitter’s datasheet, the Forward Voltage (Vf) is around 1.1V if If is 500mA. Hence, the net current flowing through the led will be almost (5-1.1)/10 = 400mA.

Page 2 of the SFH4503’s datasheet states that the diode can take a maximum surge current of 2.2A for a time period of 10uS. Also, on page 3, it is stated that the switching time of this IR Led is 10nS. On the other hand, if we look at TSL262’s datasheet on page 3 we find that the ‘Output Pulse Rise Time’ of the sensor is 7uS. Putting this information point wise,

  1. The emitter, SFH4503, turns ON in 10nS.
  2. The receiver, TSL262, after receiving the IR pulse, takes around 7uS to saturate.
  3. The SFH4503 can withstand a maximum current of 2.2A for 10uS.

Hence, we need to make sure that the current flowing through the diode never exceeds 2.2A and to be on the safer side, currents greater than 100mA should not be allowed to flow through the IR led for more than 10uS. The maximum current handling capacity of the ULN2803 buffer is 600mA and therefore, in this setup, the current should not exceed the level of 600mA. As said before, this puts a minimum limit on the value of the resistor in series with the diode. Also, since TSL262 takes 7uS to saturate, we must make sure that the emitter has been turned ON for at least 7uS before taking readings from the ADC. This should not harm our emitter diodes as they can sustain large current levels for a time period of 10uS. Moreover, this time, I used the ATMega32’s ADC in 10-bit mode which also helped in enhancing the range of the sensors.

Hardware and Software →

Coming to the implementation part, I used the AVR Development Board Rev 1.2 from Thinnkware Pvt Ltd to do all the experiments. This board was one of the few stuff that I developed for these guys while working for them for a period of 6 months after finishing my engineering. I can assure you that its one of the coolest AVR Development Boards available in the market today :-). Enough of marketing….eh!

The experimental circuit’s connections are pretty much straightforward with the emitter being controlled by the pin 3 of PORTB. In between the emitter and the microcontroller pin, there’s a ULN2803 and a 10ohm resistor in series. The output from the receiver (TSL262) goes into ADC0 pin of the microcontroller, there’s also a 100k pull-down resistor on the receiver’s output. Following images should clear any confusions.

The emitter part,

The receiver part,

The software is pretty straightforward too. The main() function calls an initialization routine which set things up for the ATMega. After that, a timer overflow interrupt runs at a frequency of 4Hz and does the work of taking the samples, filtering the ambient IR, outputting the stuff on a 16×2 LCD. In the code, you can see that I have tried the AC coupled sensing that Peter Harrison described on the forum, but that doesn’t work for me for some reason. I am very satisfied with the result from this super simple approach and am in no mood to bang my head on the wall again to figure out why the AC coupling isn’t working fine!

I have used a lot of macros and compiler directives in the code to make it easy to understand and easy to use. If you have any suggestions, then kindly let me know!

Here is a video of the Infra Red Distance Rangers in action.

The software files are available for download and can be obtained from the link given below:-

Download Files for the Infra Red Distance Ranger (.rar format)

Creative Commons License
Infra red Distance Ranger by Pranjal Chaubey is licensed under a Creative Commons Attribution 3.0 Unported License.

About Pranjal Chaubey

An engineer, who believes in 'Being Wise, b.i.t.Wise!™'
This entry was posted in AVR, Extra-Curricular, Fourth Year, Micromouse, Robotics, Sensors, Third Year, Undergrad Projects and tagged , , , , , , . Bookmark the permalink.

6 Responses to Infra Red Distance Ranger

  1. Pingback: Micromouse and Me | Pranjal Chaubey b.i.t.Wise

  2. Max says:

    Hi, I am trying to use this and the micromouseonline discussions to do similar calculations for a different emitter and have a couple of real newbie questions:
    1. Where does the determination that 500mA is the ideal current through an LED at 5V come from?
    2. How do you go from the statement “the SFH4503 can withstand a maximum current of 2.2A for 10uS” to the following: “to be on the safer side, currents greater than 100mA should not be allowed to flow through the IR led for more than 10uS.”?
    Sorry for the basic electronics questions, I just want to get the circuit designed properly and understand how to do it rather than guess.
    I’m using the SFH4511 which has a max surge current of 3A; it also has a lower power dissipation and a much longer switching time (0.5us) than the emitter you used so not sure how to factor that in.
    I’ll go back to Googling and studying data sheets, but any pointers would be appreciated. Thanks!

    • 1. If you look at the datasheet of SFH4503, its rated for a continuous current of 100mA. Hence, 500mA is pretty cool.

      2. Have a look at the datasheet, Surge Current, Ifsm = 2.2A for a pulse (tp) of 10uS. As I have already stated, the led is rated for 100mA of continuous current.

      Regarding your query,
      Make sure that the emitter switching time is LESS than the receiver saturation time.
      A higher surge current can help you to get a longer range.

  3. Max says:

    Hi, I did look at the datasheet before asking and I saw the 100mA continuous current and the 2.2A surge current specifications; however, I was just wondering if there was a datasheet specification or a formula I was missing to obtain the ideal current value of 500mA and it sounds as though it is just a general approximation based on experience.

    Since the emitter can withstand a surge current of 2.2A for 10us and it only needs to be on for approximately 7us for the receiver to saturate, it would seem that you could safely run say 1.5A through the emitter for 8us and still remain under the maximum specifications for both current and duration of the pulse. If the current specification to use for emitter pulses is the continuous current value then I’m not sure why the max surge current has any bearing. Is the continuous current value used because of the frequency of the pulses that will be driven through the emitter?

    The emitter switching time vs. the receiver saturation time makes complete sense. Fortunately, despite the slow switching time of the 4511 (50x slower than the 4503), it will still be less than the saturation time.
    Thanks, Max

    • Yeah….500mA is an experience based approximation.

      Continuous current is a current that can safely flow through the LED continuously without damaging it. Its up to you whether you pulse that current or not. On the other hand, any current value higher than the continuous current value can permanently damage the LED, given the current is allowed to flow for sufficient amount of time. If a current of 2.2A flows through the 4503 for more than 10uS, you can be sure that the LED will get damaged permanently.

  4. Max says:

    I see; thanks for the helpful info!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s