超音波レーダーを動かす

URM37の今売られてるのはV4.0、V3系から制御ICも変わっていて使い方も多少異なるようです。

URM37には機能は超音波センサー以外もあるらしいが今使うのは距離センサーでレーダー的に。V4のサンプルプログラムは見つからないのでV5参照、おそらく部品配置同じだから使い方も同じだろうから。

URM37の動作電圧は3.3~5.5VでArduino自身は内部3.3V動作だから、電源はArduinoの3.3V出力から供給して、制御ピンは

// # Pin 3 (Arduino) -> Pin 7 ECHO (URM V5.0)
// # Pin 5 (Arduino) -> Pin 6 COMP/TRIG (URM V5.0)

のように、トリガーはDIOの7、戻りのパルスはDIOの6で受けています。

工場出荷時のデフォルトはTTLになっているのでジャンパー設定は不要、というかジャンパー設定が存在しない。使い方含めて以下のメーカーサイトに記載あります。

https://wiki.dfrobot.com/URM37_V5.0_Ultrasonic_Sensor_SKU_SEN0001_

The factory default settings

  • Serial TTL level
  • Measure mode: PWM trigger
  • Comparison of distance : 0
  • Automatically measure interval time:25ms
  • Internal EEPROM Data are all 0x00
  • the EEPROM address are unavailable: 0x00~0x04, please do not try to modify the data.

一番手間の掛からなそうな、デフォルトのPWM trigger modeで使います。動作確認コードはDIOだけは変更設定して他はほぼそのまま使っています。


// # Editor : roker
// # Date : 05.03.2018

// # Product name: URM V5.0 ultrasonic sensor
// # Product SKU : SEN0001
// # Version : 1.0

// # Description:
// # The Sketch for scanning 180 degree area 2-800cm detecting range
// # The sketch for using the URM37 PWM trigger pin mode from DFRobot
// # and writes the values to the serialport
// # Connection:
// # Vcc (Arduino) -> Pin 1 VCC (URM V5.0)
// # GND (Arduino) -> Pin 2 GND (URM V5.0)
// # Pin 6 (Arduino) -> Pin 4 ECHO (URM V5.0)
// # Pin 7 (Arduino) -> Pin 6 COMP/TRIG (URM V5.0)

// # Working Mode: PWM trigger pin mode.

int URECHO = 6; // PWM Output 0-50000US,Every 50US represent 1cm
int URTRIG = 7; // trigger pin

unsigned int DistanceMeasured = 0;

void setup()
{
//Serial initialization
Serial.begin(9600); // Sets the baud rate to 9600
pinMode(URTRIG, OUTPUT); // A low pull on pin COMP/TRIG
digitalWrite(URTRIG, HIGH); // Set to HIGH
pinMode(URECHO, INPUT); // Sending Enable PWM mode command
delay(500);
Serial.println(“Init the sensor”);

}
void loop()
{
Serial.print(“Distance=”);
digitalWrite(URTRIG, LOW);
digitalWrite(URTRIG, HIGH);

unsigned long LowLevelTime = pulseIn(URECHO, LOW) ;
if (LowLevelTime >= 50000) // the reading is invalid.
{
Serial.println(“Invalid”);
}
else
{
DistanceMeasured = LowLevelTime / 50; // every 50us low level stands for 1cm
Serial.print(DistanceMeasured);
Serial.println(“cm”);
}

delay(100);
}

距離センサーの精度としては、対象物が多少傾いていてもセンターから多少外れてもきちんと距離を出してくれるので使えるセンサーです。

 

admin