{"id":16148925,"url":"https://github.com/erriez/erriezbh1750","last_synced_at":"2025-08-23T10:32:41.050Z","repository":{"id":85067588,"uuid":"121982652","full_name":"Erriez/ErriezBH1750","owner":"Erriez","description":"BH1750 digital light sensor library for Arduino","archived":false,"fork":false,"pushed_at":"2022-10-01T15:19:06.000Z","size":2204,"stargazers_count":14,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T18:49:53.930Z","etag":null,"topics":["arduino","arduino-uno","bh1750","cpp","documentation","doxygen","gy-302","i2c","library","light","lux","meter","sensor","serial","travis-ci"],"latest_commit_sha":null,"homepage":"https://github.com/Erriez/ErriezArduinoLibrariesAndSketches","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Erriez.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-18T19:22:11.000Z","updated_at":"2022-10-01T15:19:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"84f33e59-2df0-490c-9308-481b295b5453","html_url":"https://github.com/Erriez/ErriezBH1750","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Erriez/ErriezBH1750","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erriez%2FErriezBH1750","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erriez%2FErriezBH1750/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erriez%2FErriezBH1750/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erriez%2FErriezBH1750/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Erriez","download_url":"https://codeload.github.com/Erriez/ErriezBH1750/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Erriez%2FErriezBH1750/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271746655,"owners_count":24813575,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","arduino-uno","bh1750","cpp","documentation","doxygen","gy-302","i2c","library","light","lux","meter","sensor","serial","travis-ci"],"created_at":"2024-10-10T00:35:18.108Z","updated_at":"2025-08-23T10:32:41.026Z","avatar_url":"https://github.com/Erriez.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BH1750 digital light sensor library for Arduino\n\n[![Build Status](https://travis-ci.org/Erriez/ErriezBH1750.svg?branch=master)](https://travis-ci.org/Erriez/ErriezBH1750)\n\nThis is a 16-bit BH1750 digital ambient light sensor on a GY-302 breakout PCB:\n\n![BH1750](https://raw.githubusercontent.com/Erriez/ErriezBH1750/master/extras/BH1750.png)\n\n## Arduino library features\n\n- Measurement in LUX\n- Three operation modes:\n  - Continues conversion\n  - One-time conversion\n- Three selectable resolutions:\n  - Low 4 LUX resolution (low power)\n  - High 1 LUX resolution\n  - High 0.5 LUX resolution\n- Asynchronous and synchronous conversion\n\n\n## BH1750 sensor specifications\n\n- Operating voltage: 3.3V .. 4.5V max\n- Low current by power down: max 1uA\n- I2C bus interface: max 400kHz\n- Ambience light:\n  - Range: 1 - 65535 lx\n  - Deviation: +/- 20%\n  - Selectable resolutions:\n    - 4 lx (low resolution, max 24 ms measurement time)\n    - 1 lx (mid resolution max 180 ms measurement time)\n    - 0.5 lx (high resolution 180 ms measurement time)\n- No additional electronic components needed\n\n\n## GY-302 breakout specifications\n\n- Supply voltage: 3.3 .. 5V\n- 5V tolerant I2C SCL and SDA pins\n- 2 selectable I2C addresses with ADDR pin high or low/floating\n\n\n## Hardware\n\n![Schematic BH1750 and Arduino UNO](https://raw.githubusercontent.com/Erriez/ErriezBH1750/master/extras/BH1750_Arduino_UNO.png)\n\n**Connection Arduino UNO board - BH1750**\n\n| Pins board - BH1750            | VCC  | GND  |    SDA     |    SCL     |\n| ------------------------------ | :--: | :--: | :--------: | :--------: |\n| Arduino UNO (ATMega328 boards) |  5V  | GND  |     A4     |     A5     |\n| Arduino Mega2560               |  5V  | GND  |    D20     |    D21     |\n| Arduino Leonardo               |  5V  | GND  |     D2     |     D3     |\n| Arduino DUE (ATSAM3X8E)        | 3V3  | GND  |     20     |     21     |\n| ESP8266                        | 3V3  | GND  | GPIO4 (D2) | GPIO5 (D1) |\n| ESP32                          | 3V3  | GND  |   GPIO21   |   GPIO22   |\n\nNote: Tested ESP8266 / ESP32 boards:\n\n- **ESP8266 boards**: ESP12E / WeMos D1 \u0026 R2 / Node MCU v2 / v3\n- **ESP32 boards:** WeMos LOLIN32 / LOLIN D32\n\nOther unlisted MCU's may work, but are not tested.\n\n#### WeMos LOLIN32 with OLED display\n\nChange the following Wire initialization to:\n\n```c++\n// WeMos LOLIN32 with OLED support\nWire.begin(5, 4);\n```\n\n### I2C address\n\n* ```ADDR``` pin ```LOW ``` for I2C address 0x23 (0x46 including R/W bit)\n\n* ```ADDR``` pin ```HIGH``` for I2C address 0x5C (0xB8 including R/W bit)\n\n**Note:** ```ADDR``` pin may be floating (open) which is the same as LOW.\n\n## Examples\n\nExamples | Erriez BH1750:\n\n* ContinuesMode | [BH1750ContinuesAsynchronous](https://github.com/Erriez/ErriezBH1750/blob/master/examples/ContinuesMode/BH1750ContinuesAsynchronous/BH1750ContinuesAsynchronous.ino)\n* ContinuesMode | [BH1750ContinuesBasic](https://github.com/Erriez/ErriezBH1750/blob/master/examples/ContinuesMode/BH1750ContinuesBasic/BH1750ContinuesBasic.ino)\n* ContinuesMode | [BH1750ContinuesHighResolution](https://github.com/Erriez/ErriezBH1750/blob/master/examples/ContinuesMode/BH1750ContinuesHighResolution/BH1750ContinuesHighResolution.ino)\n* ContinuesMode | [BH1750ContinuesLowResolution](https://github.com/Erriez/ErriezBH1750/blob/master/examples/ContinuesMode/BH1750ContinuesLowResolution/BH1750ContinuesLowResolution.ino)\n* ContinuesMode | [BH1750ContinuesPowerMgt](https://github.com/Erriez/ErriezBH1750/blob/master/examples/ContinuesMode/BH1750ContinuesPowerMgt/BH1750ContinuesPowerMgt.ino)\n* OneTimeMode | [BH1750OneTimeBasic](https://github.com/Erriez/ErriezBH1750/blob/master/examples/OneTimeMode/BH1750OneTimeBasic/BH1750OneTimeBasic.ino)\n* OneTimeMode| [BH1750OneTimeHighResolution](https://github.com/Erriez/ErriezBH1750/blob/master/examples/OneTimeMode/BH1750OneTimeHighResolution/BH1750OneTimeHighResolution.ino)\n* OneTimeMode| [BH1750OneTimeLowResolution](https://github.com/Erriez/ErriezBH1750/blob/master/examples/OneTimeMode/BH1750OneTimeLowResolution/BH1750OneTimeLowResolution.ino)\n* OneTimeMode| [BH1750OneTimePowerMgt](https://github.com/Erriez/ErriezBH1750/blob/master/examples/OneTimeMode/BH1750OneTimePowerMgt/BH1750OneTimePowerMgt.ino)\n\n\n## Documentation\n\n- [Doxygen online HTML](https://erriez.github.io/ErriezBH1750)\n- [Doxygen PDF](https://github.com/Erriez/ErriezBH1750/raw/master/ErriezBH1750.pdf)\n- [BH1750 chip datasheet](https://github.com/Erriez/ErriezBH1750/raw/master/extras/BH1750_datasheet.pdf)\n\n\n## Example continues conversion high resolution\n\n```c++\n#include \u003cWire.h\u003e\n#include \u003cErriezBH1750.h\u003e\n\n// ADDR line LOW/open:  I2C address 0x23 (0x46 including R/W bit) [default]\n// ADDR line HIGH:      I2C address 0x5C (0xB8 including R/W bit)\nBH1750 sensor(LOW);\n\nvoid setup()\n{\n  Serial.begin(115200);\n  Serial.println(F(\"BH1750 continues measurement high resolution example\"));\n\n  // Initialize I2C bus\n  Wire.begin();\n\n  // Initialize sensor in continues mode, high 0.5 lx resolution\n  sensor.begin(ModeContinuous, ResolutionHigh);\n\n  // Start conversion\n  sensor.startConversion();\n}\n\nvoid loop()\n{\n  uint16_t lux;\n\n  // Wait for completion (blocking busy-wait delay)\n  if (sensor.isConversionCompleted()) {\n    // Read light\n    lux = sensor.read();\n\n    // Print light\n    Serial.print(F(\"Light: \"));\n    Serial.print(lux / 2);\n    Serial.print(F(\".\"));\n    Serial.print(lux % 10);\n    Serial.println(F(\" LUX\"));\n  }\n}\n```\n**Output**\n```c++\nBH1750 continues measurement high resolution example\nLight: 15.0 LUX\nLight: 31.2 LUX\nLight: 385.0 LUX\nLight: 575.1 LUX\nLight: 667.5 LUX\n```\n\n## Usage\n\n### Initialization\n\n```c++\n#include \u003cWire.h\u003e\n#include \u003cErriezBH1750.h\u003e\n\n// ADDR line LOW/open:  I2C address 0x23 (0x46 including R/W bit) [default]\n// ADDR line HIGH:      I2C address 0x5C (0xB8 including R/W bit)\nBH1750 sensor(LOW);\n\nvoid setup()\n{\n  \t// Initialize I2C bus\n  \tWire.begin();\n    \n    // Initialize sensor with a mode and resolution:\n    //   Modes:\n    //     ModeContinuous\n    //     ModeOneTime\n    //   Resolutions:\n    //     ResolutionLow (4 lx resolution)\n    //     ResolutionMid (1 lx resolution)\n    //     ResolutionHigh (0.5 lx resolution)\n    sensor.begin(mode, resolution);\n}\n```\n\n### Start conversion\n\n```Wire.begin();``` and ```sensor.begin();``` must be called before starting the conversion:\n\n```c++\nsensor.startConversion();\n```\n\n### Wait for completion asynchronous (non-blocking)\n\nThe sensor conversion completion status can be checked asynchronously before reading the light value:\n\n```c++\nbool completed = sensor.isConversionCompleted();\n```\n\n### Wait for completion synchronous (blocking)\n\nThe sensor conversion completion status can be checked synchronously before reading the light value:\n\n```c++\n// Wait for completion\n// completed = false: Timeout or device in power-down\nbool completed = sensor.waitForCompletion();\n```\n\n### Read light value in LUX\n\n**One-time mode:** The application must wait or check for a completed conversion, otherwise the sensor may return an invalid value. \n**Continues mode:** The application can call this function without checking completion, but is not recommended when accurate values are required.\n\nRead sensor light value:\n\n```c++\n// lux = 0: No light or not initialized\nuint16_t lux = sensor.read();\n```\nFor 4 lx low and 1 lx high resolutions:\n\n```c++\n// Print low and medium resolutions\nSerial.print(F(\"Light: \"));\nSerial.print(lux);\nSerial.println(F(\" LUX\"));\n```\n\nFor 0.5 lx high resolution:\n\n```c++\n// Print high resolution\nSerial.print(F(\"Light: \"));\nSerial.print(lux / 2);\nSerial.print(F(\".\"));\nSerial.print(lux % 10);\nSerial.println(F(\" LUX\"));\n```\n\n### Power down\n\nThe device enters power down automatically after a one-time conversion.\n\nA manual power-down in continues mode can be generated by calling:\n\n```c++\nsensor.powerDown();\n```\n\n## Library dependencies\n\n- Built-in ```Wire.h```\n\n\n## Library installation\n\nPlease refer to the [Wiki](https://github.com/Erriez/ErriezArduinoLibrariesAndSketches/wiki) page.\n\n\n## Other Arduino Libraries and Sketches from Erriez\n\n* [Erriez Libraries and Sketches](https://github.com/Erriez/ErriezArduinoLibrariesAndSketches)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferriez%2Ferriezbh1750","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferriez%2Ferriezbh1750","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferriez%2Ferriezbh1750/lists"}