1/27/2024 0 Comments Arduino sensorsYou can check all BH1750 library examples here. The library we’re using with the BH1750 sensor provides other examples that illustrate other useful functions and features. Go to Tools > Port and select the COM port your board is connected to. Then, go to Tools > Board and select the Arduino board you’re using. First, connect your board to your computer. Now, you can upload the code to your board. You get and print a new reading every second. float lux = lightMeter.readLightLevel() įinally, display the measurement on the Serial Monitor. To get the value, you simply call the readLightLevel() function on the BH1750 object ( lightMeter). In the loop(), we create a variable called lux, that saves the luminance values. Initialize the sensor using the begin() method on the BH1750 object ( lightMeter). If you want to use different I2C pins, pass them to the begin() method like this Wire.begin(SDA, SCL). It will start an I2C communication on the microcontroller’s default I2C pins. In the setup(), initialize the Serial Monitor at a baud rate of 9600. Then, we create a BH1750 object called lightMeter. The Wire.h library to use I2C communication protocol and the BH1750.h library to read from the sensor. We start by including the required libraries. The library also provides other examples worth exploring. For Wemos / Lolin D1 Mini Pro and the Ambient Light shield use Wire.begin(D2, D1) On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3) Initialize the I2C bus (BH1750 library doesn't do this automatically) This example initialises the BH1750 object using the default high resolution continuous mode and then makes a light level reading every second. It is the example code from the library called BH1750test (you can access it in File > Examples > BH1750 > BH1750test /*Įxample of BH1750 library usage. This code simply reads ambient light in lux and displays the values on the Serial Monitor. ApplicationsĬode – Reading BH1750 Ambient Light SensorĬopy the following code to your Arduino IDE. In one-time measurement mode, the sensor measures the ambient light value once, and then it goes to power down mode. In continuous measurement mode, the sensor continuously measures ambient light values. Each mode supports three different resolution modes. The sensor supports two different measurement modes: continuous measurement mode, and one-time measurement mode. The influence of infrared is very small.It is possible to select 2 different I2 C slave-addresses.50Hz / 60Hz Light noise reject-function.Spectral responsibility is approximately human eye response.For more information consult the BH1750 sensor datasheet. Here’s a list of the BH1750 sensor features.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |