超声波传感器

简介

这是一款开放式双探头超声波测距模块,通信方式为I2C,采用Gravity标准PH2.0-4P立式贴片座接口。该模块兼容arduino、树莓派等各种3.3V或5V逻辑电平的主控板。模块自带温度补偿,平整墙面的有效测距量程为2–500cm,分辨率为1cm,误差约为±1%。 设计150cm、300cm、500cm 三个测距量程可供程序选择切换,更短的量程设置会带来更短的测距周期和更低的测距灵敏度,用户可根据实际使用需求灵活设置。

技术规格

接口说明

URM09 V2.0模块

引脚 引脚说明
VCC 电源输入(3.3V-5.5V)
GND 电源地
C I2C时钟线SCL
D I2C数据线SDA

使用教程

URM09是一款简洁实用的超声波传感器,它采用的是I2C通信方式,可以方便的与具有I2C接口的主板时行通信

寄存器表

URM09 Ultrasonic Sensor(Gravity I²C)(V2.0)寄存器一览表

硬件连接

将模块通过I2C接口与UNO连接,如图:
URM09连线图

Arduino 距离及温度测量

模块出厂默认为被动测量模式,通过写命令寄存器发送测距命令,模块收到命令后便启动一次测距(测距时间与测距量程有关),当测距完成后,读取距离寄存器便可得到距离值。而温度测量直接读出温度寄存器后,经过简单处理就可以得到测得的温度值。

演示代码

/*!
      PassiveMesure.ino

      Download this demo to test config to URM09, connect sensor through IIC interface
      Data will print on your serial monitor

      This example is the ultrasonic passive measurement distance and the temperature of the module.

      Copyright   [DFRobot](http://www.dfrobot.com), 2016
      Copyright   GNU Lesser General Public License

      version  V2.0
      date  09/07/2019
*/
#include "DFRobot_URM09.h"

/* Create a URM09 object to communicate with IIC. */
DFRobot_URM09 URM09;

void setup() {
  Serial.begin(9600);
  while (!URM09.begin())
  {
    Serial.println("I2c device number error ");
    delay(1000);
  }
  /*
    The module is configured in automatic mode or passive ,
     MEASURE_MODE_AUTOMATIC       // automatic mode
     MEASURE_MODE_PASSIVE         // passive mode

    The measurement distance is set to 500,300,100
     MEASURE_RANG_500              // Ranging from 500
     MEASURE_RANG_300              // Ranging from 300
     MEASURE_RANG_150              // Ranging from 100
  */
  URM09.SetModeRange(MEASURE_MODE_PASSIVE , MEASURE_RANG_500);
  delay(100);
}

void loop() {
  URM09.SetMeasurement();                          // Send ranging command
  delay(100);
  int16_t dist = URM09.i2cReadDistance();          // Read distance register
  int16_t temp = URM09.i2cReadTemperature();       // Read temperature register
  Serial.print(dist, DEC); Serial.print(" cm------"); Serial.print((float)temp / 10, 1); Serial.println(" C");

  delay(100);

}

演示效果
URM09距离及温度读取

Raspberry 距离及温度测量

演示代码

# -*- coding:utf-8 -*-
'''
    # PassiveMeasure.py
    #
    # Connect board with raspberryPi.
    # Make board power and URM09 connection correct.
    # Run this demo.
    #
    # Set the i2c communication device number.
    # Set test mode and distance.
    # Get temperature and distance data.
    #
    # Copyright   [DFRobot](http://www.dfrobot.com), 2016
    # Copyright   GNU Lesser General Public License
    #
    # version  V2.0
    # date  2019-7-09
'''
import sys
import time

import URM09

sys.path.append("../..")
''' Create a URM09 object to communicate with I2C. '''
URM09 = URM09.DFRobot_URM09()
''' Set the i2c device number '''
URM09.begin(0x11)
time.sleep(0.1)
'''
    # The module is configured in automatic mode or passive
    #  _MEASURE_MODE_AUTOMATIC        // automatic mode
    #  _MEASURE_MODE_PASSIVE          // passive mode

    # The measurement distance is set to 500,300,100
    #  _MEASURE_RANG_500              // Ranging from 500
    #  _MEASURE_RANG_300              // Ranging from 300
    #  _MEASURE_RANG_150              // Ranging from 100
'''
URM09.SetModeRange(URM09._MEASURE_MODE_PASSIVE, URM09._MEASURE_RANG_500)
while(1):
    ''' Write command register and send ranging command '''
    URM09.SetMeasurement()
    time.sleep(0.1)
    ''' Read distance register '''
    dist = URM09.i2cReadDistance()
    ''' Read temperature register '''
    temp = URM09.i2cReadTemperature()

    print("Temperature is %.2f .c    " % (temp / 10))
    print("Distance is %d cm         " % dist)
    time.sleep(0.1)

演示结果
URM09距离及温度测量

疑难解答

如果遇到技术问题,请登陆到我们的售后论坛留言,我们会尽快解答您的问题。

更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖!

更多

DFshopping_car1.png DFRobot商城购买链接