Wednesday, 09 July 2025
     
 
Main Menu
Home Home
Shop Shop
News News
BASCOM-AVR BASCOM-AVR
BASCOM-8051 BASCOM-8051
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-AVR Help BASCOM-AVR Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login
Username

Password

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

RSS News
 
     
 

 
   
     
 
AN #40 - Infrared Proximity Distance Measurement Print
by K.S.Sankar - Mostek Electronics ( www.mostek.biz )
Originaly published in ELECTRONICS FOR YOU magazine ( INDIA - W W W . E F Y M A G . C O M )

    Infrared proximity detectors are commonly used in robotic projects in sensing obstacles. If you need to measure the approximate distance from the object for wall following or maze solving robot projects, you need to use ultrasonic or reflective unmodulated light sensing circuits using expensive components. This circuit that can be used with ATMEL AT89c2051 to generate a 38k burst frequency of IR and receive it using Siemens SFH5110 receiver to calculate an approximate distance from the reflected object.
 
    This article uses AT89s8252 and an lcd for demonstration.  Int-0 multiple count generated during the IR 38k Burst is used to find out the distance with INT edge triggering turned OFF . On experimenting , we found the count vary from 0 to about 900 for an object  distance of 12” down to 3”. A comfortable variation in value to experiment with - in close proximity sensor projects.

    IR modulation is normally done using a 555 wired as a square wave oscillator. To reduce the number of components, the software generates the frequency through a port pin with the correct time delay between ON/OFF periods. With a 6 Mhz xtal, the time period is too short, so NOPs are used for the timing with two BYTE variable loops in the software that sends a burst of 38 Khz for a duration of about 1/0th of a second.
 

    The final count can be used in the project to find the approximate distance if the object . Two leds indicate the IR xmit in progress and IR recd.

The   source code is given below:

 '--------------------------------------
' mcs80prox.bas 14-10-2006
' (c) by k.s. sankar www.mostek.biz chennai / madras India
' written in bascom-51 micro controller
' embedded visual basic language for 8051 family of micros
' from www.mcselec.com holland
' max 900 count for close reflection
'---------------------------------------

''''$regfile = "89c2051.dat"
$regfile = "89s8252.dat"

' the micro controller's include file
$crystal = 6000000
'6 mhz crystal used

Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = P0.4 , Db5 = P0.5 , Db6 = P0.6 , Db7 = P0.7
Config Lcdpin = Pin , E = P0.3 , Rs = P0.2

' define variables below
Dim Irrecd As Bit
Dim Ircount As Integer

Declare Sub Fn38k6()

Irrecd = 0
Ircount = 0

' another name for port pin p1.0
Irport
Alias P1.0
' make all ports 0
P0 = 0
P2 = 0

P1 = 0
P3 = 0
P3.2 = 1
' make port-3.2 int0 high for interrupt to work

' on interrupt - call int0_int fuction
On Int0 Int0_int
Reset Tcon.0
' int enabled... NOT edge triggered
Enable Interrupts


Begin:
Ircount = 0
' show IR xmit mode on port-1
P1.1 = 1
' enable int0
Enable Int0

Call Fn38k6
' send out a beam for 1/10th of a second
' of IR at 38khz freq
' int would have taken place if ir was reflected recd

Disable Int0
' disable int

' check if int occurred
If Irrecd = 0 Then
 
' no int occured
 
P1.1 = 0
 
' flash standby led
 
Waitms 100
 
' wait for ( 1/10th of a second)
 
Goto Begin
End If

' here int recd
' show ir count..related to distance
Home
Lcd "ircount=" ; Ircount ; " "

Irrecd = 0
P1.2 = 1
' confirm led ON
Waitms 255
P1.2 = 0
Goto Begin


' =-=-=-=-subroutines below =-=-=-=-=-=-=
Sub Fn38k6()
' function to oscillate IR port pin
' at 38,000 times a sec for 1/10th second
Dim Jj As Byte , Kk As Byte
Jj = 0
While Jj < 10
Incr Jj
Kk = 0
While Kk < 255
Incr Kk
Irport = 1
NOP
Irport = 0
NOP
NOP
Wend
Wend

End Sub
' = - = - = - = - = - = - = - = - = - = - = - = - = -
' The Interrupt Handler For The Int0 Interrupt
Int0_int:
 Irrecd = 1
 
Incr Ircount
 
' set a flag , increment a counter and return
Return
' - - - - - - - - - -
' end 788 bytes
' -=-==-=-=-=-=-=-=-=

Schematic below: