![]() |
發(fā)布時間: 2017-3-28 14:17
正文摘要:問題:超聲波測量一個水塔的水位,假如水塔1.5米高,水位有1米,那么我把超聲波模塊固定在水塔的口子上(因為模塊不防水,沒辦法放進水里),測出來的就只是0.5米已經(jīng)用了的水位,而不是還有多少,這個問題怎么解決 ... |
已知水塔深度的話 做減法 水塔深度未知的話 這種方式水塔有水的情況下測量不到水塔深度的 |
做一個相減就行 |
其實可以用共陰極的數(shù)碼管來顯示,而且電路圖幾乎跟你一樣,不用到鎖存器。 求黑幣,求黑幣,求黑幣。。。 #include<reg51.h> #include<intrins.h> #define uint unsigned int #define uchar unsigned char sbit c=P2^0; // sbit b=P2^1; sbit a=P2^2; sbit d=P2^3; sbit trig=P2^4; sbit echo=P2^5; uint time=0; uint timer=0; uchar posit=0; unsigned long s=0; bit flag =0; unsigned char code WE0[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; //uchar temp[3]; //測距接收緩沖區(qū) void delay(uint z) { uchar x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void display() //顯示函數(shù) { a=1,b=0,c=0,d=0; P0=WE0[s/100]; delay(25); P0=0x00; a=0,b=1,c=0,d=0; P0=WE0[s%100/10]; delay(25); P0=0x00; a=0;b=0;c=1;d=0; P0=WE0[s%100%10]; delay(25); P0=0x00; } void time0() interrupt 1 { flag=1; } void StartModule() //啟動模塊 { trig=1; //啟動一次模塊 _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); //delay(20000); trig=0 ; } void count() { time=TH0*256+TL0; TH0=0; TL0=0; s=(time*1.7)/100; //算出來是CM display(); } void main() { TMOD=0x01; //設(shè)T0、T1為方式1,GATE=1; TH0=0; TL0=0; ET0=1; //允許T0中斷 EA=1; // uint z; //開啟總中斷 while(1) { StartModule(); while(!echo); //當UL_RX為零時等待 TR0 = 1; //開啟計數(shù) while(echo); //當UL_RX為1計數(shù)并等待 TR0 = 0; count(); } } |
可以用一個連通器,測得就準了 |
超聲波測水位嚴重不準,測水上漂浮物還可以。 |
先測一個空池深度,然后用池深減去你的測量值,最后顯示剩下的數(shù)就是水深。 |
實地測試了嗎,超聲波遇到水面反射的多嗎,能測準嗎 |
既然用超聲波頭測試距離,那么要知道水位,就要進行簡單的距離計算和判斷,修改這一句 S=(time*1.7)/100; //算出來是CM 對S進行重新計算 S=1.5-((time*17)/100) 試試,然后修改 |
參與人數(shù) 1 | 黑幣 +20 | 收起 理由 |
---|---|---|
![]() | + 20 | 回帖助人的獎勵! |
用水塔高度減去超聲波半程吧,S=150-(time*1.7)/100; //算出來是CM,150是水塔高度,單位cm |
參與人數(shù) 1 | 黑幣 +20 | 收起 理由 |
---|---|---|
![]() | + 20 | 回帖助人的獎勵! |
我的思路是,安裝時,先讓超聲波模塊測量并記錄空水池的深度,作為初始常量--因為該水池深度是不變。 然后,實際運作時,利用超聲波測量到的安裝點到水面距離,記錄測試變量。 最后,簡單計算下即可得到可讀的水位信息:水池深度(初始變量)-水面距離(實測變量) |
參與人數(shù) 1 | 黑幣 +50 | 收起 理由 |
---|---|---|
![]() | + 50 | 回帖助人的獎勵! |
解決的怎么樣了,手繪原理圖很漂亮. |
Powered by 單片機教程網(wǎng)