RPR-0521RS是将光学式接近传感器和红外LED(IrLED)、数字照度传感器整合在一起的传感器。 接近传感器 (PS)通过对IrLED发射光线的接近物产生的反射光,检测出人及物体的接近。另外,照度传感器(ALS)可测量从昏暗光线到直射日光的广泛照度。根据照度数据调整LCD显示器及按键的亮度,从而提高组件的节电性能和画面的可视性。
RPR-0521RS系列光学传感器特点: ·
兼容I2C BUS接口(支持f/s模式); ·
兼容1.8V逻辑接口;
·掉电模式下,电流损耗低;
·有两种ALS输出值:可见光(Data0)对应光谱响应峰值;红外线光(Data1)对应光照度计算。
·能检测到从黑暗环境乃至直接太阳光照的环境范围,具有广泛的照度测量;
·具有抑制(工频)50Hz/60Hz光噪声(ALS功能下);
·光学接近传感探测范围在1~100mm(可通过I2C接口调整);
·内置电流配置的IrLED驱动器;
在网上找到rpr-0521rs的arduino库,现在来测试一下,读取传感器数值。
传感器接如下I2C引脚。
代码如下:
/*****************************************************************************
RPR-0521RS.ino
Copyright (c) 2016 ROHM Co.,Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
******************************************************************************/
#include <Wire.h>
#include <RPR-0521RS.h>
RPR0521RS rpr0521rs;
#define myLED 15 //设置引脚15为LED引脚
void setup() {
byte rc;
pinMode(myLED, OUTPUT);
digitalWrite(myLED, HIGH);
Serial.begin(115200);
Serial.println("******************************** senser test *******************************************");
Wire.begin();
rc = rpr0521rs.init();
}
void loop() {
byte rc;
unsigned short ps_val;
float als_val;
byte near_far;
digitalWrite(myLED, HIGH);
delay(100);
rc = rpr0521rs.get_psalsval(&ps_val, &als_val);
if (rc == 0) {
Serial.print(F("RPR-0521RS (Proximity) = "));
Serial.print(ps_val);
Serial.print(F(" [count]"));
near_far = rpr0521rs.check_near_far(ps_val);
if (near_far == RPR0521RS_NEAR_VAL) {
Serial.println(F(" Near"));
} else {
Serial.println(F(" Far"));
}
if (als_val != RPR0521RS_ERROR) {
Serial.print(F("RPR-0521RS (Ambient Light) = "));
Serial.print(als_val);
Serial.println(F(" [lx]"));
Serial.println();
}
}
digitalWrite(myLED, LOW);
delay(1000);
}
编译烧写
然后复位,可以看到串口输出数据如下: