You are on page 1of 7

For more products visit our website http://www.sunrom.

com

Document: Datasheet

Date: 6-Jun-12

Model #: 1127

Products Page: www.sunrom.com/p-1129.html

Ultrasonic Distance Sensor - Serial Out + Display


Its compact size, higher range and easy usability make it a handy sensor for distance measurement and mapping. It includes display PCB along with serial output.

Features
Minimum range 4 centimeters Maximum range 400 centimeters (4 Meters) Accuracy of +-1 cm Resolution 1 cm 5V DC Supply voltage Compact sized SMD design Modulated at 40 kHz Serial data of 9600 bps TTL level output for easy interface with any microcontroller

Specification
Parameter Supply Voltage Supply Current Output Data speed Output Data Format Value 5 15 9600 8-N-1 Unit V mA Bps 8 data bytes, no parity, 1 stop bit

Pin Details
Pin GND TX-OUT +5V Value Supply Ground Serial output data (TTL 5V level) at 9600 baud rate Supply +5V Details Connects to RXD pin of microcontroller or RS232/USB to TTL boards

More Pictures

Display PCB

Sensor

Power and Serial Out

Sunrom Technologies

Your Source for Embedded Systems

Visit us at www.sunrom.com

Output format
The serial output data consist of nine ASCII bytes as per table below Sample outputs strings 100.00cm 080.01cm 075.96cm 010.56cm
xxx.xxcm<CR> 0 to 9 0 to 9 ASCII ASCII 0 to 9 ASCII . Fixed Decimal 0 to 9 ASCII 0 to 9 ASCII c Fixed ASCII character m Fixed ASCII character <CR> New line

Position 9 8 7 6 5 4 3 2 1

ASCII character 0 to 9 0 to 9 0 to 9 . 0 to 9 0 to 9 c m <CR>

HEX 0x30 to 0x39 0x30 to 0x39 0x30 to 0x39 0x2E 0x30 to 0x39 0x30 to 0x39 0x63 0x6D 0x0D

DEC 48 to 57 48 to 57 48 to 57 46 48 to 57 48 to 57 99 109 13

Description Xxx.xxcm Hundred character xXx.xxcm Tens character xxX.xxcm Ones character xxx.xxcm Decimal character xxx.Xxcm character xxx.xXcm character c character m character New Line character

Sunrom Technologies

Your Source for Embedded Systems

Visit us at www.sunrom.com

Interfacing with RS232


If you wish to interface the module with RS232 level like a PC serial port or any other device you need a level convertor such as MAX232 as shown below. U5 VCC You can also use our Sunrom Ultrasonic Sensor Model#1127 C16 P2 100n DB9-CONN-F Max232 Board Model 1104 U6 1
+5V TX-OUT GND 16 MAX232 11 9 12 10 + C13 10uF 16V VCC 2 + C14 10uF 16V 1 3 T1IN R2OUT R1OUT T2IN C+ C1V+ T1OUT R2IN R1IN T2OUT C2+ C2V14 8 13 7 4 5 6 C15 10uF 16V + + C12 10uF 16V 6 2 7 3 8 4 9 5 3 2 1 VCC

http://www.sunrom.com/p-245.html

RS232 INTERFACING

VCC

Interfacing to USB Port and Powering from USB Port


U9 Sunrom Ultrasonic Sensor Model#1127 +5V TX-OUT GND U8 USB to Serial Board SUNROM#1151 RX-IN TX-OUT GND +5V

3 2 1

USB INTERFACING

It will appear as virtual serial port on PC to which you can communicate through any software which can transmit receive by this serial port like hyperterminal or custom made software. We recommend this terminal software on PC to view data

You can use our USB to Serial Board Model 1151

http://www.sunrom.com/p-244.html

1 2 3 4

15

GND

Download it from this link http://www.sunrom.com/files/Terminal.exe

Sunrom Technologies

Your Source for Embedded Systems

Visit us at www.sunrom.com

Application for reading through microcontroller


Connect Serial Out pin to RX pin of microcontroller and set the microcontroller to receive serial data at 9600 baud rate.
VCC

TTL UART INTERFACING


C1 100n P2.0/A8 P2.1/A9 P2.2/A10 P2.3/A11 P2.4/A12 P2.5/A13 P2.6/A14 P2.7/A15 P3.0/RXD P3.1/TXD P3.2/INT0 P3.3/INT1 P3.4/T0 P3.5/T1 P3.6/WR P3.7/RD 21 22 23 24 25 26 27 28 10 11 12 13 14 15 16 17 29 30 VCC U4 Sunrom Ultrasonic Sensor Model#1127 +5V TX-OUT GND 3 2 1

U2 AT89S52 39 38 37 36 35 34 33 32 1 2 3 4 5 6 7 8 VCC + C8 10uF 16V R1 10K 31 P0.0/AD0 P0.1/AD1 P0.2/AD2 P0.3/AD3 P0.4/AD4 P0.5/AD5 P0.6/AD6 P0.7/AD7 P1.0/T2 P1.1/T2EX P1.2 P1.3 P1.4/SS P1.5/MOSI P1.6/MISO P1.7/SCK EA/VPP

VCC XTAL1

40

PSEN ALE/PROG GND RST XTAL2 Y1 18 C10 33p 9

20

19

C9 33p

11.0592

Sample code for AT89S52 microcontroller working at 11.0592 Mhz crystal and reading serial data and displaying to LCD. Following sample code shows how to read the serial data and use the serial data to display value on LCD and convert the serial data to integer.

Sunrom Technologies

Your Source for Embedded Systems

Visit us at www.sunrom.com

Code is in C and can be adapted to any compiler after minor modifications.


#include <REGX51.H> // standard 8051 defines #include <stdio.h> // printf // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // -=-=-=-=- Include files -=-=-=-=-=-=-= // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #include "lcd.h" //This LCD part you will have to create as per your hardware #include "utils.h" // This file only contains delay, you have to create delay function as per your hardware crystal. // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // -=-=-=-=- Hardware Defines -=-=-=-=-=-=-= // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= sbit BUZZER=P1^3; sbit RELAY = P1^5; char sbuf[10], c, length; char buf[16]; unsigned char pos; int range; //receive serial character from serial port char mygetchar(void) { char c; while(!RI); RI =0; c = SBUF; // myputchar(c); // echo to terminal return SBUF; } //convert serial buffer to integer range void convert() { range = (sbuf[0]-0x30)*100; range = range+ (sbuf[1]-0x30)*10; range = range+ (sbuf[2]-0x30)*1; //range } // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= // -=-=-=-=- Main Program -=-=-=-=-=-=-= // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= void main() { // -=-=- Intialize variables -=-=-= BUZZER = 0; RELAY = 0; SCON = 0x52; // 8-bit UART mode TMOD = 0x20; // timer 1 mode 2 auto reload TH1= 0xfd; // 9600 8-n-1 TR1 = 1; // run timer1 // -=-=- Intialise -=-=-= lcdInit(); // -=-=- Welcome LCD Message -=-=-= lcdClear(); lcdGotoXY(0,0); // 1st Line of LCD

Sunrom Technologies

Your Source for Embedded Systems

Visit us at www.sunrom.com

// "xxxxxxxxxxxxxxxx" lcdPrint("WELCOME TO "); lcdGotoXY(0,1); // 2nd Line of LCD // "xxxxxxxxxxxxxxxx" lcdPrint("COLLISION SYSTEM"); delayms(5000); // 5 sec pos = 0; length = 0; // -=-=- Program Loop -=-=-= while(1) { c = mygetchar(); //loop till character received if(c==0x0D) // if received character is <CR> end of line, time to display { length = pos; pos = 0; convert(); // convert serial buffer to integer lcdClear(); lcdGotoXY(0,0); // 1st Line of LCD sprintf (buf, "Range: %c%c%c%c%c%c cm", sbuf[0], sbuf[1], sbuf[2], sbuf[3], sbuf[4], sbuf[5]); lcdPrint(buf); if(range < 20) // we check if range is less than 20 { RELAY = 1; lcdGotoXY(0,1); // 2nd Line of LCD lcdPrint("Collision!!!!"); } else { RELAY = 0; lcdGotoXY(0,1); // 2nd Line of LCD lcdPrint("Preset:20"); //sprintf (buf, "Collision at:%d", 20); //sprintf (buf, "Range: %d", range); //lcdPrint(buf); } } else { //store serial data to buffer sbuf[pos] = c; pos++; } } // end while }// end main

Sunrom Technologies

Your Source for Embedded Systems

Visit us at www.sunrom.com

You might also like