US-015使用说明书及例程-V2.0+SA-260
US-015是US-020模块的升级版本,和US-020兼容,以前US-020的测试程序US-015也适用。
US-015超声波测距模块例程与US-020的测试例程相同。
文件夹“US_015_GPIO_HighPrecision_ino”是用Arduino进行控制的高精度测距版本。
文件夹中的pde文件为Arduino的工程文件,可通过记事本打开和编辑。
US-015_GPIO_Arduino源程序如下:
- unsigned int EchoPin = 2; // connect Pin 2(Arduino digital io) to Echo at US-015
- unsigned int TrigPin = 3; // connect Pin 3(Arduino digital io) to Trig at US-015
- unsigned long Time_Echo_us = 0;
- unsigned long Len_mm = 0;
- void setup()
- { //Initialize
- Serial.begin(9600); //Serial: output result to Serial monitor
- pinMode(EchoPin, INPUT); //Set EchoPin as input, to receive measure result from US-015
- pinMode(TrigPin, OUTPUT); //Set TrigPin as output, used to send high pusle to trig measurement (>10us)
- }
- void loop()
- {
- digitalWrite(TrigPin, HIGH); //begin to send a high pulse, then US-015 begin to measure the distance
- delayMicroseconds(20); //set this high pulse width as 20us (>10us)
- digitalWrite(TrigPin, LOW); //end this high pulse
-
- Time_Echo_us = pulseIn(EchoPin, HIGH); //calculate the pulse width at EchoPin,
- if((Time_Echo_us < 60000) && (Time_Echo_us > 1)) //a valid pulse width should be between (1, 60000).
- {
- Len_mm = (Time_Echo_us*34/100)/2; //calculate the distance by pulse width, Len_mm = (Time_Echo_us * 0.34mm/us) / 2 (mm)
- Serial.print("Present Distance is: "); //output result to Serial monitor
- Serial.print(Len_mm, DEC); //output result to Serial monitor
- Serial.println("mm"); //output result to Serial monitor
- }
- delay(1000); //take a measurement every second (1000ms)
- }
复制代码
所有资料51hei提供下载:
US-015使用说明书及例程-V2.0 SA-260.rar
(2.21 MB, 下载次数: 99)
|