Introduction: Micromouse(mobile Robot) IR Distance Sensor Board +tips
Hello and welcome to my first instructable! In this short instructable I will explain how to build an IR and phototransistor distance sensor unit. I built this sensor board for my Micromouse robot, however, this board should work on every robot which requires sensors that measure distance.
Step 1: Part and Price List
This sensor board can be made using Breadboard, Stripboard, PCBs or any other board, so the price of the board is not included in the part/price list. What is more, I bought all my components on Farnell, so it may not be available for everyone. On the other hand, all components can be found on eBay.
Part and price list:
- 4x IR LED, 5mm (Farnell) -> £0.09 each;
- 4x Phototransistor, 3mm (Farnell) -> £0.09 each;
- Male and Female headers (eBay) -> £0.99 (optional);
- 4x 100 ohm resistors;
- 4x 10k ohm resistors;
- Case for IR LED and Phototransistor.
Total price should be around £1.71 excluding board's, resistors' and sensor cases' prices.
Step 2: Sensor Case
After tests and researches I found out that it is a good idea to use a sensor case. The main purpose of the case is to keep IR LED and Phototransistor separate(there should be an opaque gap between them), because it interferes sensor readings. I used a Lego part as my sensor case. Besides, you can buy different size IR LEDs and Phototransistors(3mm, 5mm, etc.), so they could fit in your case. If you do not have anything to make a case from, just use a black electrical tape.
Finally, case is good to keep both sensor parts at the same place at all times.
Step 3: IR LED Testing
All LEDs emit light and IR LED(Infrared Emitting LED) is not an exception in this case. However, due to the limits of our eyes, it is impossible to see Infrared light, so it is difficult to say if the IR LED is working or not. The easiest way to check it is to try to take a photo with your phone camera! If your IR LED is working, you should see pink light (see the picture above), if it is not - then there will be no light.
Step 4: How It Works?
IR LED emits light and if there is an obstacle the emitted light reflects from the obstacle and then Phototransistor 'catches' the reflected light. The closer the object is, the more intense reflected light is and by connecting IR and Phototransistor in a particular way, the output will be voltage, which varies in proportion to the reflected light.
Step 5: Circuit Schematics
After connecting IR LED and Phototransistor as it is shown in the picture(where R1 is 100 ohm and R2 is 10k ohm resistors), the output should be voltage, which changes when distance from the sensor unit to the object changes. Congratulations, you have a simple IR and Phototransistor sensor unit!
Step 6: (Optional) Output Dependence to the Distance
It is recommended to use Oscilloscope or Multimeter for this task.
IR LED and Phototransistor sensor unit sensitivity to a specific distance depends on resistor values. I needed sensors that are the most sensitive with short distances, so I have been changing different resistor values, moving obstacle in range 1-20 cm and recording the output(voltage). Later I plotted the graph and I was able to see the best sensor resistors for my application(see picture above).
If you do not want to do this part, you can use R1 = 100 ohm and R2 = 10k ohm resistors as I suggested in the beginning and it will work well, but maybe it will not be the most efficient resistor pair.
Step 7: Schematics and PCB
I put Eagle file (schematics and PCB), so you could download and use it. Feel free to change the dimensions of the PCB - my Micromouse chassis was round, so my sensor board had to be round as well, also it has 3 mounting holes which can be removed or replaced.
Moreover, instead of 8 resistors I put female headers, so I could plug and unplug any resistors - good for testing sensitivity(Step 6). However, it works well, but it is not the most reliable way to do this.
Step 8: Software
Sensor output - voltage - theoretically should have value between 0 to 5V, so the output signal is analog. In order to make software to understand analog data, it has to be converted into digital data. I used microcontroller for my Micromouse, so I had to use ADC (Analog-to-Digital Converter) and the sensor output was converted into integer between 0 and 1023 where 0 is 0V and 1023 - 5V.
On the other hand, it is a lot easier to convert and read sensor value using Arduino development board. Build the sensor as it is shown in Step 5, then connect the output pin to the A0 (analog) pin on Arduino and upload Arduino code. Open Serial menu and you will see values between 0 and 1023. Feel free to change Arduino code. As an example, something happens(LED lights up) when sensor value is greater than 400.
Step 9: Future Improvements
If you have built the circuit shown in Step 5 you should have noticed that the output depends on the light level in the environment. This is because Phototransistor receives environment light the same as reflected IR. In order to fix this problem, sensor circuit has to be modified (see picture above). When Arduino was reading data from sensor in Step 8, the data was combination of reflected light and environment light. Digital pin is going to be used in order to turn on/off the IR LED, so it would be possible to get raw sensor data by subtracting combined light (when IR LED is ON) and environment light (when IR LED is OFF).
Connect Arduino pin 12 to DIGITAL and A0 to OUTPUT and upload the code. Now sensor data does not depend on environment light so much.
Note: Eagle improved schematics and PCB files are uploaded. However, the PCB has not been tested (it was done using Breadboard).
Step 10: Overall
I hope you have built or learned something new from my instructable. If you have any questions or if there are any mistakes, please leave a comment and I will respond as fast as I can!