How to build an homemade IR sensors?

Hi there. I am trying to build a follow-line robot, and wish to build my own IR sensors (something like -

Since i'm a newbie, what components should I buy when going to the eletronic store today? I want to build 5 sensors.


Hmmm…I can’t tell you exactly how the best way to do it, but I can give you a few hints.

Typical “line following” sensors can be bought pretty cheap (<2$). Eg. the QRD1114 or the QRB1134. They consist of an IR LED and a phototransistor and that’s it. When you hook them up you typically need a 220 Ohm resistor for the IR LED and a 10K pullup resistor for the signal. But you may have to play around with those resistor values to get the optimal result. You could replace the resistors with potmeters so you can dial in the best values and later replace them with fixed resistors with corresponding values.

Here is the schematic I used to hook up a QRB1134 recently:

You may wanna play around with different capacitor sizes (start with 0.1uF and go upwards) to smoothen out the signal. Or perhaps lose the capacitor alltogether.

You can also simply buy these components and make it yourself. That is an IR LED and a phototransistor. I’ve also seen people use a photoresistors instead of phototransistors for some applications.

Anyway I recommend doing a bit of research on the different options :wink:

Thanks! I got all the components, now to my next question: How can I test the sensitivity of my sensors (see a "live" data) on the screen without connect it to the motors/etc, just connect 1 IR sensor to the arduino and check the values it gets?

Well you set up your circuit according to the schematic above and connect the signal wire to one of Arduino's analog inputs. You can then read the output using the function analogRead().

I recommend using a software oscilloscope to look at the readings. I made my own some time ago which helped me out a lot. Here is an example of my readings:

It's reading LOW when a white surface is in front of the sensor and HIGH when a black surface (or nothing) is in front of it.

If you're using windows you can use the software scope I made. It's not perfect but it does the job. Get the latest build here. If you're using Mac or Linux others have made scopes for those platforms. Check the exhibition area of this forum.

If you use my scope you can use the following code for testing (if not it will give you an idea):

void setup() {
  Serial.begin(115200); // initialize serial
  Serial.print("START"); // syncronize with scope

void loop() {
    int val = analogRead(0); // read sensor input from analog input 0
    val = val / 4; // map the value down to 8 bit resolution
    Serial.print(val, BYTE); // send the value to scope
    delay(1); // wait 1 millisec

Good luck ;)

Cool software but I can't seem to connect it to my arduino:

when using the Arduino software, I checked and seen that the com port used by arduino is port 19.

when trying to choose port on SerialScope, the maximum number it can reach is 9.


Damn! Well it is a quick and dirty application and I just figured that it would suffice with up to port 9.

When I get the time I'll expand it to include more ports.

OK! Done :D

It now accepts up to port 25. A bit of a hassle because I had to move ALL the buttons to make space for the extra digit. My fault for prototyping TOO quick and dirty in the 1st place.

Anyway you can download the new build here:

you'r fast buddy, I don't know why, but it said "unable to open COM port".

hmmm...that's odd :/

You're sure you chose the correct COM port and that it's plugged in and all?

Added: I tested the newest build and checked the code. I really see no reason at all that it shouldn't work for you if you have set the COM port to the one where your Arduino is connected. It makes no sense. Unfortunately it's hard to test for me cause my own Arduino is on port 8.

Again are you certain that you set it correctly?