Wednesday, 24 July 2019
Main Menu
Home Home
Shop Shop
News News
Products Products
Application Notes Application Notes
Publications Publications
Links Links
Support Center Support Center
Downloads Downloads
Forum Forum
Resellers Resellers
Contact Us Contact Us
Updates Updates
MCS Wiki MCS Wiki
Online Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login


If you have problem after log in with disappeared login data, please press F5 in your browser

RSS News

AN #16 - Using the Sharp GP2D02 distance sensor Print
Using the Sharp GP2D02 distance sensor

The following application note was donated by Lex Bolkesteijn.
Lex is using the GP2D02 in his robots but there are many applications
for this part.
The GP2D02 from Sharp is a distance sensor that can measure
distances from 7cm to 1.2 meter.
It uses an optical transmitter and receiver to measure the distance and
outputs the distance in 8 bit serial format.

The datasheet of the GP2D02 can be downloaded from :

A more in depth desciption of the GP2D02 is also available.
Dr.-Ing. Claus Kuehnel donated one of the chapters of his BASIC
STAMP book that decripes the GP2D02.
In fact the BASIC STAMP book is a good source for interfacing all
kind of hardware.

Download the  .PDF file for GP2D02


' (c) 1999 Lex Bolkesteijn
' file: GP2D02.BAS
' Sample program to use a Sharp GP2D02 distance sensor
' with a 89C2051. The GP2D02 is non lineair. The shorter
' the distance between object and sensor the higher the output.
' The GP2D02 is availlible at Conrad Electronics
' GP2D02 89C2051
' pin 1 : Gnd -> Gnd +-- connect Vin/P1.0 here
' pin 2 : Vin -> P1.0 (Vcc - 1K --X-- 1K - Gnd)
' pin 3 : Vcc -> Vcc
' pin 4 : Vout -> P1.1 (GP2D02 12K internal pull up)

Dim D As Byte 'distance value
Dim T As Byte
Dim I As Byte
Dim S As String * 20
Config Lcd = 16 * 2 'configure lcd screen


Set P1.0 'set powerdown for sensor
Waitms 10 'default wait

Reset P1.0 'Start cycle
Waitms 70 'time to calculate
Set P1.0
Shiftin P1.1 , P1.0 , D , 0 'clock bits in MSB first on falling edge
Set P1.0 'set powerdown for sensor
Waitms 2 'minimum delay for sensor
= D / 16 'we use a 16 char. display (255/x)= 16 max
Lcd "Distance : " ; D 'display the distance
If T > 0 Then 'else string will fail
= String(t , 61)
Lcd S
End If