Ultrasonic Range Meter

Projects Home

Measure the distance to an object within 25 cm to 8 meters using standard 40 kHz transducers. Takes around 20 samples per second.

Very useful for robotics! The first v2 version takes only 5 mA at 9v. The schematics are based on a project from Elektor dating from 1982!!!

Here again, the NOKIA LCD has been chosen for display. The circuit is controlled by a PIC16F877 running at 4 MHz.

In the next v3 version i'll try to reduce the minimum distance & power consumption.


At 20ºC/68ºF, sound travels through the air at 343,8 m/s. This is approximately 29µs for 1 cm.

We want to measure the distance to an object. To do so, we will have to measure the time between the transmission & the reflected reception of an ultrasonic pulse.

Because the reflected pulse will travel twice until received back, we divide the speed by two. So, this makes 58µS for 1 cm.

This v2 version counts the amount of periods of 58µS it takes until the ultrasonic pulse is received back.


Waveforms:

 


Schematic: right-click & "save picture as" for full resolution or download the eagle-file below.

basic v2 version


 

PIC

 NOKIA LCD
  1= +5v
RD6 2= sclk
RD7 3= sda
RD0 4= d/!c
RD3 5= !cs
  6= gnd
  7=Vout
RD1 8= !res

PIC

US signal
   
RB2 USRX_q
RD2 USRX_res
RD4 USTX_en
   

PIC

 i²c
   
RC3,SCK SCL
RC4,SDI SDA
 

Downloads:

WARNING: may not be duplicated for any commercial use whatsoever without explicit consent from the author. (c) Michel Bavin.

Hex files:

008_v2_hex.zip,  October 7, 2003: us_v2.hex (to program the PIC)  

ascii_eeprom_v2.zip, September 10, 2003: ascii_eeprom_v2.hex (for the EEPROM.)

----------------------------------------------

Source code: 008_v2_c.zip (Hi-Tech PICC),  October 7, 2003: us_v2.c , with include files defs.h, delay.c, delay.h

Schematics: 008_v2_sch.zip (Eagle), October 7, 2003.

PCB: 008_v2_brd.zip (Eagle), march 26, 2004.


Source code explanation: (Hi-Tech PICC)

ultrasonic driving: coming soon.

i²c EEPROM to NOKIA: void ext_eeprom_to_nokialcd(void): read character en symbol data in eeprom & send them to the NOKIA LCD.

NOKIA LCD: various routines.


Tools:

I work with the Hi-tech PICC compiler. It is relatively easy to use AND has a complete working FREE version (PICC Lite) available. This lite version is limited to 2K for the 16F877 (1/4 of total code size) but this is sufficient for this projects. You'll have to install Microchip's free MPLAB IDE to get things going.

Programming of the PIC was done with IC-Prog on a PIC- programmer built from Electronique pratique nr 253 (January 2001).

Eagle was used for the PCB layout. The free version was ok for this design. Best is to download the schematic below and then to create your own board.


Info & datasheet:

24C256 i²c EEPROM

Graphic LCD module type LPH7779 (NOKIA 3310 LCD) and its integrated controller PCD8544.


Projects Home