i wanna build a distance measure using ultrasonic and i have the module vm125 by vellemanusa on this link here
it suppose to measure distance between range: 0.66-8.20ft or 20.12-249.94cm
the module has an analog output which represent the distance and it has rating of voltage output 0-5v
am using pic microcontroller and in my case 16f876 but am confused i can't measure the right distance and i guess there is some thing wrong in my calculation
the adc has a resolution of 10bit and the analog output is 5v so the analog reading will represent the distance using this formula
distance = adc reading * (5/1024) but when i tested it gives me wrong result can any one help me here plz
i include her the code and photos of the circuit
it suppose to measure distance between range: 0.66-8.20ft or 20.12-249.94cm
the module has an analog output which represent the distance and it has rating of voltage output 0-5v
am using pic microcontroller and in my case 16f876 but am confused i can't measure the right distance and i guess there is some thing wrong in my calculation
the adc has a resolution of 10bit and the analog output is 5v so the analog reading will represent the distance using this formula
distance = adc reading * (5/1024) but when i tested it gives me wrong result can any one help me here plz
i include her the code and photos of the circuit
Rich (BB code):
void initialize(){
PORTA=0x00;
TRISA=0x01;
ADCON1=0b10001110;
ADCON0=0b10000000;
ADCON0.f0=1;
Lcd_Init(&PORTB);
Lcd_Cmd(Lcd_CLEAR);
Lcd_Cmd(Lcd_CURSOR_OFF);
}
void ad_read(){
ADCON0.f2=1;
while(ADCON0.f2==1){}
ad_res=0;
ad_res=ADRESH;
ad_res=ad_res<<8;
ad_res=ad_res+ADRESL;
distance=ad_res*(5/1024);
Lcd_Cmd(Lcd_Clear);
FloatToStr(distance, ad_res_txt);
Lcd_Out_Cp(ad_res_txt);
Lcd_Out_Cp("cm");
Lcd_Cmd(LCD_SECOND_ROW);
WordToStr(ad_res, ad_res_txt);
Lcd_Out_Cp(ad_res_txt);
}