Bite Size Arduino – Sharp IR Sensor

I have received a few messages asking me to give a bit more detail into the individual bits of the robots I have built so far. Thus I am starting this series of posts in which I will cover a single sensor\actuator integration to an Arduino board per post.

Today we will have a look at how to use a Sharp IR Sensor.

The IR sensor has 3 pins – 2 pins used to power the sensor and a signal pin that is used to communicate its reading.


As shown in the image above, connect the red pin to the 5V pin on the Arduino, the black to the GND pin and the yellow signal pin to any one of the analog pins, for the purpose of this example we will use A4.

Below is the code used to get a reading from the sensor and print it out using the Serial.println:

#define IR_PIN A4
int IRDist = 0; 

void setup()

void loop()
IRDist = analogRead(IR_PIN);

I suggest using this code to experiment and see what readings get generated by placing the sensor at different distances from an obstacle.

Bite Size Arduino – Sharp IR Sensor

3 thoughts on “Bite Size Arduino – Sharp IR Sensor

    1. JR says:

      That is correct, to convert to voltage can be done as follows:
      IRDistmm = ((67870.0 / (IRDist – 3.0)) – 40.0);

      I have however noticed that I need to manually adjust the constant values above for each sensor to get an accurate reading.


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