Other Arduino Codes and Videos by Robojax
/*
* Sharp IR (infrared) distance measurement module for Arduino
* Measures the distance in cm and display on LCD1602 (whtout the I2C module)
* Original library: https://github.com/guillaume-rico/SharpIR
* Watch Video instrution for this code: https://youtu.be/NjUOEAoKY7A
*
* Full explanation of this code and wiring diagram is available at
* my Arduino Course at Udemy.com here: http://robojax.com/L/?id=62
* Written by Ahmad Shamshiri on Feb 03, 2018 at 07:34
* in Ajax, Ontario, Canada. www.robojax.com
*
* Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in structured course with all material, wiring diagram and library
all in once place. Purchase My course on Udemy.com http://robojax.com/L/?id=62
If you found this tutorial helpful, please support me so I can continue creating
content like this. You can support me on Patreon http://robojax.com/L/?id=63
or make donation using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been download from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// 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
}
If you found this tutorial helpful, please support me so I can continue creating content like this. support me via PayPal