Print Friendly, PDF & Email


IR sensors are used when we need to detect if any object is crossing or coming at the restricted areas because they can only detect the bounced back ray from the object. But there are cases when we need to know that from how far the object is coming i.e. distance of the object. Here Sharp IR sensors are used. The Sharp sensor has a special detector that not only determines if there is light, but they can also measure how far the object is and gives us an analog value for it.

Detector and IR LEDs have fixed orientation and distance with respect to each other. So nearer and farther object will definetly affect the angle in which the lights from IR LEDs hitting the receiver. So after receiving lights distance can be easily calculated.


Where ever distance needs to be calculated Sharp IR sensors can be of a very good use.

Common applications of Sharp IR sensors are Robotics, Security areas etc.


Project for Reference:


#define sensor A0  // Sharp IR GP2Y0A21SK0F (10-80cm, analog)

void setup()
  Serial.begin(9600);  // Start the serial port

void loop()
  float volts = analogRead(sensor)*0.0048828125;  // Value from sensor * (5/1024)
  int distance = 13*pow(volts, -1);  // Worked out from datasheet graph
  delay(1000);  // Slow down serial port 
  if (distance <= 50)
    Serial.println(distance);   // Print the distance

Output at Serial Monitor: