Home> Note> Arduino> Arduino 亮度土壤濕度計(四)-亮度計 BH1750

Arduino 亮度土壤濕度計(四) - 亮度計 BH1750

2015.10.13

  第一篇已經提過這個東西的材料、功能,先複習一下成品,如下圖

Lose image

繼續介紹的是亮度感測器 BH1750,如下圖:

Lose image Lose image

這光照度感測模組最大的特色,在於可以直接將測量出的光照度轉換為數位資料,其單位為流明(Lux)

可量測區間為1 - 65535 lx

另外使用 I2C 腳位,Arduino UNO 為A4(SDA)、A5(SCL)腳位,其I2C通訊腳位已經內建電壓準位轉換電路,可以直接使用5V、3.3V,其測量出的值也較為準確。

Lose image Lose image

感測器電路圖:

Lose image

來源:BHT1750 datasheet

腳位 說明 接法
VCC Voltage +5V
SCL Serial data line Arduino UNO analog pin 5
SSA Serial clock line Arduino UNO analog pin 4
ADDR Slave Address is 2 types, it is determined by ADDR Terminal
ADDR = ‘H’ ( ADDR ≧ 0.7VCC ) → “1011100“="5C HEX"
ADDR = 'L' ( ADDR ≦ 0.3VCC ) → “0100011“="23 HEX"
GND
GND Ground GND

以下內容是我已經縮減過後的程式碼,如果需要完整的請 google ~

宣告

I2C 定址在 0x23 ( 因為ADDR 接地 )

--------------------------------------------------------------------

 #include <Wire.h>//亮度
 int BH1750_address = 0x23; // i2c Addresse  
 byte buff[2];
 int valf=0;

--------------------------------------------------------------------

void setup() 設定

--------------------------------------------------------------------

void setup(){
  Serial.begin(9600);
  BH1750_Init(BH1750_address);
}

--------------------------------------------------------------------

void loop()

--------------------------------------------------------------------

void loop(){
  BH1750();
  Serial.println(valf);
}
 

--------------------------------------------------------------------

副程式

--------------------------------------------------------------------

    
  void BH1750(){
  
    if(BH1750_Read(BH1750_address)==2){
      
      valf=((buff[0]<<8)|buff[1])/1.2;
    }
  }
  void BH1750_Init(int address){
    
    Wire.beginTransmission(address);
    Wire.write(0x10); // 1 [lux] aufloesung
    Wire.endTransmission();
  }
  
  byte BH1750_Read(int address){
    
    byte i=0;
    Wire.beginTransmission(address);
    Wire.requestFrom(address, 2);
    while(Wire.available()){
      buff[i] = Wire.read(); 
      i++;
    }
    Wire.endTransmission();  
    return i;
  }
 

--------------------------------------------------------------------

結果:

Lose image

其數值結果單位為「流明」,如果在辦公室、教室日光燈,大約為 300 to 500 左右,當手指完全遮住時,會趨近於 0。
備註:1 流明/平方米 = 1 燭光/平方米。

----------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------

Top