Introduction: Micromouse(mobile Robot) IR Distance Sensor Board +tips

Picture of 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

Picture of 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:

  1. 4x IR LED, 5mm (Farnell) -> £0.09 each;
  2. 4x Phototransistor, 3mm (Farnell) -> £0.09 each;
  3. Male and Female headers (eBay) -> £0.99 (optional);
  4. 4x 100 ohm resistors;
  5. 4x 10k ohm resistors;
  6. 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

Picture of 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

Picture of 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?

Picture of 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

Picture of 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

Picture of (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

Picture of 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

Picture of 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!

Comments

AlbertoS2 (author)2015-01-02

what is the recommended thickness of a cable that powers 5v?

clazman (author)2014-06-11

Thanks for the response. I believe you have answered my question. I wasn't trying to be obnoxious. Your answer indeed indicates that your analysis greatly exceeds your project here. Robotic control can become very complex trying to emulate only a fraction of the human system. It was indeed a pleasure chatting with you.

clazman (author)2014-05-27

Nice project and informative too by discussing the problems associated with this system.

I've
always wondered though how directionality can be take into account. I
understand, by trig., that as the robot progresses toward the object
directionality to be less an issue. However, at some distance, I assume
that the system will not ascertain the location of the object and may
turn in t/he wrong direction. Is this problem solved by continual monitoring of the object,
as the robot approaches an object to the side there would be a point
that it would not sense the object and thus "be safe"? Have I described
my query effectively? It is so difficult to write coherently with so few
words!

gycka (author)clazman2014-05-28

Hi, I am not sure if I understood you correctly, but are you asking how robot knows its position and direction? If so, I used motor encoders in order to determine if it has travelled enough to perform action(e.g turn left/right) and program then updates the mouse actual direction and position(if it went forward).
Talking about 'not sensing the object' - it might not sense it if the object is too close - if I remember correctly sensor values become faulty when object/wall is less than 1 cm (more/less). By faulty I mean if the actual distance is 1cm, it might show that the distance is 10cm.

clazman (author)gycka2014-05-28

Thanks for the kind reply. I understand your explanation. What I
was wondering is if there is any calculating process to determine a need
for path correction when the object is just inside the field of
view but not necessarily be contacted by the robot and not need an avoidance
maneuver. For example, if the object is sensed but would be outside of the robots course and, therefore, not requiring course correction for avoidance.

gycka (author)clazman2014-06-11

In your determined case I would program the robot. As an example, if sensor value is less/more than a specific value that you determine(object is detected and correction has to be made) turn left/right accordingly in order to avoid obstacle/object.
Code example:
if(sensor_left > 500) // let 500 be 3cm, so correction has to be made

Drive left motor faster than right; // in order to turn right - away from obstacle

else

Do nothing!
Do the same for right sensor and you will have simple obstacle avoidance code. You can continue working, experimenting and add functions like don't go too far from the obstacle - in my example it will go right/left until another obstacle is found and it will try to avoid it. Besides, you can add advanced functions such as return back to the same path when obstacle is not sensed anymore. Finally, you can add calculations to the robot. For example, if object is really close it has to turn away from it very fast, or if it is far away but in the 'zone' - small speed adjustments. Let me know if I have answered to your question!

techno guy (author)2014-06-03

Doesn't ambient light somewhat throw off the reading on the phototransistors, and if so, how would you adress that problem?

gycka (author)techno guy2014-06-11

Hi, check Step 9 again, is this what you are asking? If not, just let me know.

ofey (author)2014-05-27

Hi, This is a great instructable. Any chance you could post an instructable on details of the rest of your bot i.e. the chips you used and how to program them. Also how did you power the whole thing? I can't see a battery in the pics.

Great work,

Thanks

gycka (author)ofey2014-05-28

Thanks, I know that micromouse is very popular robot in the World - many students make it for learning purposes. I could make instructable how to make and program it, but, to my mind, it would be too easy for other people. As an example, if anybody from my university will see it(2nd year students make it every year and the parts are usually the same (microcontrollers and motors)), they will have to copy and paste it.
To power my robot I used 9V battery which is between 2 motors (there is perfect gap for 9V battery), so you can't see it.

ofey (author)gycka2014-06-03

Hi Gycka, thanks for the reply. I see your point and thanks for the info.
Shane

Mic100 (author)2014-05-26

2 DS PIC it well move and interact,

i made a mini robot based on an ATtiny13 is already moving and not bad for a tiny

https://www.instructables.com/id/Mini-2-wheel-robot-with-IR-sensor-weight-14gr-and-/

gycka (author)Mic1002014-05-26

Looks nice! You should check this robot controller:

http://www.pololu.com/product/1220/

Mic100 (author)gycka2014-05-29

Good for France the distributor is Lextronic

Mic100 (author)gycka2014-05-29

Thank you for the link, I'll find out if the book in France :)

Interesting but wont you only be able to tell relative distnace since the intensity of reflected light will be inconsistant between objects? Very cool though!

I am not sure if there is a relationship between distance and intensity of reflected light(I am not sure if you can derive a math formula). I used specific sensor values in my code - if the distance is between 300 and 400 that means there is a wall or vice versa.

achand8 (author)2014-05-27

Thats a nicely built bot! Awesome! Why do you need two microcontrollers? Which tyres and motors are you using? Regarding the IR sensor. Since an IR led works at 1.5 v, you could have put 3 in series and put a current limited resistor, it's more efficient than a resistor for each led. But it wont make much of a difference! BTW whats the middle PCB for?

gycka (author)achand82014-05-28

Thanks! Well, I have 2 microcontrollers (dsPIC30F4011) because one can read only 1 motor encoder data. I couldn't use different microcontroller which could do 2 motors at the same time, because of learning purposes (communication between microcontrollers etc.).
Wheels are 3D printed(40mm diameter) and I don't know what type tires are because it was provided by my university.
As I have mentioned below, I used Faulhaber DC motors. Datasheet(I am using 6V motors, 33:1 gearbox): http://www.micromo.com/micromo/DC-ENCODERS/2619_S... .
Finally, middle PCB is motor control (H-bridge), I made my micromouse in steps, so in order to avoid mistakes I split my electronics in 2 main pieces - 'motherboard' and 'motor board'.

artaex (author)2014-05-27

Wouldn't TV remotes interfere with the distance detection since they emit IR light too?

Wragie (author)artaex2014-05-27

TV remotes and most IR devices use codes to discriminate from natural or man made interference. As an example it has to eliminate the single largest and most powerful source aka the sun, or eliminate any 60 or 50hz signals from light bulbs or other light sources. Having typed that I can't think of an example string to show you but they are pretty distinct and not found in nature, and the receiver has to get the correct code before it follows the command. You can find some of this on the data sheets for ir led transmitters.

fixfireleo (author)2014-05-27

wow, dude! awesome! now, can it cook and clean? does it matter if i feed it after dark? :P

Mic100 (author)2014-05-25

good job :=)

what microcontroler are you used for the robot

gycka (author)Mic1002014-05-25

Thanks! I had to use 2 dsPIC30F4011 - one microcontroller can read only 1 motor encoder data, and I wasn't allowed to use different microcontroller.

ASCAS (author)2014-05-25

Nice work! BTW, what motor are you using?

gycka (author)ASCAS2014-05-25

Thank you, Faulhaber DC motors were supplied by university. Datasheet(I am using 6V motors, 33:1 gearbox): http://www.micromo.com/micromo/DC-ENCODERS/2619_SR_IE2-16DFF.pdf

repkid (author)2014-05-25

Noooooooo, please don't butcher LEGO.

About This Instructable

42,290views

233favorites

License:

More by gycka:Micromouse(mobile robot) IR distance sensor board +tips
Add instructable to: