“数字光线”的版本间的差异

来自Labplus盛思维基百科
跳转至: 导航搜索
技术参数
使用教程
第27行: 第27行:
  
 
== 使用教程 ==
 
== 使用教程 ==
 +
<font size="3.5">BH1750FVI支持单次或连续两种测量模式,每种测量模式又提供了0.5lux、1lux、4lux三种分辨率供选择。分辨力越高,一次测量所需的时间就越长。在单次测量模式时,每次测量之后传感器都自动进入Power Down模式。</font>
 +
{|
 +
|-
 +
| :[[文件:BH1750测量模式.png|800px|左|缩略图|BH1750测量模式]]
 +
|}
  
 +
=== <font size="3">Arduino示例</font> ===
 +
<pre style="color:blue">
 +
/*
 +
Measurement of illuminance using the BH1750FVI sensor module
 +
Connection:
 +
Module        UNO
 +
VCC    <----->    5V
 +
GND    <----->    GND
 +
SCL    <----->    A5
 +
SDA    <----->    A4
 +
 +
*/
 +
#include <Wire.h>
 +
 +
#define ADDRESS_BH1750FVI 0x23    //ADDR="L" for this module
 +
#define H_RESOLUTION_MODE 0x10
 +
//continuously H-Resolution Mode:
 +
//Resolution = 1 lux
 +
//Measurement time (max.) = 120ms
 +
//Power down after each measurement
 +
 +
byte highByte = 0;
 +
byte lowByte = 0;
 +
unsigned int sensorOut = 0;
 +
unsigned int illuminance = 0;
 +
 +
 +
void setup()
 +
{
 +
Wire.begin();
 +
Serial.begin(115200);
 +
}
 +
 +
void loop()
 +
{
 +
Wire.beginTransmission(ADDRESS_BH1750FVI); //"notify" the matching device
 +
Wire.write(H_RESOLUTION_MODE);    //set operation mode
 +
Wire.endTransmission();
 +
 +
delay(120);
 +
 +
Wire.requestFrom(ADDRESS_BH1750FVI, 2); //ask Arduino to read back 2 bytes from the sensor
 +
highByte = Wire.read();  // get the high byte
 +
lowByte = Wire.read(); // get the low byte
 +
 +
sensorOut = (highByte << 8) | lowByte;
 +
illuminance = sensorOut / 1.2;
 +
Serial.print(illuminance);    Serial.println(" lux");
 +
 +
delay(1000);
 +
}
 +
</pre>
 
=== <font size="3">Python示例</font> ===
 
=== <font size="3">Python示例</font> ===
 
<pre style="color:blue">
 
<pre style="color:blue">

2018年8月14日 (二) 11:47的版本

黑色传感器最终版12.20-38.png

概述

基于BH1750数字型光照度传感器集成IC。用于检测环境光线的强度,可对广泛的亮度进行1勒克斯的高精度测定。采用I2C通讯方式,操作简便。

技术参数

  • 工作电压:VCC 3.3-5V
  • 接口方式:I2C接口
  • 光照度范围:0-65535 lux
  • 直接输出对应亮度的数字值
  • 光源依赖性弱(白炽灯,荧光灯,卤素灯,白光LED,日光灯)
  • 受红外线影响很小
  • 最小变动在±20%
  • 模块尺寸:24x46x7.5mm

引脚定义

VCC 电源
SDA I2C数据
SCL I2C时钟
GND

使用教程

BH1750FVI支持单次或连续两种测量模式,每种测量模式又提供了0.5lux、1lux、4lux三种分辨率供选择。分辨力越高,一次测量所需的时间就越长。在单次测量模式时,每次测量之后传感器都自动进入Power Down模式。

 :
BH1750测量模式

Arduino示例

/*
Measurement of illuminance using the BH1750FVI sensor module
Connection:
Module        UNO
VCC    <----->    5V
GND    <----->    GND
SCL    <----->    A5
SDA    <----->    A4

*/
#include <Wire.h>

#define ADDRESS_BH1750FVI 0x23    //ADDR="L" for this module
#define H_RESOLUTION_MODE 0x10
//continuously H-Resolution Mode:
//Resolution = 1 lux
//Measurement time (max.) = 120ms
//Power down after each measurement

byte highByte = 0;
byte lowByte = 0;
unsigned int sensorOut = 0;
unsigned int illuminance = 0;


void setup()
{
	Wire.begin();
	Serial.begin(115200);
}

void loop()
{
	Wire.beginTransmission(ADDRESS_BH1750FVI); //"notify" the matching device
	Wire.write(H_RESOLUTION_MODE);     //set operation mode
	Wire.endTransmission();

	delay(120);

	Wire.requestFrom(ADDRESS_BH1750FVI, 2); //ask Arduino to read back 2 bytes from the sensor
	highByte = Wire.read();  // get the high byte
	lowByte = Wire.read(); // get the low byte

	sensorOut = (highByte << 8) | lowByte;
	illuminance = sensorOut / 1.2;
	Serial.print(illuminance);    Serial.println(" lux");

	delay(1000);
}

Python示例

from microbit import *
import math
display.off()

def getAmbientLight():
  i2c.write(0x23, bytearray([0x10]))
  sleep(120)
  t=i2c.read(0x23, 2)
  sleep(10)
  return (t[0]*256 + t[1])/1.2

while True:
    print('Light:',getAmbientLight())
    sleep(500)
  

图形化示例

实物连接如下图:
数字光线2.png
程序功能:数码管显示数字光线传感器的测量值
数字光线传感器.png

版本历史记录

Version Date Note [+]新增[-]删除[^]修复
V2.0