請問大神 為什么程序 超聲波測距返回值一直是0.03 或0.05的錯(cuò)誤值
-
#include <.h> const int trig = 8; // 觸發(fā)信號 const int echo = 5; // 反饋信號 #include
Servo myservo0; float pos0 = 0; float i= 45; float S=100; void setup() { pinMode(echo, INPUT); pinMode(trig, OUTPUT); //觸發(fā)端... #include <.h> const int trig = 8; // 觸發(fā)信號 const int echo = 5; // 反饋信號 #include Servo myservo0; float pos0 = 0; float i= 45; float S=100; void setup() { pinMode(echo, INPUT); pinMode(trig, OUTPUT); //觸發(fā)端口設(shè)置為輸出,反饋端口設(shè)置為輸入 Serial.begin(9600); myservo0.attach(9); myservo1.attach(10); myservo2.attach(11); myservo3.attach(6);// attaches the servo on pin 9 to the servo object } void loop() { long IntervalTime=0; //定義一個(gè)時(shí)間變量 for(pos0 = i; pos0 < 48; pos0 += 0.5) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo0.write(pos0); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } i=pos0; for(pos1 = k; pos1 <73; pos1+= 0.5) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo1.write(pos1); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } k=pos1; while(S>15){ S=0; digitalWrite(trig, 1);//置高電平 delayMicroseconds(15);//延時(shí) 15us digitalWrite(trig, 0);//設(shè)為低電平 IntervalTime=pulseIn(echo, HIGH);//用自帶的函數(shù)采樣反饋的高電平的寬度, 單位 us float S=IntervalTime/58.00; //使用浮點(diǎn)計(jì)算出距離,單位 cm Serial.println(S);//通過串口輸出距離數(shù)值 IntervalTime=0;//對應(yīng)的數(shù)值清零。 delay(500);//延時(shí)間隔決定采樣的頻率,根據(jù)實(shí)際需要變換參數(shù) } 展開
全部評論(1條)
-
- 549228752QQ吧 2017-08-23 16:50:56
- 先看看硬件是否有問題,硬件沒有問題的前提下,應(yīng)該是軟件出問題了。軟件只能慢慢仿真。
-
贊(20)
回復(fù)(0)
熱門問答
- 請問大神 為什么程序 超聲波測距返回值一直是0.03 或0.05的錯(cuò)誤值
- #include <.h> const int trig = 8; // 觸發(fā)信號 const int echo = 5; // 反饋信號 #include
Servo myservo0; float pos0 = 0; float i= 45; float S=100; void setup() { pinMode(echo, INPUT); pinMode(trig, OUTPUT); //觸發(fā)端... #include <.h> const int trig = 8; // 觸發(fā)信號 const int echo = 5; // 反饋信號 #include Servo myservo0; float pos0 = 0; float i= 45; float S=100; void setup() { pinMode(echo, INPUT); pinMode(trig, OUTPUT); //觸發(fā)端口設(shè)置為輸出,反饋端口設(shè)置為輸入 Serial.begin(9600); myservo0.attach(9); myservo1.attach(10); myservo2.attach(11); myservo3.attach(6);// attaches the servo on pin 9 to the servo object } void loop() { long IntervalTime=0; //定義一個(gè)時(shí)間變量 for(pos0 = i; pos0 < 48; pos0 += 0.5) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo0.write(pos0); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } i=pos0; for(pos1 = k; pos1 <73; pos1+= 0.5) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo1.write(pos1); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } k=pos1; while(S>15){ S=0; digitalWrite(trig, 1);//置高電平 delayMicroseconds(15);//延時(shí) 15us digitalWrite(trig, 0);//設(shè)為低電平 IntervalTime=pulseIn(echo, HIGH);//用自帶的函數(shù)采樣反饋的高電平的寬度, 單位 us float S=IntervalTime/58.00; //使用浮點(diǎn)計(jì)算出距離,單位 cm Serial.println(S);//通過串口輸出距離數(shù)值 IntervalTime=0;//對應(yīng)的數(shù)值清零。 delay(500);//延時(shí)間隔決定采樣的頻率,根據(jù)實(shí)際需要變換參數(shù) } 展開
- 超聲波測距程序問題
- #include
#define uchar unsigned char #define uint unsigned int #define ulong unsigned long sbit Tx = P3^3; //產(chǎn)生脈沖引腳 sbit Rx = P3^2; //回波引腳 uchar code SEG7[10]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0...
- 求一份verilog的超聲波測距程序
- 基本要求: 1) 測量距離不低于0.5m,測量精度優(yōu)于0.1m。 2) 數(shù)字顯示測量結(jié)果,并能動(dòng)態(tài)更新,更新周期約為0.5s。 拓展要求: 1) 測量距離大于1m,測量精度優(yōu)于0.05m,顯示精度為0.01m,顯示要求同上。 2) 數(shù)字顯示測量結(jié)果的更新周期可調(diào),顯示... 基本要求: 1) 測量距離不低于0.5m,測量精度優(yōu)于0.1m。 2) 數(shù)字顯示測量結(jié)果,并能動(dòng)態(tài)更新,更新周期約為0.5s。 拓展要求: 1) 測量距離大于1m,測量精度優(yōu)于0.05m,顯示精度為0.01m,顯示要求同上。 2) 數(shù)字顯示測量結(jié)果的更新周期可調(diào),顯示穩(wěn)定。當(dāng)距離小于0.5m時(shí),通過蜂鳴器給出間歇式的“滴-滴”聲響告警;當(dāng)距離小于0.3m時(shí),告警聲響變得更加急促。 3) 其它功能(如使用多個(gè)超聲波傳感器實(shí)現(xiàn)汽車倒車?yán)走_(dá)的功能)。 拓展要求可要可不要,求做過的大佬給份程序謝謝。 展開
- 超聲波測距或單片機(jī)的英文資料
- 我做畢業(yè)設(shè)計(jì) 要用的 關(guān)于超聲波車在倒車?yán)走_(dá) 測距 誰有相關(guān)英文文獻(xiàn)及翻譯啊 英文Z好要原版的 翻譯不要簡單的軟件翻譯的 拜托各位大哥 幫幫小弟
- 求一個(gè)cc2530 超聲波模塊測距的程序
- 基于89C52單片機(jī)的HC-SR04超聲波測距系統(tǒng)程序
- multisim 13.0 示波器B通道的值為什么一直是零?
- 幫幫忙 幫我解釋詳細(xì)下 這個(gè)程序 超聲波測距的
- void Conut(void) { time=TH0*256+TL0; TH0=0; TL0=0; S=(time*1.72)/100; //算出來是CM
- 求一份如圖 基于單片機(jī)超聲波倒車測距的程序
- 這個(gè)51單片機(jī)HC-SR04超聲波測距程序哪里錯(cuò)了
- //晶振11.0592MHz #include
#define uchar unsigned char #define uint unsigned int sbit trig=P0^2; sbit echo=P3^3; float dis=0; uint irtime=0; void delay_20us() { uchar bt ; for(bt=0;bt<100;bt++); } void TI... //晶振11.0592MHz #include #define uchar unsigned char #define uint unsigned int sbit trig=P0^2; sbit echo=P3^3; float dis=0; uint irtime=0; void delay_20us() { uchar bt ; for(bt=0;bt<100;bt++); } void TIM1init(void)//定時(shí)器1初始化 { TMOD=0x22;//定時(shí)器1工作方式2,TH1是重裝值,TL1是初值 TH1=0xd2; //重載值 溢出一次約50us TL1=0xd2; //初始化值 ET1=1; //開中斷 } void EX1init(void) //外部中斷1初始化 { IT1 = 1; //指定外部中斷0下降沿觸發(fā),INT1 (P3.3) EA = 1; //開總中斷 } /*------------------------------------------------ 定時(shí)器1中斷處理 ------------------------------------------------*/ void tim1_isr (void) interrupt 3 { irtime++; //用于計(jì)數(shù)2個(gè)下降沿之間的時(shí)間 } /*------------------------------------------------ 外部中斷1中斷處理 ------------------------------------------------*/ void EX1_ISR (void) interrupt 2 //外部中斷1服務(wù)函數(shù) { dis=340*(irtime/2.0)*50/10000; irtime=0; TR1=0; EX1=0; } void test(void) { trig=1; delay_20us(); trig=0; EX1=1; while(!echo); TR1=1; } void main(void) { TIM1init(); EX1init(); while(1) { test(); display(dis); } } 主函數(shù)調(diào)用test,然后在數(shù)碼管上顯示(顯示函數(shù)略過),測試的時(shí)候,在數(shù)碼管上顯示的距離明顯不對,還各種不穩(wěn)定,有時(shí)就個(gè)位數(shù)上顯示一個(gè)1或2,不知道怎么回事 展開
- 誰有基于AVR atmega16超聲波測距程序 發(fā)給我
- 超聲波測距
- time=timeH*256+timeL; distance=time*0.0172; //厘米 0.0172怎么來的 , distance怎么來的 求具體轉(zhuǎn)換過程,只要真心,一定采納
- 求個(gè)51單片機(jī)超聲波測距(距離+報(bào)警)的c程序
- 求個(gè)51單片機(jī)超聲波測距(距離+報(bào)警)的c程序
- 單片機(jī)大神來看看 出現(xiàn)這錯(cuò)誤怎么回事?這是個(gè)加速度傳感器的程序。
- 超聲波測距的原理
- 超聲波測距模塊
- 1——超聲波模塊測距的有效距離是多少?模塊的有效距離與什么有關(guān)?2——怎樣在一個(gè)單片機(jī)上同時(shí)使用幾個(gè)頻率不同的超聲波模塊(注意是完全同時(shí)工作)?是不是使用頻率不同的模塊就可... 1——超聲波模塊測距的有效距離是多少?模塊的有效距離與什么有關(guān)? 2——怎樣在一個(gè)單片機(jī)上同時(shí)使用幾個(gè)頻率不同的超聲波模塊(注意是完全同時(shí)工作)?是不是使用頻率不同的模塊就可以?如果是的話,那推薦一下每個(gè)模塊的頻率(同時(shí)使用3-4個(gè))。 展開
- 超聲波測距原理
- 找了Z短的程序還是看不懂,怎么感覺這程序是在測回波的時(shí)間而不是測發(fā)波與回波的時(shí)間 //超聲波模塊程序 #include
#define uchar unsigned char #define uint unsigned int code table[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6...
- 超聲波測距公式
- 為什么超聲波聲吶不能用于太空測距?
- 跪求大神幫分析這個(gè)超聲波測距接收電路的工作原理
- TL074的幾個(gè)運(yùn)放與周邊的電阻,電容了起什么作用,看了好久都不懂,求大神幫忙啊
4月突出貢獻(xiàn)榜
推薦主頁
最新話題





參與評論
登錄后參與評論