Working Voltage: DC 5 V
Working Current: 15mA
Working Frequency: 40Hz
Max Range: 4m
Min Range: 2cm
MeasuringAngle: 15 degree
Trigger Input Signal: 10uS TTL pulse
Echo Output Signal: Input TTL lever signal and the range in proportion
Dimension: 45*20*15mm
二、佈線圖
三、程式碼
#define TrigPIN 13 #define EchoPIN 12 #define LED1 8 #define LED2 9 void setup() { pinMode(TrigPIN, OUTPUT); pinMode(EchoPIN, INPUT); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); } void loop() { float duration, distance; digitalWrite(TrigPIN, HIGH); delayMicroseconds(1000); digitalWrite(TrigPIN, LOW); duration = pulseIn (EchoPIN, HIGH);//pulseIn ( ) :讀取一個針腳的脈衝時間(HIGH或LOW) distance = (duration/2)/29; if (distance <= 100) { digitalWrite(LED1, HIGH); delay(distance*1.5 + 10); digitalWrite(LED1, LOW); digitalWrite(LED2, HIGH); delay(distance*1.5 + 10); digitalWrite(LED2, LOW); } delay(100); }
四、作業
1.請將此系統改裝成車雷達(小於一段距離時)產生聲音
五、參考資料
https://eportal.stust.edu.tw/eshare/EshareFile/2014_5/2014_5_c185d20a.pdf
http://blog.lyhdev.com/2012/10/arduino-1hc-sr04.html
沒有留言:
張貼留言