{"id":25151,"date":"2022-04-13T08:02:41","date_gmt":"2022-04-12T23:02:41","guid":{"rendered":"https:\/\/www.souichi.club\/?p=25151"},"modified":"2022-04-13T08:03:11","modified_gmt":"2022-04-12T23:03:11","slug":"bh1750","status":"publish","type":"post","link":"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/","title":{"rendered":"Measuring illuminance with light intensity sensor module (BH1750FVI) and ESP32"},"content":{"rendered":"<ul class=\"bogo-language-switcher list-view\"><li class=\"en-US en current first\"><span class=\"bogoflags bogoflags-us\"><\/span> <span class=\"bogo-language-name\"><a rel=\"alternate\" hreflang=\"en-US\" href=\"https:\/\/www.souichi.club\/en\/wp-json\/wp\/v2\/posts\/25151\/\" title=\"English\" class=\"current\" aria-current=\"page\">English<\/a><\/span><\/li>\n<li class=\"ja last\"><span class=\"bogoflags bogoflags-jp\"><\/span> <span class=\"bogo-language-name\"><a rel=\"alternate\" hreflang=\"ja\" href=\"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/25151\/\" title=\"Japanese\">\u65e5\u672c\u8a9e<\/a><\/span><\/li>\n<\/ul>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e32a92cab63\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #454e5c;color:#454e5c\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #454e5c;color:#454e5c\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e32a92cab63\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#BH1750FVI\" >BH1750FVI<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#Measurement_Mode\" >Measurement Mode<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#MTReg\" >MTReg<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#Calculation_Formula\" >Calculation Formula<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#Connectors\" >Connectors<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#I2C_Address\" >I2C Address<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#Other_Parts\" >Other Parts<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#ESP32_module\" >ESP32 module<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#Silicon_Wire\" >Silicon Wire<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#Preliminary_Preparation\" >Preliminary Preparation<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#BH1750_Library\" >BH1750 Library<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#Wiring_Diagram\" >Wiring Diagram<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#Sketch\" >Sketch<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#bh1750ino\" >bh1750.ino<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#supplementary_explanation\" >supplementary explanation<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#setup\" >setup()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#lightMetersetMTreg69\" >lightMeter.setMTreg(69)<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.souichi.club\/en\/m5stack\/bh1750\/#Execution_Result\" >Execution Result<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"BH1750FVI\"><\/span>BH1750FVI<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Article on the measurement of illuminance with the ESP-WROOM-32 module using the GY-302, a modularized illuminance sensor (BH1750FVI) from ROHM Co.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-04.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-04.jpg?resize=214%2C252&#038;ssl=1\" alt=\"BH1750FVI surface\" class=\"wp-image-25036\" width=\"214\" height=\"252\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-04.jpg?w=854&amp;ssl=1 854w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-04.jpg?resize=768%2C907&amp;ssl=1 768w\" sizes=\"auto, (max-width: 214px) 100vw, 214px\" \/><\/a><\/figure>\n\n\n\n<p>The GY-302 has the following features<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Interface: I2C<\/li><li>I2C Address: 0x23 or 0x5C<\/li><li>Illuminance: 0.11 to 100,000 lux<\/li><li>Voltage: 3.0 to 5.0 V (3.3 V was used in this case)<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Measurement_Mode\"><\/span>Measurement Mode<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>There are three modes of measurement as follows<\/p>\n\n\n<figure class=\"wp-block-table is-style-regular\">\n<table class=\"r_table01\">\n<tbody>\n<tr>\n<td class=\"r_td30\">\n<p>H-Resolution Mode<\/p>\n<\/td>\n<td>\n<p>High resolution mode<\/p>\n<ul>\n<li><span style=\"font-size: revert; font-family: inherit; font-weight: inherit; color: initial;\">Measurement time: 120 ms<\/span><\/li>\n<li>Resolution: 1 lux<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>H-Resolution Mode2<\/p>\n<\/td>\n<td>\n<p>High resolution mode 2<\/p>\n<ul>\n<li>Measurement time: 120 ms<\/li>\n<li>Resolution: 0.5 lux<\/li>\n<\/ul>\n<p>Measurement time is the same as in high-resolution mode, but the measurable range is different (see below)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>L-Resolution Mode<\/p>\n<\/td>\n<td>\n<p>Low resolution mode<\/p>\n<ul>\n<li>Measurement time: 16 ms<\/li>\n<li>Resolution: 4 lux<\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p>In addition to the above modes, there are two other modes, Continuously and One Time, so there are 3 x 2 = 6 possible combinations.<\/p>\n\n\n<figure class=\"wp-block-table is-style-regular\">\n<table class=\"r_table01\">\n<tbody>\n<tr>\n<td class=\"r_td30\">\n<p>Continuously<\/p>\n<\/td>\n<td>\n<p>Used for continuous measurement<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>One Time<\/p>\n<\/td>\n<td>\n<p>One time<\/p>\n<p>Automatically enters power-down mode after measurement is complete<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"MTReg\"><\/span>MTReg<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The sensor sensitivity can be adjusted with the register that adjusts the measurement time.<\/p>\n\n\n\n<p>The default setting is 69, with a range of 31 to 254.<\/p>\n\n\n\n<p>A higher value (254) will increase the measurement time and allow for finer sensitivity, but will lower the maximum measurable illuminance.<\/p>\n\n\n\n<p>In H-Resolution Mode, the maximum illuminance is 14,836 lux, and in Mode 2, the maximum illuminance is 7,418 lux, which is half of the maximum, making it unsuitable for outdoor measurements.<\/p>\n\n\n\n<p>On the other hand, indoors, there was no problem with the default setting of 69.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Calculation_Formula\"><\/span>Calculation Formula<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>The following is a description of the calculation formulas performed inside the library.<\/p>\n\n\n\n<p>In H-Resolution Mode and Mode2, the sensitivity is calculated by the following formula.<\/p>\n\n\n<pre><code class=\"lang-shell\">H-reslution mode : Illuminance per 1 count ( lx \/ count ) = 1 \/ 1.2 *( 69 \/ X )\nH-reslution mode2 : Illuminance per 1 count ( lx \/ count ) = 1 \/ 1.2 *( 69 \/ X ) \/ 2<\/code><\/pre>\n\n\n<p>X : MTreg value<\/p>\n\n\n\n<p>Ex.)<\/p>\n\n\n\n<p>When X (MTreg) is 254 in H-Resolution Mode<\/p>\n\n\n<pre><code class=\"lang-shell\">1 \/ 1.2 *( 69 \/ 254 ) = 0.2263\u30fb\u30fb\u30fb \u2252 0.23\n<\/code><\/pre>\n\n\n<p>Measured in 0.23 lux units. (Half of that when Mode 2 is selected)<\/p>\n\n\n\n<p>The same formula is used to calculate the unit of 1.85 lux when MTreg is 31.<\/p>\n\n\n\n<p>The value measured by the sensor is returned in High Byte and Low Byte as shown below (<a href=\"https:\/\/docs.rs-online.com\/f199\/0900766b81539909.pdf\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"quoted from BH1750FVI datasheet\">quoted from BH1750FVI datasheet<\/a>).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-05.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-05.png?resize=646%2C257&#038;ssl=1\" alt=\"Calculation method of measurement results\" class=\"wp-image-25050\" width=\"646\" height=\"257\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-05.png?w=861&amp;ssl=1 861w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-05.png?resize=768%2C305&amp;ssl=1 768w\" sizes=\"auto, (max-width: 646px) 100vw, 646px\" \/><\/a><\/figure>\n\n\n\n<p>The powers of 2 where the bit is 1 are added together and divided by 1.2 (fixed).<\/p>\n\n\n\n<p>The above ex) is a calculation example when MTreg is set to the default value of 69, but if all bits are set to 1 and MTreg is set to 254, the calculation formula for H-Resolution Mode is as follows<\/p>\n\n\n<pre><code class=\"lang-shell\">(2^15 + 2^14 + 2^13 + 2^12 + 2^11 + 2^10 + 2^9 + 2^8 + 2^7 + 2^6 + 2^5 + 2^4 + 2^3 + 2^2 + 2^1 + 2^0) \/ 1.2 *( 69 \/ 254 ) = 14835.67913\u30fb\u30fb\u30fb \u2252 14,836<\/code><\/pre>\n\n\n<p>The above formula indicates that a maximum of 14,836 lux can be measured.<\/p>\n\n\n\n<p>In Mode 2, the maximum measurable illuminance is about 7,400 lux, which is half of the maximum measurable illuminance. Therefore, care should be taken when measuring illuminance in bright places with high sensitivity.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Connectors\"><\/span>Connectors<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The following five connectors are available.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>VCC: 3 to 5V<\/li><li>GND: GND<\/li><li>SCL: I2C connection<\/li><li>SDA: Same as above<\/li><li>ADDR: For I2C address change<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-05.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-05.jpg?resize=243%2C176&#038;ssl=1\" alt=\"Back side of BH1750\" class=\"wp-image-25038\" width=\"243\" height=\"176\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-05.jpg?w=973&amp;ssl=1 973w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-05.jpg?resize=768%2C556&amp;ssl=1 768w\" sizes=\"auto, (max-width: 243px) 100vw, 243px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"I2C_Address\"><\/span>I2C Address<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>When ADDR is connected LOW (0.3V or lower), the value is 0x23; when ADDR is connected HIGH (0.7V or higher), the value is 0x5C.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Other_Parts\"><\/span>Other Parts<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Other major parts prepared are as follows.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"ESP32_module\"><\/span>ESP32 module<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Various ESP32 modules are available on the market, but the ESP-WROOM-32 module we used this time is from the following product.<\/p>\n\n\n\n<p>The pin layout is the pin <a href=\"https:\/\/www.souichi.club\/en\/m5stack\/esp32-pin-layout\/#ESP32_DEVKIT_V1\" target=\"_blank\" rel=\"noreferrer noopener\" title=\"layout of ESP32 DEVKIT V1 (30 pins)\">layout of ESP32 DEVKIT V1 (30 pins)<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-01.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-01.jpg?resize=480%2C294&#038;ssl=1\" alt=\"ESP32 Dev Kit V1\" class=\"wp-image-25170\" width=\"480\" height=\"294\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-01.jpg?w=1920&amp;ssl=1 1920w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-01.jpg?resize=768%2C470&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-01.jpg?resize=1536%2C941&amp;ssl=1 1536w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Silicon_Wire\"><\/span>Silicon Wire<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Recently purchased silicon wire (24 AWG)<\/p>\n\n\n\n<p>Silicon is soft and very comfortable to use.<\/p>\n\n\n\n<p>The temperature range of -60 to +200 C is also very nice.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-02.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-02.jpg?resize=480%2C325&#038;ssl=1\" alt=\"Silicon Wire\" class=\"wp-image-25174\" width=\"480\" height=\"325\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-02.jpg?w=1920&amp;ssl=1 1920w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-02.jpg?resize=768%2C520&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-02.jpg?resize=1536%2C1039&amp;ssl=1 1536w\" sizes=\"auto, (max-width: 480px) 100vw, 480px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Preliminary_Preparation\"><\/span>Preliminary Preparation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Arduino IDE (Ver 1.8.19) was used as the development environment.<\/p>\n\n\n\n<p>Please <a href=\"https:\/\/www.souichi.club\/en\/m5stack\/m5stickc\/#Download_the_Arduino_IDE\" target=\"_blank\" rel=\"noreferrer noopener\">refer to this article<\/a> for downloading and installing Arduino IDE.<\/p>\n\n\n\n<p>Install the necessary libraries in advance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"BH1750_Library\"><\/span>BH1750 Library<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p><br>Start the Arduino IDE and launch the Library Manager by going to Sketch-&gt;Include Library-&gt;Manage Libraries.<\/p>\n\n\n\n<p>Type &#8220;BH1750&#8221; in the search field to search and installed the library that appears at the top of the list.<\/p>\n\n\n\n<p>Github <a href=\"https:\/\/github.com\/claws\/BH1750\" target=\"_blank\" rel=\"noreferrer noopener\">is here<\/a>.<\/p>\n\n\n\n<p>This library does the calculations I just described internally, so all I need to do from the sketch is to call the function that reads the MTreg set and the illuminance.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-03.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-03.png?resize=588%2C332&#038;ssl=1\" alt=\"Search the BH1750 library\" class=\"wp-image-25175\" width=\"588\" height=\"332\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-03.png?w=784&amp;ssl=1 784w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-03.png?resize=768%2C434&amp;ssl=1 768w\" sizes=\"auto, (max-width: 588px) 100vw, 588px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Wiring_Diagram\"><\/span>Wiring Diagram<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The wiring diagram is as follows.<\/p>\n\n\n\n<p>ADDR is connected to GND, so the I2C address is 0x23.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-04.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-04.png?resize=829%2C540&#038;ssl=1\" alt=\"Wiring diagram between BH1750FVI and ESP-WROOM-32\" class=\"wp-image-25179\" width=\"829\" height=\"540\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-04.png?w=1658&amp;ssl=1 1658w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-04.png?resize=768%2C500&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-04.png?resize=1536%2C1001&amp;ssl=1 1536w\" sizes=\"auto, (max-width: 829px) 100vw, 829px\" \/><\/a><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Sketch\"><\/span>Sketch<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The following is a sketch of the illuminance measured and displayed on the console approximately every 10 seconds.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"bh1750ino\"><\/span>bh1750.ino<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n<pre class=\"line-numbers\"><code class=\"lang-cpp\">\/*\n * BH1750 test\n * \n*\/\n#include &lt;Wire.h&gt;\n#include &lt;BH1750.h&gt;\n\n\/\/ I2C Pin\nconstexpr short int SDA_PIN = 21;\nconstexpr short int SCL_PIN = 22;\n\nBH1750 lightMeter(0x23);\n\nfloat lux;\n\nvoid setup() {\n    Serial.begin(115200);\n    Wire.begin(SDA_PIN, SCL_PIN); \/\/ I2C\n\n    \/*\n     * 6 Mode\n     *   CONTINUOUS_HIGH_RES_MODE\n     *   CONTINUOUS_HIGH_RES_MODE_2\n     *   CONTINUOUS_LOW_RES_MODE\n     *   ONE_TIME_HIGH_RES_MODE\n     *   ONE_TIME_HIGH_RES_MODE_2\n     *   ONE_TIME_LOW_RES_MODE\n     *   \n     *\/\n    lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE_2);\n}\n\nvoid loop() {\n    if (lightMeter.measurementReady(true)) {\n        if (lightMeter.setMTreg(69)) { \/\/ set MTreg(Measurement Time)\n            Serial.println(\"MTreg Normal Setting(69)\");\n        } else {\n            Serial.println(\"MTreg setting error\");\n        }\n        delay(500);\n        lux = lightMeter.readLightLevel();\n        \n        Serial.print(\"Light: \");\n        Serial.print(lux);\n        Serial.println(\" lx\");\n    } else {\n        Serial.println(F(\"--------------------------------------\"));\n    }\n    delay(10000);\n}<\/code><\/pre>\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"supplementary_explanation\"><\/span>supplementary explanation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"setup\"><\/span>setup()<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Initial processing of I2C connection and initial processing of BH1750FVI.<\/p>\n\n\n\n<p>The following six modes can be set.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>CONTINUOUS_HIGH_RES_MODE<\/li><li>CONTINUOUS_HIGH_RES_MODE_2<\/li><li>CONTINUOUS_LOW_RES_MODE<\/li><li>ONE_TIME_HIGH_RES_MODE<\/li><li>ONE_TIME_HIGH_RES_MODE_2<\/li><li>ONE_TIME_LOW_RES_MODE<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"lightMetersetMTreg69\"><\/span>lightMeter.setMTreg(69)<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>MTreg is set to the standard 69.<\/p>\n\n\n\n<p>The above sketch is an example of a single measurement with standard settings, but if you want to measure as accurately as possible in high-resolution mode from very bright to very dark locations, you can use the<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Set MTreg to 69 and measure in high resolution mode 2<\/li><li>If the measurement result is less than 10 lux, go to 4.<\/li><li>If the result is more than 5,000 lux, go to 5. Otherwise, go to 6.<\/li><li>If MTreg is set to 254, go to 7.<\/li><li>Set MTreg to 32 and go to 7.<\/li><li>Set MTreg to 69 and go to 7.<\/li><li>Measure again in High Resolution 2 mode<\/li><\/ol>\n\n\n\n<p>The measurement may be performed in two steps, such as<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Execution_Result\"><\/span>Execution Result<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The results are as follows.<\/p>\n\n\n\n<p>The measurement results are displayed on the console, and a high illuminance was measured when the sensor was illuminated by an LED light.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a class=\"r_image\" href=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-05.png?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-05.png?resize=848%2C347&#038;ssl=1\" alt=\"Execution Result\" class=\"wp-image-25182\" width=\"848\" height=\"347\" srcset=\"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-05.png?w=1131&amp;ssl=1 1131w, https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-en-05.png?resize=768%2C314&amp;ssl=1 768w\" sizes=\"auto, (max-width: 848px) 100vw, 848px\" \/><\/a><\/figure>\n\n\n\n<p>This concludes this article.<\/p>\n\n\n<div class=\"postscript_balloon\">Finally.<\/div>\n\n\n<p>I hope this article will be useful to someone somewhere.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Article on the measurement of illuminance with the ESP32-WROOM-32 module using ROHM&#8217;s GY-302, a modularized illuminance sensor (BH1750FVI).<\/p>\n","protected":false},"author":5,"featured_media":25068,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"en_US","_original_post":"https:\/\/www.souichi.club\/?p=25021","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[238],"tags":[],"class_list":["post-25151","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-m5stack","en-US"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.souichi.club\/wp-content\/uploads\/bh1750-08.jpg?fit=1920%2C1560&ssl=1","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/25151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/comments?post=25151"}],"version-history":[{"count":14,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/25151\/revisions"}],"predecessor-version":[{"id":25187,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/posts\/25151\/revisions\/25187"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/media\/25068"}],"wp:attachment":[{"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/media?parent=25151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/categories?post=25151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.souichi.club\/wp-json\/wp\/v2\/tags?post=25151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}