{"id":108856,"date":"2022-03-10T23:56:16","date_gmt":"2022-03-10T23:56:16","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=108856"},"modified":"2022-03-11T19:22:24","modified_gmt":"2022-03-11T19:22:24","slug":"arduino-bh1750-ambient-light-sensor","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/arduino-bh1750-ambient-light-sensor\/","title":{"rendered":"Arduino with BH1750 Ambient Light Sensor"},"content":{"rendered":"\n<p>The BH1750 is a 16-bit ambient light sensor. In this guide, you\u2019ll learn how to use the BH1750 ambient light sensor with the Arduino board. The sensor communicates with a microcontroller using I2C communication protocol.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BH1750-Ambient-Light-Sensor-Arduino.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino Board with BH1750 Ambient Light Sensor Arduino IDE\" class=\"wp-image-108857\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BH1750-Ambient-Light-Sensor-Arduino.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BH1750-Ambient-Light-Sensor-Arduino.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BH1750-Ambient-Light-Sensor-Arduino.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BH1750-Ambient-Light-Sensor-Arduino.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n\n<p>You\u2019ll learn how to wire the sensor to the Arduino board, install the required libraries and use a simple sketch to display the sensor readings in the Serial Monitor.<\/p>\n\n\n\n<p>This tutorial covers the following topics:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"#introducing-bh1750\">Introducing the BH1750 Ambient Light Sensor<\/a><\/li><li><a href=\"#bh1750-pinout\">BH1750 Pinout<\/a><\/li><li><a href=\"#bh1750-interface\">BH1750 I2C Interface<\/a><\/li><li><a href=\"#bh1750-esp8266-example\">Example: BH1750: Read Ambient Light with Arduino<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"introducing-bh1750\">Introducing BH1750 Ambient Light Sensor<\/h2>\n\n\n\n<p>The BH1750 is a 16-bit ambient light sensor that communicates via I2C protocol. It outputs luminosity measurements in lux (SI-derived unit of illuminance). It can measure a minimum of 1 lux and a maximum of 65535 lux. <\/p>\n\n\n\n<p>The sensor may come in different breakout board formats. See pictures below. Both images represent a BH1750 sensor.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"288\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BH1750-ambient-light-sensors.jpg?resize=750%2C288&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BH1750 Ambient Light Sensor Breakout Boards\" class=\"wp-image-108841\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BH1750-ambient-light-sensors.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BH1750-ambient-light-sensors.jpg?resize=300%2C115&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">BH1750 Features<\/h3>\n\n\n\n<p>Here&#8217;s a list of the BH1750 sensor features. For more information consult the <a href=\"https:\/\/datasheet.octopart.com\/BH1750FVI-TR-Rohm-datasheet-25365051.pdf\" target=\"_blank\" rel=\"noreferrer noopener\">BH1750 sensor datasheet<\/a>. <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>I2C bus Interface<\/li><li>Spectral responsibility is approximately human eye response<\/li><li>Illuminance to digital converter<\/li><li>Range: 1 &#8211; 65535 lux<\/li><li>Low current by power down function<\/li><li>50Hz \/ 60Hz Light noise reject-function<\/li><li>It is possible to select 2 different I2 C slave-addresses<\/li><li>Small measurement variation (+\/- 20%)<\/li><li>The influence of infrared is very small<\/li><li>Supports continuous measurement mode<\/li><li>Supports one-time measurement mode<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"measurement-modes\">Measurement Modes<\/h3>\n\n\n\n<p>The sensor supports two different measurement modes: <em>continuous measurement mode<\/em>, and <em>one-<\/em>time measurement mode. Each mode supports three different resolution modes.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Low Resolution Mode<\/strong><\/td><td>4 lux precision<\/td><td>16 ms measurement time<\/td><\/tr><tr><td><strong>High Resolution Mode<\/strong><\/td><td>1 lux precision<\/td><td>120 ms measurement time<\/td><\/tr><tr><td><strong>High Resolution Mode 2<\/strong><\/td><td>0.5 lux precision<\/td><td> 120 ms measurement time <\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>In continuous measurement mode, the sensor continuously measures ambient light values. In one-time measurement mode, the sensor measures the ambient light value once, and then it goes to power down mode.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Applications<\/strong><\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/02\/BH1750-Ambient-light-sensor-f.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BH1750 Ambient Light Sensor\" class=\"wp-image-109235\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/02\/BH1750-Ambient-light-sensor-f.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/02\/BH1750-Ambient-light-sensor-f.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>The BH1750 is an ambient light sensor so it can be used in a wide variety of projects. For example:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>to detect if it is day or night;<\/li><li>to adjust or turn on\/off LED&#8217;s brightness accordingly to ambient light;<\/li><li>to adjust LCDs and screen&#8217;s brightness;<\/li><li>to detect if an LED is lit;<\/li><li>&#8230;<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"bh1750-pinout\">BH1750 Pinout<\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/02\/BH1750-pinout.JPG.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BH1750 Ambient Light Sensor Pinout\" class=\"wp-image-109234\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/02\/BH1750-pinout.JPG.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/02\/BH1750-pinout.JPG.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>Here&#8217;s the BH1750 Pinout:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>VCC<\/strong><\/td><td>Powers the sensor (3.3V or 5V)<\/td><\/tr><tr><td><strong>GND<\/strong><\/td><td>Common GND<\/td><\/tr><tr><td><strong>SCL<\/strong><\/td><td>SCL pin for I2C communication<\/td><\/tr><tr><td><strong>SDA<\/strong> (Data)<\/td><td>SDA pin for I2C communication<\/td><\/tr><tr><td><strong>ADD<\/strong>*<\/td><td>Selects address<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The  ADD pin is used to set the I2C sensor address. If the voltage on that pin is less than 0.7VCC (pin is left floating or connected to GND), the I2C address is <span class=\"rnthl rntliteral\">0x23<\/span>. But, if the voltage is higher than 0.7xVCC (pin is connected to VCC), the address is <span class=\"rnthl rntliteral\">0x5C<\/span>. In summary:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>ADD pin floating or connected to <span class=\"rnthl rntcblack\">GND<\/span> \u2192 address: <span class=\"rnthl rntliteral\">0x23<\/span><\/li><li>ADD pin connected to <span class=\"rnthl rntcred\">VCC<\/span> \u2192 address: <span class=\"rnthl rntliteral\">0x5C<\/span><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"bh1750-interface\">BH1750 I2C Interface<\/h2>\n\n\n\n<p>The BH1750 ambient light sensor supports I2C interface.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"422\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/02\/Arduino-BH1750-f.jpg?resize=750%2C422&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino with BH1750 Ambient Light Sensor\" class=\"wp-image-109243\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/02\/Arduino-BH1750-f.jpg?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/02\/Arduino-BH1750-f.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n\n<p>You can connect the BH1750 sensor to the Arduino using the default&#8217;s I2C pins (these are the pins for the Arduino UNO, if you&#8217;re using another model, check its I2C pins):<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BH1750<\/strong><\/td><td><strong>Arduino<\/strong><\/td><\/tr><tr><td>SCL<\/td><td><span class=\"rnthl rntcyellow\">A5<\/span><\/td><\/tr><tr><td>SDA<\/td><td><span class=\"rnthl rntclgray\">A4<\/span><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">BH1750: Read Ambient Light with Arduino<\/h2>\n\n\n\n<p>Now that you are more familiar with the BH1750 sensor, let&#8217;s test it. In this section, we&#8217;ll build a simple project that reads the ambient light and displays it in the Arduino IDE Serial Monitor.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Parts Required<\/h3>\n\n\n\n<p>To complete this tutorial you need the following parts:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/makeradvisor.com\/tools\/bh1750-ambient-light-sensor\/\" target=\"_blank\" rel=\"noreferrer noopener\">BH1750 ambient light sensor<\/a><\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/compatible-arduino-uno-r3-board\/\" target=\"_blank\" rel=\"noreferrer noopener\">Arduino <\/a>(read <a href=\"https:\/\/makeradvisor.com\/best-arduino-starter-kits\/\" target=\"_blank\" rel=\"noreferrer noopener\">Best Arduino starter kits<\/a>)<\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/mb-102-solderless-breadboard-830-points\/\">Breadboard <\/a>(optional)<\/li><li><a href=\"https:\/\/makeradvisor.com\/tools\/jumper-wires-kit-120-pieces\/\">Jumper wires<\/a> (optional)<\/li><\/ul>\n\n\n<p>You can use the preceding links or go directly to <a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\">MakerAdvisor.com\/tools<\/a> to find all the parts for your projects at the best price!<\/p><p style=\"text-align:center;\"><a href=\"https:\/\/makeradvisor.com\/tools\/?utm_source=rnt&utm_medium=post&utm_campaign=post\" target=\"_blank\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2017\/10\/header-200.png?w=1200&#038;quality=100&#038;strip=all&#038;ssl=1\"><\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Schematic &#8211; Arduino with BH1750<\/h3>\n\n\n\n<p>Wire the BH1750 sensor to the Arduino I2C pins. You can follow the next schematic diagram.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"1016\" height=\"796\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/Arduino-BH1750-Wiring-Diagram.png?resize=1016%2C796&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino BH1750 Wiring Diagram\" class=\"wp-image-108860\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/Arduino-BH1750-Wiring-Diagram.png?w=1016&amp;quality=100&amp;strip=all&amp;ssl=1 1016w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/Arduino-BH1750-Wiring-Diagram.png?resize=300%2C235&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/Arduino-BH1750-Wiring-Diagram.png?resize=768%2C602&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1016px) 100vw, 1016px\" \/><\/figure><\/div>\n\n\n\n<p>You can also follow the next table:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>BH1750<\/strong><\/td><td><strong>Arduino<\/strong><\/td><\/tr><tr><td><strong>VCC<\/strong><\/td><td><span class=\"rnthl rntcred\">5V<\/span><\/td><\/tr><tr><td><strong>GND<\/strong><\/td><td><span class=\"rnthl rntcblack\">GND<\/span><\/td><\/tr><tr><td><strong>SCL<\/strong><\/td><td><span class=\"rnthl rntcyellow\">A5<\/span><\/td><\/tr><tr><td><strong>SDA<\/strong> (Data)<\/td><td><span class=\"rnthl rntclgray\">A4<\/span><\/td><\/tr><tr><td><strong>ADD<\/strong>*<\/td><td>Don&#8217;t connect<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>By not connecting the <strong>ADD <\/strong>pin, we&#8217;re selecting <span class=\"rnthl rntliteral\">0x23<\/span> I2C address. Connect it to 3.3V to select <span class=\"rnthl rntliteral\">0x5C<\/span> address instead.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing the BH1750 Library<\/h3>\n\n\n\n<p>There are several libraries to read from the BH1750 sensor. We&#8217;ll use the <a href=\"https:\/\/github.com\/claws\/BH1750\" target=\"_blank\" rel=\"noreferrer noopener\">BH1750 library by Christopher Laws<\/a>. It is compatible with the ESP32, ESP8266, and Arduino.<\/p>\n\n\n\n<p>Open your Arduino IDE and go to&nbsp;<strong>Sketch&nbsp;<\/strong>&gt;&nbsp;<strong>Include Library<\/strong>&nbsp;&gt;&nbsp;<strong>Manage Libraries<\/strong>. The Library Manager should open. <\/p>\n\n\n\n<p>Search for \u201c<strong>BH1750<\/strong>\u201d on the search box and install the <em>BH1750 library by Christopher Laws<\/em>.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"786\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BHT1750-Library-Arduino-IDE.png?resize=786%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"BHT1750 Library Arduino IDE\" class=\"wp-image-108821\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BHT1750-Library-Arduino-IDE.png?w=786&amp;quality=100&amp;strip=all&amp;ssl=1 786w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BHT1750-Library-Arduino-IDE.png?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BHT1750-Library-Arduino-IDE.png?resize=768%2C433&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 786px) 100vw, 786px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Code &#8211; Reading BH1750 Ambient Light Sensor<\/h2>\n\n\n\n<p>Copy the following code to your Arduino IDE. This code simply reads ambient light in lux and displays the values on the Serial Monitor. It is the example code from the library called <strong>BH1750test <\/strong>(you can access it in <strong>File <\/strong>&gt; <strong>Examples <\/strong>&gt; <strong>BH1750 <\/strong>&gt; <strong>BH1750test<\/strong><\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-c\">\/*\n  Example of BH1750 library usage. This example initialises the BH1750 object using the default high resolution continuous mode and then makes a light level reading every second.\n*\/\n\n#include &lt;Wire.h&gt;\n#include &lt;BH1750.h&gt;\n\nBH1750 lightMeter;\n\nvoid setup(){\n  Serial.begin(9600);\n\n  \/\/ Initialize the I2C bus (BH1750 library doesn't do this automatically)\n  Wire.begin();\n  \/\/ On esp8266 you can select SCL and SDA pins using Wire.begin(D4, D3);\n  \/\/ For Wemos \/ Lolin D1 Mini Pro and the Ambient Light shield use Wire.begin(D2, D1);\n\n  lightMeter.begin();\n\n  Serial.println(F(&quot;BH1750 Test begin&quot;));\n}\n\nvoid loop() {\n  float lux = lightMeter.readLightLevel();\n  Serial.print(&quot;Light: &quot;);\n  Serial.print(lux);\n  Serial.println(&quot; lx&quot;);\n  delay(1000);\n}\n<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Random-Nerd-Tutorials\/raw\/master\/Projects\/Arduino\/BH1750test.ino\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>The library also provides other examples worth exploring.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Code Works<\/h2>\n\n\n\n<p>We start by including the required libraries. The <span class=\"rnthl rntliteral\">Wire.h<\/span> library to use I2C communication protocol and the <span class=\"rnthl rntliteral\">BH1750.h<\/span> library to read from the sensor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>#include &lt;Wire.h&gt;\n#include &lt;BH1750.h&gt;<\/code><\/pre>\n\n\n\n<p>Then, we create a <span class=\"rnthl rntliteral\">BH1750<\/span> object called <span class=\"rnthl rntliteral\">lightMeter<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>BH1750 lightMeter;<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">setup()<\/span>, initialize the Serial Monitor at a baud rate of 9600.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.begin(9600);<\/code><\/pre>\n\n\n\n<p>Initialize I2C communication protocol. It will start an I2C communication on the microcontroller&#8217;s default I2C pins. If you want to use different I2C pins, pass them to the <span class=\"rnthl rntliteral\">begin()<\/span> method like this <span class=\"rnthl rntliteral\">Wire.begin(SDA, SCL)<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Wire.begin();<\/code><\/pre>\n\n\n\n<p>Initialize the sensor using the <span class=\"rnthl rntliteral\">begin()<\/span> method on the <span class=\"rnthl rntliteral\">BH1750<\/span> object (<span class=\"rnthl rntliteral\">lightMeter<\/span>).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>lightMeter.begin();<\/code><\/pre>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\">loop()<\/span>, we create a variable called <span class=\"rnthl rntliteral\">lux<\/span>, that saves the luminance values. To get the value, you simply call the <span class=\"rnthl rntliteral\">readLightLevel()<\/span> function on the <span class=\"rnthl rntliteral\">BH1750<\/span> object (<span class=\"rnthl rntliteral\">lightMeter<\/span>).<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>float lux = lightMeter.readLightLevel();<\/code><\/pre>\n\n\n\n<p>Finally, display the measurement on the Serial Monitor.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>Serial.print(\"Light: \");\nSerial.print(lux);\nSerial.println(\" lx\");<\/code><\/pre>\n\n\n\n<p>You get and print a new reading every second.<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>delay(1000);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>Now, you can upload the code to your board. First, connect your board to your computer. Then, go to <strong>Tools <\/strong>> <strong>Board <\/strong>and select the Arduino board you&#8217;re using. Go to <strong>Tools <\/strong>> <strong>Port <\/strong>and select the COM port your board is connected to. Finally, click on the upload button.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"30\" height=\"30\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/05\/arduino-2-0-upload-button.png?resize=30%2C30&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino 2.0 Upload Button\" class=\"wp-image-103678\"\/><\/figure><\/div>\n\n\n\n<p>After successfully uploading the code, open the Serial Monitor at a <u>baud rate of 9600<\/u>.<\/p>\n\n\n\n<p>New luminance readings should be printed in the Serial Monitor.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"601\" height=\"461\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BH1750-readings-serial-monitor.png?resize=601%2C461&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Arduino Board with BH1750 Ambient Light Sensor Arduino IDE Demonstration\" class=\"wp-image-108824\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BH1750-readings-serial-monitor.png?w=601&amp;quality=100&amp;strip=all&amp;ssl=1 601w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BH1750-readings-serial-monitor.png?resize=300%2C230&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 601px) 100vw, 601px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Other Useful Functions<\/h2>\n\n\n\n<p>The library we&#8217;re using with the BH1750 sensor provides other examples that illustrate other useful functions and features. You can <a href=\"https:\/\/github.com\/claws\/BH1750\/tree\/master\/examples\" target=\"_blank\" rel=\"noreferrer noopener\">check all BH1750 library examples here<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Setting Measurement Mode<\/h3>\n\n\n\n<p>By default, the library uses the continuous high resolution measurement mode, but you can change it by passing the desired measurement mode to the begin() method when initializing the sensor. For example:<\/p>\n\n\n\n<pre class=\"wp-block-code language-c\"><code>lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)<\/code><\/pre>\n\n\n\n<p>Here&#8217;s a list of all available modes:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><span class=\"rnthl rntliteral\">BH1750_CONTINUOUS_LOW_RES_MODE<\/span><\/li><li><span class=\"rnthl rntliteral\">BH1750_CONTINUOUS_HIGH_RES_MODE<\/span> (default)<\/li><li><span class=\"rnthl rntliteral\">BH1750_CONTINUOUS_HIGH_RES_MODE_2<\/span><\/li><li><span class=\"rnthl rntliteral\">BH1750_ONE_TIME_LOW_RES_MODE<\/span><\/li><li><span class=\"rnthl rntliteral\">BH1750_ONE_TIME_HIGH_RES_MODE<\/span><\/li><li><span class=\"rnthl rntliteral\">BH1750_ONE_TIME_HIGH_RES_MODE_2<\/span><\/li><\/ul>\n\n\n\n<p>See the properties of each mode in <a href=\"#measurement-modes\">this previous section<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you&#8217;ve learned how to use the BH1750 ambient light sensor with the Arduino Uno. The sensor is very easy to use. It uses I2C communication protocol, which makes wiring simple, and the library provides methods to easily get the readings.<\/p>\n\n\n\n<p>We hope you found this tutorial useful. Tell us in the comments below in which project would you use the BH1750 sensor.<\/p>\n\n\n\n<p>We have tutorials for other sensors with the Arduino board that you may like:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/randomnerdtutorials.com\/arduino-bmp388\/\">Arduino with BMP388: <strong>Altimeter Sensor<\/strong><\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-ds18b20-temperature-sensor-with-arduino\/\">Arduino with DS18B20: <strong>Temperature Sensor<\/strong><\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/bme680-sensor-arduino-gas-temperature-humidity-pressure\/\">Arduino with BME680: <strong>Gas, Pressure, Humidity, and Temperature<\/strong> <strong>Sensor<\/strong><\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/bme280-sensor-arduino-pressure-temperature-humidity\/\">Arduino with BME280: <strong>Temperature, Humidity, and Pressure Sensor<\/strong><\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/complete-guide-for-dht11dht22-humidity-and-temperature-sensor-with-arduino\/\">Arduino DHT11\/DHT22: <strong>Temperature, and Humidity Sensor<\/strong><\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/complete-guide-for-ultrasonic-sensor-hc-sr04\/\">Arduino HC-SR04: <strong>Ultrasonic Distance Sensor<\/strong><\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/arduino-with-pir-motion-sensor\/\">Arduino PIR: <strong>Motion Sensor<\/strong><\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/guide-for-bmp180-barometric-sensor-with-arduino\/\">Arduino BMP180: <strong>Pressure Sensor<\/strong><\/a><\/li><li><a href=\"https:\/\/randomnerdtutorials.com\/arduino-lm35-lm335-lm34-temperature-sensor\/\">Arduino LM35: <strong>Temperature Sensor<\/strong><\/a><\/li><\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The BH1750 is a 16-bit ambient light sensor. In this guide, you\u2019ll learn how to use the BH1750 ambient light sensor with the Arduino board. The sensor communicates with a &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"Arduino with BH1750 Ambient Light Sensor\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/arduino-bh1750-ambient-light-sensor\/#more-108856\" aria-label=\"Read more about Arduino with BH1750 Ambient Light Sensor\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":108857,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[303,267,2,302,245,264],"tags":[],"class_list":["post-108856","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-0-arduino","category-arduino-project","category-arduino","category-0-guide","category-arduino-ide","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/BH1750-Ambient-Light-Sensor-Arduino.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/108856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=108856"}],"version-history":[{"count":6,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/108856\/revisions"}],"predecessor-version":[{"id":109800,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/108856\/revisions\/109800"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/108857"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=108856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=108856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=108856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}