基本資料:
電壓: | 5V |
靜態電流: | 2.2mA |
感應角度: | 不大於 15度 |
探測距離: | 2 - 400 cm |
探測精度: | 0.1cm+1% |
分辨率: | 高於 1mm (可達 0.5mm) |
相關資料下載:
US-015
US-015-V2.0
接線方法:
UNO | US-015 |
---|---|
D2 | Echo |
D3 | Trig |
5V | VCC |
GND | GND |
測試程式:
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) }
沒有留言:
張貼留言