极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12253|回复: 4

新手求BH1750照度传感器参考程序~~~~

[复制链接]
发表于 2013-3-28 13:45:18 | 显示全部楼层 |阅读模式
新手求BH1750照度传感器参考程序~~~~
回复

使用道具 举报

发表于 2013-3-28 16:22:04 | 显示全部楼层
*
Sample code for the BH1750 Light sensor
Version 0.1
website:www.DFRobot.com

Connection:

VCC-5v
GND-GND
SCL-SCL(analog pin 5)
SDA-SDA(analog pin 4)
ADD-NC
*/


#include <Wire.h> //BH1750 IIC Mode
#include <math.h>
int BH1750address = 0x23; //setting i2c address

byte buff[2];
void setup()
{
  Wire.begin();
  Serial.begin(57600);//init Serail band rate
  Serial.print("begin...");
  delay(2000);
}

void loop()
{
  int i;
  uint16_t val=0;
  BH1750_Init(BH1750address);
  delay(200);

  Serial.print("ini...");
  if(2==BH1750_Read(BH1750address))
  {
    Serial.print("recive...");
    val=((buff[0]<<8)|buff[1])/1.2;
    Serial.print(val,DEC);     
    Serial.println("[lx]");
  }
  delay(150);
}

int BH1750_Read(int address) //
{
  int i=0;
  Wire.beginTransmission(address);
  Wire.requestFrom(address, 2);
  while(Wire.available()) //
  {
    buff = Wire.read();  // receive one byte
    i++;
  }
  Wire.endTransmission();  
  return i;
}

void BH1750_Init(int address)
{
  Wire.beginTransmission(address);
  Wire.write(0x10);//1lx reolution 120ms
  Wire.endTransmission();
}


回复 支持 反对

使用道具 举报

发表于 2013-5-7 11:06:45 | 显示全部楼层
#include <Wire.h>
#include <math.h>

int BH1750address = 0x23;//BH1750 I2C地址
byte buff[2];

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

void loop()
{
    Serial.print( BH1750() );
    Serial.println("[lx]");
}

double BH1750() //BH1750设备操作
{
  int i=0;
  double  val=0;
  //开始I2C读写操作
  Wire.beginTransmission(BH1750address);
  Wire.write(0x10);//1lx reolution 120ms//发送命令
  Wire.endTransmission();  

  delay(200);
  //读取数据
  Wire.beginTransmission(BH1750address);
  Wire.requestFrom(BH1750address, 2);
  while(Wire.available()) //
  {
    buff[i] = Wire.read();  // receive one byte
    i++;
  }
  Wire.endTransmission();
  if(2==i)
  {
   val=((buff[0]<<8)|buff[1])/1.2;
  }
  return val;
}
回复 支持 反对

使用道具 举报

发表于 2017-10-13 12:17:57 | 显示全部楼层
本帖最后由 newspaper 于 2017-10-17 14:09 编辑


前辈,请给看看这个模块用的是那个照度器件。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2017-10-13 13:08:13 | 显示全部楼层
newspaper 发表于 2017-10-13 12:17
前辈,请给看看这个模块用的是那个照度器件。

这个是人体红外传感器
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-26 12:14 , Processed in 0.045871 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表