Arduino code and video for Sharp IR distance module

This is the Arduino code and video for Sharp Infrared Sensor Module

This video shows you how to measure the distance between 4cm to 180cm depending on the module, using Arduino. Sharp Analog output modules:
  1. Distance Measuring Sensors (Website)
  2. Sharp IR Library (from
  3. Sharp IR Library (from getHub)

 * Sharp IR (infrared) distance measurement module for Arduino
 * Measures the distance in cm.

 * Watch the video

 *  * 

Original library:

Updated by by Ahmad Nejrabi for
on Feb 03, 2018 at 07:34 in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.

  // Sharp IR code for
#define DETECT 2 // pin 2 for  sensor
#define ACTION 8 // pin 8 for action to do someting

void setup() {
  Serial.println(" Laser Module Test");
  pinMode(DETECT, INPUT);//define detect input pin
  pinMode(ACTION, OUTPUT);//define ACTION output pin

  // Laser sensor code for


void loop() {
       // Sharp IR code for

  int detected = digitalRead(DETECT);// read Laser sensor
  if( detected == HIGH)
    digitalWrite(ACTION,HIGH);// set the buzzer ON

    digitalWrite(ACTION,LOW); // Set the buzzer OFF
    Serial.println("No laser");
       // Sharp IR code for