• No results found

Ultrasonic Distance Measurement Module

N/A
N/A
Protected

Academic year: 2021

Share "Ultrasonic Distance Measurement Module"

Copied!
7
0
0

Loading.... (view fulltext now)

Full text

(1)

Ultrasonic Distance Measurement Module

General Description

Distance measurement sensor is a low cost full functionality solution for distance measurement applications. The module is based on the measurement of time flight of ultrasonic pulse, which is reflected by an object. The distance to be measured mainly depends on the speed of ultrasonic waves in space or air –which is a constant- and the flight time of the pulse.

The module performs these calculations and outputs a pulse width depends on the measured distance, this pulse is easily interfaced to any microcontroller.

Features

• Supply voltage +5Vdc • Supply Current 10mA

• Measurement distance Range from 2cm to 400cm.

• Input trigger pulse is 5V TTL compatible (5 µs minimum). • Output echo pulse is 5V TTL compatible.

• Size 44.5mm W x 20mm H x 15mm D.

• Interface connector 4-pin header SIP, 0.1” spacing. • Operating temperature range 0° - 70° C.

(2)

Distance Measurement Module

RAM Electronics

+5V

Microcontroller +5V Ultrasonic Module

VCC Output Pulse GND Input Pulse Input Trigger Pulse Output Echo Pulse TX RX

Table1. Connector signals definition

Label Definition Direction Function

VCC Supply voltage Power Supply power to module

5VDC with 10mA max

Trig Trigger Input

Input trigger for measurement module. This pin is TTL/CMOS logic (5V and 0V). The trigger pulse should be 5µs minimum

Echo Echo Output

Output echo pulse from measurement module. This pin is TTL/CMOS logic (5V and 0V).

The output pulse width time is function of the distance to be measured

GND Ground Ground System ground connected to the same ground of the host.

Connection Diagram

(5 µs min)

Measured distance

Pulse width depends on Measured distance

Timing Diagram

Trigger Input

Pulse

Echo Output

Pulse

T1

T2

T3

(3)

©2012 RAM Electronics Page 3 of 7

Distance Measurement Module

RAM Electronics

Timing Characteristics

Time Description

Value

Unit Min Typ Max

T1 Trigger pulse 5 10 - µs

T2 Echo hold off 400 450 500 µs

T3 Echo pulse 150 - 16000 µs

Calculating equation

D = (T × 0.0343) / 2

Where:

D is the measured distance in cm.

T is the echo output pulse in µsec.

0.0343

is the speed of sound in air in cm/µsec.

Alternative calculating equation

D = (T / 29.1) / 2

Where:

D is the measured distance in cm.

T is the echo output pulse in µsec.

(4)

Distance Measurement Module

RAM Electronics

Typical application circuit using PIC16F628A

Here is a simple project you may build to test your module.

The project uses PIC16F628A microcontroller to trigger the module,

measuring the echo pulse, calculating the distance in cm and displaying it on 2X16 LCD.

The project also include the source code written in BASIC language for PROTON compiler. The firmware may be rewritten for any other compiler to perform the required function.

(5)

©2012 RAM Electronics Page 5 of 7

Distance Measurement Module

RAM Electronics

'================================================================================ '==================== Initialization ========================= '================================================================================

Device = 16F628A 'Microcontroller name

XTAL = 4 ;XTAL speed in MHz

Config XT_OSC,WDT_OFF,BODEN_OFF,LVP_OFF,PWRTE_OFF,CP_OFF '---

;I/O Ports Programming

TRISA = %11111000

TRISB = %00001111

CMCON = %00000111

'---'LCD definition

Symbol DO_RS = PORTA.1 Symbol DO_EN = PORTA.0 Symbol DO_LCD_D4 = PORTB.4 Symbol DO_LCD_D5 = PORTB.5 Symbol DO_LCD_D6 = PORTB.6 Symbol DO_LCD_D7 = PORTB.7

'--- 'Other I/O definitions

Symbol DO_Trigger = PORTA.2 Symbol DI_Echo = PORTA.3

'--- 'Variables declaration

Dim W_Word As Word Dim F_Float As Float

'--- 'LCD Initialization

LCD_TYPE 0 '0 FOR ALPHABETIC 1 FOR GRAPHIC

LCD_INTERFACE 4 '4 BIT DATA LENGTH

LCD_LINES 2 'NUMBER OF LINES

LCD_DTPIN DO_LCD_D4 'DATA PORT

LCD_ENPIN DO_EN 'ENABLE PIN

LCD_RSPIN DO_RS 'RS PIN

'======================================== 'Main '======================================== Cls Print At 1,1,"Distance = " Start:

DO_Trigger = 0 ' Output low to the trigger input of ultrasonic module.

DelayUS 10 ' Wait 10 µS for trigger pulse.

DO_Trigger = 1 ' Output high to the trigger input of ultrasonic module.

W_Word = PulsIn DI_Echo,1 ' Read the echo pulse time ( refer to Proton help to get

' more information about “PulseIn” instruction)

F_Float = W_Word * 10 ' convert the unit of time to microseconds .

F_Float = F_Float * 0.0343 ' multiply the time by the speed of sound in air (cm/µsec). F_Float = F_Float / 2 ' Divide the calculated distance by 2

Print At 1,12," " ' Clear the last value on LCD. Print At 1,12,DEC1 F_Float ' Display the new distance on LCD.

DelayMS 300 ' Wait 300 millisecond before next measurement.

(6)

Distance Measurement Module

RAM Electronics

Example Code for ARDUINO

It should be noticed that:

1. The calculation of distance rely on the Pace of sound (29.1 µsec /cm) and not the speed of sound

2. The distance limited to 200cm only.

3. The calculated distance is sent over serial interface.

/*

ultrasonic module Ping distance sensor] VCC to arduino 5v GND to arduino GND

Echo to Arduino pin 13 Trig to Arduino pin 12 */ #define trigPin 12 #define echoPin 13 void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); } void loop() {

int duration, distance; digitalWrite(trigPin, HIGH); delayMicroseconds(1000); digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; if (distance >= 200 || distance <= 0) { Serial.println("Out of range"); } else { Serial.print(distance); Serial.println(" cm"); } delay(300); }

(7)

Distance Measurement Module

RAM Electronics

RAM Electronics 32 El Falaky St. Tahreer, Cairo Egypt. Tel: 02-27960551 Sales@ram-electronics.com www.ram-e-shop.com

Notes:

References

Related documents

Within that loop, a call is made to function PwmInterval, which returns a Boolean value and sets output PTA3 (also called PTAD_PTAD3) on or off as appropriate for the given duty

Yapılan çoklu regresyon analizi sonucunda; R2 determinasyon katsayısı değerine göre algılanan sosyal destek alt boyutları (aile, arkadaş, ve özel bir insan) ile sosyal

Note 1: The trigger signal will be removed by filtering if active pulse width of input trigger signal is less than “Line Debounce Time” setting time.. Please input trigger signal

We previously investigated whether OB with divergent origins from different bone types exhibit divergence in their behavior, by comparing growth, differentiation, and

A program was done to analyze and identify the same promising 20 selected local and Indian accessions taro, aiming at the characterization of the extent and distribution of

Specifically, during alcohol intoxication, IPA perpetrators will exhibit the greatest deficits in neurocognitive processing (smallest P300 ERP component amplitude), which will

It is useful to contrast the study of the social history of the Middle East with the analogous ®eld in medieval and early modern European history.. The rise of social history,

Analyzing the impact of administrative division adjustment on economic development and exploring the influence mechanism of administrative division adjustment on