Microcontroller › 8051 › MICRO CONTROLLER BASED ULTRASONIC DISTANCE MEASUREMENT SYSTEM
- This topic has 24 replies, 10 voices, and was last updated 7 years, 9 months ago by Anonymous.
-
AuthorPosts
-
October 26, 2013 at 3:46 pm #2661amit d vekariyaParticipant
An Ultrasonic distance measurement system uses ultrasonic waves (inaudible to humans) to measure distance. These system consist of an Ultrasonic Transmitter (Tx) that emits the ultrasonic wave, the waves after striking any obstacle bounces back and reach the Ultrasonic Receiver (Rx). By measuring the time it take for the whole process to complete and using simple arithmetic we can measure the distance to the obstacle. This system has a wide operating range of 1cm to 400cm with an accuracy of 1cm. This specification makes it ideal for distance measurement application.
The speed of Ultra Sonic waves is 343m/s (speed of sound) which is not too fast for MCUs to measure accurately. Ultrasonic waves travels more narrow, like a beam than normal sound wave. This property helps the sensor detect the obstacles that are exactly in line with it only. The sensors can be rotated with steppers or servo motor to get a “image” of obstacle in the surrounding area (like a radar).
This system can be used as Contact less measurement of liquid level in tanks (even 4m deep tank!), Radars for robot ,car parking.
October 29, 2013 at 8:54 am #10562AJISH ALFREDParticipantHi Amit,
Nice project idea. Do you have any issues or doubts regarding that project?March 6, 2014 at 5:48 am #11213imran akbarParticipantnice………..
March 7, 2014 at 5:26 am #11223ANITHAParticipantcan you give me code for measuring the ultrasonic distance
March 7, 2014 at 6:08 am #11226ANITHAParticipant#include<reg52.h>#define First_Line 0x80#define Second_Line 0xc0#define Curser_On 0x0f#define Curser_Off 0x0c#define Clear_Display 0x01#define Data_Port P0sbit Lcd_rs = P2^7;sbit Lcd_rw = P2^6;sbit Lcd_en = P2^5;sbit RX= P3^2;sbit TX= P3^5;void Distance_Measure();void Lcd8_Init();void Lcd8_Command(unsigned char);void Lcd8_Write(unsigned char,unsigned char);void Lcd8_Display(unsigned char,const unsigned char*,unsigned int);void Lcd8_Decimal2(unsigned char,unsigned char);void Lcd8_Decimal3(unsigned char,unsigned char);void Lcd8_Decimal4(unsigned char,unsigned int);void Delay(unsigned int);void del();unsigned char i,inch1,inch2,result,obj_distance,rept,sec,j,a=0,c=0,kc,cu=0xc0,l,e[20],num[20],n,v[20];unsigned long int count=0,count1=0;void main(){EA=1;ET0=1;TMOD=0x01;TH0=TL0=0x00;TR0=1;relay2=0;Lcd8_Init();Delay(65000);Lcd8_Display(0x80,”Ultrasonic “,16);Lcd8_Display(0xc0,” “,16);Delay(65000);Delay(65000);Lcd8_Display(0xC0,”Distance: “,16);while(1){Distance_Measure();}}void Distance_Measure(){count=count1=0;TH0=0x00;TL0=0x00;TR0=0;for(i=0;i<10;i++){TX=0;Delay(1000);TX=1;Delay(10);TX=0;while(RX==0);TR0=1;while(RX==1);TR0=0;count=TH0<<8;count=count|TL0;TH0=TL0=0x00;count1=count1+count;Delay(5000);}count=count1/10;inch1=count%10000/1000;inch2=count%1000/100;result=(inch1*10)+inch2;obj_distance=result-2;Lcd8_Decimal3(0XCb,obj_distance);}void Lcd8_Init(){Lcd8_Command(0x38); //to select function setLcd8_Command(0x06); //entry mode setLcd8_Command(0x0c); //display onLcd8_Command(0x01); //clear display}void Lcd8_Command(unsigned char com){Data_Port=com;Lcd_en=1;Lcd_rs=Lcd_rw=0;Delay(125);Lcd_en=0;Delay(125);}void Lcd8_Write(unsigned char com,unsigned char lr){Lcd8_Command(com);Data_Port=lr; // DataLcd_en=Lcd_rs=1;Lcd_rw=0;Delay(125);Lcd_en=0;Delay(125);}void Lcd8_Display(unsigned char com,const unsigned char *word,unsigned int n){unsigned char Lcd_i;for(Lcd_i=0;Lcd_i<n;Lcd_i++){Lcd8_Write(com+Lcd_i,word[Lcd_i]);}}void Lcd8_Decimal2(unsigned char com,unsigned char val){unsigned int Lcd_hr,Lcd_t,Lcd_o;Lcd_hr=val%100;Lcd_t=Lcd_hr/10;Lcd_o=Lcd_hr%10;Lcd8_Write(com,Lcd_t+0x30);Lcd8_Write(com+1,Lcd_o+0x30);}void Lcd8_Decimal3(unsigned char com,unsigned char val){unsigned int Lcd_h,Lcd_hr,Lcd_t,Lcd_o;Lcd_h=val/100;Lcd_hr=val%100;Lcd_t=Lcd_hr/10;Lcd_o=Lcd_hr%10;Lcd8_Write(com,Lcd_h+0x30);Lcd8_Write(com+1,Lcd_t+0x30);Lcd8_Write(com+2,Lcd_o+0x30);}i am not getting output for this program can u pls explain mevoid Delay(unsigned int del){while(del–);}March 7, 2014 at 4:29 pm #11231SHAH DISHANT H.ParticipantIts a nice project.
March 25, 2014 at 8:05 am #11381amit d vekariyaParticipantYOU HAVE ANY IDEA HOW TO INTERFACE BUZZER IN THIS PROJECT AT PERTICULAR DISTANCE…..
SUPOSE DISTANCE REACHS AT 100CM AND BUZZER WILL ACTIVATE AUTOMATICALLY…PLZ ANY ONE HAVING ANY IDEA THEN REPLAY…
MY PROGRAMM….
#include<REGX51.h>#include<intrins.h>sfr16 DPTR =0x82;sbit trig=P3^7;unsigned int target_range=0;void delay(unsigned int t){ unsigned int i,j;for(i=0;i<t;i++)for(j=0;j<111;j++);}void lcddata(unsigned char a){ unsigned char q;q=a;a=a & 0xf0;a=a >> 2;P1=a | 0x03;delay(1);P1_1=0;delay(1);q=q & 0x0f;q=q << 2;P1=0x03 ;P1=q | 0x03;delay(1);P1_1=0;}void lcdcmd(unsigned char a){ unsigned char q;q=a;a=a & 0xf0;a=a >> 2;P1=0x02;P1=a | 0x02;delay(1);P1_1=0;delay(1);q=q & 0x0f;q=q << 2;P1=0x02 ;P1=q | 0x02;delay(1);P1_1=0;}void send_pulse(void){TH0=0x00;TL0=0x00;trig=1;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();trig=0;}unsigned char get_range(void){unsigned char range;send_pulse();while(!INT0);while (INT0);DPH=TH0;DPL=TL0;TH0=0xFF;TL0=0xFF;if(DPTR<35000)range=DPTR*1.085/59;elserange=0;return range;}void main(){ unsigned char x,y,z;TMOD=0x09;TR0=1;TH0=0x00;TL0=0x00;P0=0xff;P3_2=1;P0=0XFF;delay(1);lcdcmd(0x33);delay(1);lcdcmd(0x32);delay(1);lcdcmd(0x28);delay(1);lcdcmd(0x0c);delay(1);lcdcmd(0x01);delay(1);lcdcmd(0x80);delay(1);lcddata(‘D’);delay(1);lcddata(‘i’);delay(1);lcddata(‘s’);delay(1);lcddata(‘t’);delay(1);lcddata(‘a’);delay(1);lcddata(‘n’);delay(1);lcddata(‘c’);delay(1);lcddata(‘e’);delay(1);lcddata(‘:’);delay(1);lcdcmd(0x8c);lcddata(‘c’);delay(1);lcddata(‘m’);delay(1);while(1){ lcdcmd(0x89);target_range=get_range();target_range=target_range%1000;z=target_range/100;lcddata(z|0x30);target_range=target_range%100;x=target_range/10;lcddata(x|0x30);y=target_range%10;lcddata(y|0x30);delay(500);}}March 27, 2014 at 3:39 am #11394SHAH DISHANT H.ParticipantHi,
If you want to add buzzer without controller then also you can do that.
Output of ULTRASONIC SENSOR will be analog. Give that output to OP-AMP configured as comparator. Use variable pot output as reference voltage. By changing that value you can set the distance at which you would like to give buzzer signal.
March 27, 2014 at 6:34 am #11402amit d vekariyaParticipantTHANKS BRO….
March 27, 2014 at 7:28 am #11403amit d vekariyaParticipantI M USING HCSRO4 SENSOR ….U MEAN ALSO HELPFUL FOR THIS SENSOR AND U HAVE CKT DIAGRAM FOR
THAT???
March 28, 2014 at 3:45 am #11406SHAH DISHANT H.ParticipantHi,
Ya your sensor will work for that. Use LM358 in comparator mode. If you are not aware of comparator then just google it…!!
You will get it within a min. If you face any issue, revert me back.
April 10, 2014 at 6:22 pm #11520amit d vekariyaParticipantI TRY THIS BUT NOT WORKING..I HAVE CHECKED THE VOLTAGE AT ECHO PIN. OF HCSR04 BUT THERE IS NO VARIATION IN VOLTAGE.
April 12, 2014 at 11:40 am #11536saiParticipantcan any one explin me about this code to measure distance in mm using 3 pin ultrasonic sensor…plz…#include<reg51.h>#include<intrins.h>#include<lcd_busy.h>#define lcd_port P1bit rec_flag=0;bit data_flag=0;void lcd_dispaly();void int_char_con(void);void serial_init();unsigned char array[5],count=0,dis_count=0;unsigned char rec=0;unsigned int dis=0,rot_count=0,ror_flag=0,step=0;unsigned int dis_array[10],direction_count=0,loop_count=0;unsigned int THOUSANDS,HUNDREDS, TENS, UNITS, DISTANCE, TEMP_VAL;////////////////////////////////void main(){// buzzer=0;lcd_init();lcd_init();serial_init();serial_init();message(0x80,”Ultrasonic target”);delay(500);init(0x01);while(1){if(data_flag==1){ES=0;rec_flag=0;data_flag=0;DISTANCE=array[1]*256+array[2];lcd_dispaly();delay(5);count=0;ES=1;}}}//////////////////////////void serial_init(){SCON=0X50; //SM2 SM1 SM0 REN TB8 RB8 TI RI G C/T M1 M0 G C/T M1 M0TMOD=0X20; //0010 0000 // 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0TH1=0XFD; //9600TR1=1;EA=1;ES=1;}////////////////////////////void serial(void) interrupt 4{if(RI==1){RI=0;rec=SBUF;if(rec==0xff){rec_flag=1;}if(rec_flag==1){array[count++]=SBUF;if(count=)data_flag=1;}}}/////////////////////////////////////////////void lcd_dispaly(){int_char_con();dis_count=0;}void int_char_con(void){init(0x80);THOUSANDS = DISTANCE/1000;//to get thousands numTEMP_VAL = DISTANCE%1000;HUNDREDS = TEMP_VAL/100; //to get hundreds numTEMP_VAL %= 100;TENS = TEMP_VAL/10; //to get tens numUNITS = TEMP_VAL%10;write_lcd(THOUSANDS+0x30);write_lcd(HUNDREDS+0x30);write_lcd(TENS+0x30);write_lcd(UNITS+0x30);}April 13, 2014 at 6:22 am #11543SHAH DISHANT H.ParticipantHi,
First check sensor without controller. Connect power supply and keep an object near the sensor. Measure output voltage. Keep moving object and notice variations in output voltage..!!
First make a table of Ditance vs output voltage for accurcate system.
Keep that table here and we will tell what to do next..!!
all the best
May 12, 2015 at 9:10 am #12878Sukhdev chauhanParticipanti want to this project as my final assesment project.
please provide me source code and circuit connectrion with circuit diagram.
it will so much help full if any one of you can provide my this requirement to my mail id
pls help me out
-
AuthorPosts
- You must be logged in to reply to this topic.