GR-ADZUKI ULTRASONIC DISTANCE SENSOR

Pocket


超音波距離センサを使用しました。
パララックス社超音波距離センサーモジュール
http://akizukidenshi.com/catalog/g/gM-05400/


Pingサンプルがそのまま使用できます。
今回は、センサの入出力ピンをD7からD5に変更しただけです。
距離は、サンプルプログラムのままで使用できます。
シリアルモニタに距離が表示されます。

プログラムの説明をします。

センサピンを出力に設定します。
5ミリ秒のパルスを出します。
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

センサピンを入力に設定します。
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
pulseIn()関数は、ピンがHIGHになるのを待ち、時間計測を開始します。その後、ピンがLOWになるのを待ち、時間計測が終了します。
エコーの戻り時間と音速から距離を測ります。
cm = microsecondsToCentimeters(duration);

サンプルプログラムは以下にあります。
https://github.com/jendo1969/GR-ADZUKI2/blob/master/Ping/Ping.ino

超音波距離センサを使用しました。
パララックス社超音波距離センサーモジュール
http://akizukidenshi.com/catalog/g/gM-05400/

Ping sample can be used as it is.
In this example, I changed the sensor input / output pin from D7 to D5.
Distance can be used as it is in the sample program.
The distance is displayed on the serial monitor.

I will explain the program.

Set the sensor pin to output.
I emit a pulse of 5 msec.

pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

Set the sensor pin to input.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
The pulseIn() function waits for the pin to go HIGH and starts time measurement. After that, wait for the pin to go LOW and the time measurement is completed.
Measure the distance from the echo return time and sound speed.

cm = microsecondsToCentimeters(duration);

The sample program is below.
https://github.com/jendo1969/GR-ADZUKI2/blob/master/Ping/Ping.ino

超音波距離センサを使用しました。
パララックス社超音波距離センサーモジュール
http://akizukidenshi.com/catalog/g/gM-05400/

Ping樣本可以照原樣使用。
在這個例子中,我將傳感器輸入/輸出引腳從D7改為D5。
距離可以像在示例程序中一樣使用。
距離顯示在串行監視器上。

我會解釋這個程序。

將傳感器引腳設置為輸出。
我發出5毫秒的脈衝。

pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

將傳感器引腳設置為輸入。
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
pulseIn()函數等待引腳變為高電平並開始時間測量。 之後,等待引腳變為低電平並完成時間測量。
測量迴聲返回時間和聲速的距離。

cm = microsecondsToCentimeters(duration);

示例程序如下。
https://github.com/jendo1969/GR-ADZUKI2/blob/master/Ping/Ping.ino

 

Post Tagged with , ,

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください