搜索代码

How to Use a BH1750 to Measure Light Lux with an Arduino

How to Use a BH1750 to Measure Light Lux with an Arduino

This video shows you how to use the BH1750 light intensity lux sensor. You will also learn how to change the I2C address of the module.

🔴 light intensity lux sensor

图像

BH1750 Light intensity, Lux sensor
BH1750 Light intensity, Lux sensor
Arduino wiring for BH1750 Light intensity, Lux sensor
Arduino wiring for BH1750 Light intensity, Lux sensor
314-How to use a BH1750 to measure light lux with an Arduino
语言: C++
/*

  Example of BH1750 library usage.
  This code is part of the library; it is here: https://github.com/claws/BH1750

  This example initializes the BH1750 object using the default high resolution
  continuous mode and then makes a light level reading every second.
  Watch video instructions for this code: https://youtu.be/iKUwu220UFQ
  Video posted on April 20, 2020 on YouTube

  Connection:

    VCC -> 3V3 or 5V
    GND -> GND
    SCL -> SCL (A5 on Arduino Uno, Leonardo, etc or 21 on Mega and Due, on esp8266 free selectable)
    SDA -> SDA (A4 on Arduino Uno, Leonardo, etc or 20 on Mega and Due, on esp8266 free selectable)
    ADD -> (not connected) or GND



 
 * Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place. 

****************************
Get early access to my videos via Patreon and have your name mentioned at the end of every 
video I publish on YouTube here: http://robojax.com/L/?id=63 (watch until the end of this video for a list of my Patrons)
****************************

or make a donation using PayPal http://robojax.com/L/?id=64

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.* 
 * This code has been downloaded from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

*/


#include <Wire.h>
#include <BH1750.h>

BH1750 lightMeter;


void setup(){

  Serial.begin(9600);

  // Initialize the I2C bus (BH1750 library doesn't do this automatically)
  Wire.begin();
  // On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);

  lightMeter.begin();

  Serial.println(F("BH1750 Test begin"));

}


void loop() {

  float lux = lightMeter.readLightLevel();
  Serial.print("Light: ");
  Serial.print(lux);
  Serial.println(" lx");
  delay(1000);

}

资源与参考

文件📁

没有可用的文件。