Other Arduino Codes and Videos by Robojax

Arduino code and video for Sharp IR distance module with LCD1602 Display Robojax.com

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

This video shows you how to measure the distance between 4cm to 180cm depending on the module, using Arduino. The result is displayed on LCD1602 display module.
Sharp Analog output modules:
  1. Distance Measuring Sensors (Website)
  2. Sharp IR Library (from Robojax.com)
  3. Sharp IR Library (from getHub)
  4. Download Firtzing Sketch
Sharp IR Distance meter with LCD1602 wiring diagram
Sharp IR Distance meter with LCD1602 wiring diagram

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

 * Watch the video https://youtu.be/NjUOEAoKY7A

 *  * 

Original library: https://github.com/guillaume-rico/SharpIR


// Written and updated by Ahmad Nejrabi for Robojax.com
// on Jan 03, 2018 at 20:01 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.
 * 
 /*
/*



// original source https://www.arduino.cc/en/Tutorial/HelloWorld
// include the library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

///////////////////***** start of Sharp IR
//Sharp IR library source: https://github.com/guillaume-rico/SharpIR
#include <SharpIR.h>

#define IR A0 // define Sharp IR signal pin
#define model 430 // the model of the IR module
// Sharp IR code for Robojax.com
// ir: the pin where your sensor is attached
// model: an int that determines your sensor:
/*
 * GP2Y0A02YK0F --> "20150"
 GP2Y0A21YK --> "1080"
 GP2Y0A710K0F --> "100500"
  GP2YA41SK0F --> "430"
 */

SharpIR SharpIR(IR, model);
/////////////////////**** end of Sharp IR

void setup() {
  // Robojax LCD1602 Test 
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  // Robojax Sharp IR with LCD1602 Test 
}

void loop() {
   lcd.clear();
  // Robojax.com Sharp IR Test 
    lcd.setCursor(0, 0);
    lcd.print("Robojax IR Test");
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
 int dis=SharpIR.distance();// gets the distance in cm
 String distance = String(dis);
 distance ="Distance: "+distance+"cm";
 lcd.print(distance); 



  delay(500);
  // Robojax.com Sharp IR Test  
}