GY-30 光照传感器

数字光强度检测模块:GY-30

  • 采用ROHM原装BH1750FVI芯片
  • 供电电源 :3-5v
  • 光照度范围:0-65535 lx
  • 传感器内置16bitAD转换器
  • 直接数字输出,省略复杂的计算,省略标定
  • 不区分环境光源
  • 接近于视觉灵敏度的分光特性
  • 可对广泛的亮度进行1勒克斯的高精度测定

代码

采用IIC通讯方式,GY-30VCC接+5V,GND接地。GY-30 SDA 、SCL分别接A4、 A5

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

#include <Wire.h>
// GY-30
// BH1750FVI
// in ADDR 'L' mode 7bit addr
#define ADDR 0b0100011
// addr 'H' mode
// #define ADDR 0b1011100
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Wire.begin();
  Wire.beginTransmission(ADDR);
  Wire.write(0b00000001);
  Wire.endTransmission();
}
void loop() {
  // put your main code here, to run repeatedly:
  int val = 0;
  // reset
  Wire.beginTransmission(ADDR);
  Wire.write(0b00000111);
  Wire.endTransmission();
 
  Wire.beginTransmission(ADDR);
  Wire.write(0b00100000);
  Wire.endTransmission();
  // typical read delay 120ms
  delay(120);
  Wire.requestFrom(ADDR, 2); // 2byte every time
  for (val = 0; Wire.available() >= 1; ) {
    char c = Wire.read();
    //Serial.println(c, HEX);
    val = (val << 8) + (c & 0xFF);
  }
  val = val / 1.2;
  Serial.print("lx: ");
  Serial.println(val);
  Serial.println("OK");
  delay(100);
}