{"id":9543,"date":"2020-11-14T11:02:54","date_gmt":"2020-11-14T11:02:54","guid":{"rendered":"https:\/\/wolles-elektronikkiste.de\/si1145-als-ir-uv-und-ps-sensor"},"modified":"2021-05-16T08:39:13","modified_gmt":"2021-05-16T08:39:13","slug":"si1145-als-ir-uv-und-ps-sensor","status":"publish","type":"post","link":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor","title":{"rendered":"SI1145 ALS, IR, UV and PS sensor"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">About this post<\/h2>\n<p>I had already reported about the SI1145 in <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/uv-sensors-and-sensor-modules?lang=en\" target=\"_blank\" rel=\"noopener noreferrer\">my last post<\/a> about UV sensors. However, the SI1145 can do much more, namely ambient (ALS\/VIS) and infrared light (ALS\/IR) measurements, and you can also use it as a proximity sensor (PS). Unfortunately, I couldn&#8217;t find a library that would make all these options accessible with the associated settings. That&#8217;s why I wrote a library myself (SI1145_WE), which you can find <a href=\"https:\/\/github.com\/wollewald\/SI1145_WE\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a> on Github. Or you can install it through library management in the Arduino IDE.<\/p>\r\n\r\n<p>I would like to introduce the library in this post, but I will discuss the properties of the SI1145 (module) beforehand. The post has become very long &#8211; but that reflects that the SI1145 is a complex device. If you&#8217;re too bored, go to the library right away. But with more background knowledge, it is easier to understand.<\/p>\n<h2 class=\"wp-block-heading\">Features of the SI1145<\/h2>\n\n<h3 class=\"wp-block-heading\">Key technical data<\/h3>\n<ul>\r\n \t<li><strong>Distance measurement<\/strong> from 1 cm to &gt; 50 cm<\/li>\r\n \t<li><strong>Light measurement<\/strong> from 1 to 128000 Lux<\/li>\r\n \t<li><strong>Power consumption<\/strong> in the microampere range\r\n<ul>\r\n \t<li>&lt;500 Nanoamperes on standby<\/li>\r\n<\/ul>\r\n<\/li>\r\n \t<li><strong>Supply voltage:<\/strong>1.71 &#8211; 3.6 volts\r\n<ul>\r\n \t<li>for modules mostly 3 &#8211; 5 volts<\/li>\r\n<\/ul>\r\n<\/li>\r\n \t<li><strong>Communication<\/strong> via I2C\r\n<ul>\r\n \t<li>Address: 0x60 specified, adjustable via register<\/li>\r\n<\/ul>\r\n<\/li>\r\n<\/ul>\n<h3 class=\"wp-block-heading\">Ambient light measurements (ALS VIS\/IR)<\/h3>\n\n<h4 class=\"wp-block-heading\">Measuring principle \/ procedure<\/h4>\n<p>The SI1145 has one photodiode for the visible and two photodiodes for the infrared spectrum. The two IR photodiodes differ in their size and thus in their sensitivity. They have two tasks. On the one hand, they are used for correction in ambient light measurement because this interferes with the proportion of infrared light. On the other hand, they serve as detectors for distance measurements. You can choose which IR photodiode you assign to which function. For example, one will work in direct sunlight with the small diode, since the large diode will overflow under these conditions (or the downstream A\/D converter).<\/p>\r\n\r\n<p>The VIS and IR measurements take place one after the other. The SI1145 is very fast. Typically, a VIS\/IR measurement in a double pack takes only 285 microseconds.<\/p>\r\n\r\n<p>The SI1145 stores the results of the measurements in the 16-bit data registers (2 x 8 bits each to be exact) for the visible and infrared range. These raw data have to be processed further, for example to calculate the light intensity in lux.<\/p>\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/spectral_response_si1145.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/spectral_response_si1145.png\" alt=\"Taken from the data sheet of the SI1145: sensitivity of the photodiodes vs. wavelength\" class=\"wp-image-8222\" width=\"580\" height=\"392\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/spectral_response_si1145.png 967w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/spectral_response_si1145-300x203.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/spectral_response_si1145-768x520.png 768w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><figcaption>Taken from the data sheet: sensitivity of the photodiodes vs. wavelength<\/figcaption><\/figure><\/div>\n\n<h4 class=\"wp-block-heading\">Settings<\/h4>\n<p>For the VIS and IR measurements, the measurement time (gain, integration time) can be set. You can choose a factor between 1 and 128. The measuring time is then 25.6 \u00b5s x 2^GAIN with GAIN = 0 to 7. For particularly strong light, the SI1145 offers a &#8220;High Signal Range Mode&#8221; corresponding to a gain factor of 1\/14.5.<\/p>\r\n\r\n<p>In addition, you can (theoretically) set the minimum regeneration time for the A\/D converter before performing the next measurement. However, I adhered to the data sheet recommendation in my library and implemented a gain-dependent algorithm.<\/p>\r\n\r\n<p>The A\/D converter has an unusual resolution of 17 bits. By default, the top 16 bits are transferred to the data registers. You can also use the lower 16 bits. This doubles the resolution, but halves the upper limit accordingly.<\/p>\r\n\r\n<p>The provision of the measured values in the data register can be indicated by an interrupt.\n<h4 class=\"wp-block-heading\">Lux calculations<\/h4>\n<p>Getting reliable lux values out of light sensors is generally a science in itself because:<\/p>\r\n<ul>\r\n \t<li>The photodiodes for the visible area are influenced by the infrared light.<\/li>\r\n \t<li>Within the visible range, the photodiodes have different sensitivities depending on the wavelength and thus respond differently to different light sources (sunlight, incandescent lamp, LED (cold\/white), halogen, etc.).<\/li>\r\n<\/ul>\r\n<p>The problem related with infrared light can be solved by additional sensors which subtract the proportion of infrared light.<\/p>\r\n\r\n<p>The problem of sensor characteristics, on the other hand, can only be solved by calibrating to different light sources. Even commercially available light sensors have this problem. Often they are calibrated to light bulbs, which is hardly to be found.<\/p>\r\n\r\n<p>Here is an example of two light sensors, which differ 5% for incandescent light according to my &lt; measurements. On the other hand, the results with overcast sky (i.e. cold light) differ by about 40% in relation to the lower value:<\/p>\n<figure class=\"wp-block-image\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Luxmeter.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Luxmeter-1024x768.jpg\" alt=\"Two light sensors measuring with overcast skay: 5200 vs. 7255 Lux\" class=\"wp-image-3791\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Luxmeter-1024x768.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Luxmeter-300x225.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Luxmeter-768x576.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Luxmeter-1320x990.jpg 1320w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Luxmeter.jpg 1903w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>Two light sensors measuring with overcast skay: 5200 vs. 7255 Lux<\/figcaption><\/figure><p>Considering this, one should perhaps reduce one&#8217;s expectations on the exactness of self-built light sensors a little. But at least you should be aware that exact measurements involve a certain amount of effort.<\/p>\r\n\r\n<p>The whole thing becomes even more complex when you use the SI1145 under covers that absorb a certain amount of visible and infrared light.<\/p>\n<h4 class=\"wp-block-heading\">Calculation formula for the SI1145<\/h4>\n<p>In the Application Notes <a href=\"https:\/\/www.silabs.com\/documents\/public\/application-notes\/AN523.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">AN523<\/a> (Overlay considerations for the Si114X sensor) I found the following formula for lux calculation on page 3:<\/p>\n<figure class=\"wp-block-image\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/lux_formel.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1006\" height=\"64\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/lux_formel.png\" alt=\"\" class=\"wp-image-8226\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/lux_formel.png 1006w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/lux_formel-300x19.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/lux_formel-768x49.png 768w\" sizes=\"auto, (max-width: 1006px) 100vw, 1006px\" \/><\/a><\/figure><p>The two coefficients in case no coverage is used can be found on the next page of application notes AN523:<\/p>\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Koeffizienten.png\"><img loading=\"lazy\" decoding=\"async\" width=\"771\" height=\"175\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Koeffizienten.png\" alt=\"\" class=\"wp-image-8227\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Koeffizienten.png 771w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Koeffizienten-300x68.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Koeffizienten-768x174.png 768w\" sizes=\"auto, (max-width: 771px) 100vw, 771px\" \/><\/a><figcaption>Coefficients for the lux calculation for the SI1145<\/figcaption><\/figure><\/div>\n<p>The ALS \/ ALSIR values in the above equation are the values read from the sensor at current light or in the dark (&#8220;dark reading&#8221;). The dark values must be determined once. However, the formula applies only to the following boundary conditions:<\/p>\r\n<ul>\r\n \t<li>IR and VIS gain = 0<\/li>\r\n \t<li>Normal signal range<\/li>\r\n \t<li>Use of the small IR photodiode.<\/li>\r\n<\/ul>\r\n<p>If you deviate from this, you have to apply correction factors.<\/p>\r\n\r\n<p>With this formula, I achieved results that were within the range of the results of my commercial light sensor. From my point of view, however, there would still have to be a weighting by the count-per-lux factors (see <a href=\"https:\/\/www.silabs.com\/documents\/public\/data-sheets\/Si1145-46-47.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">data sheet<\/a>, p. 6-7). In my example sketch SI1145_lux_calculation I therefore offered an alternative in addition to the standard formula.<\/p>\r\n\r\n<p>If you want to get more into this topic, you should read the <a href=\"https:\/\/www.silabs.com\/documents\/public\/application-notes\/AN576.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">AN576<\/a> and the <a href=\"https:\/\/www.silabs.com\/documents\/public\/application-notes\/AN498.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">AN498<\/a> in addition to the <a href=\"https:\/\/www.silabs.com\/documents\/public\/application-notes\/AN523.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">AN523.<\/a> I have focused more on mastering the SI1145 than on the subsequent processing of the raw data. Therefore, and because the lux calculation can be adjusted very individually, I did not implement it in the library itself.<\/p>\n<h3 class=\"wp-block-heading\">Distance measurements (PS)<\/h3>\n\n<h4 class=\"wp-block-heading\">Measuring principle \/ procedure<\/h4>\n<p>The SI1145 does not have an integrated IR LED. You have to connect them separately to the LED pin (with the minus pole to the sensor by the way). The &#8220;bigger brothers&#8221; SI1146 and SI1147 even offer the option to connect two or three IR LEDs and perform separate PS measurements. Unfortunately, they do not exist as a module.<\/p>\r\n\r\n<p>The minimum pulse duration for the IR LED is 25.6 microseconds. Depending on the setting, the radiation reflected by objects is detected by the large or small IR photodiode. Within a measurement cycle, the SI1145 always performs the PS measurement first and then the VIS\/IR measurements.<\/p>\r\n\r\n<p>The results of the PS measurements can be found in the 16-bit PS data register.<\/p>\n<h4 class=\"wp-block-heading\">Settings<\/h4>\n<p>For PS measurements, the SI1145 allows the following settings:<\/p>\r\n<ul>\r\n \t<li>LED pulse width (gain): Factor 1 to 32<\/li>\r\n \t<li>LED current: from 5.6 to 360 mA<\/li>\r\n \t<li>High Signal Range Mode (as with ALS measurements)<\/li>\r\n \t<li>Selecting the top or lower 16 bits of the A\/D converter<\/li>\r\n \t<li>(Regeneration time: again I followed the data sheet recommendations &#8211;&gt; automatic setting with my library)<\/li>\r\n \t<li>Interrupt when providing the measurement result<\/li>\r\n<\/ul>\n<h3 class=\"wp-block-heading\">UV index measurements<\/h3>\n<p>Here I refer again to <a href=\"https:\/\/wolles-elektronikkiste.de\/en\/uv-sensors-and-sensor-modules\" target=\"_blank\" rel=\"noopener noreferrer\">my last post<\/a>. I would just like to stress once again that there is no real UV radiation measurement, but the data from the VIS\/IR data are extrapolated. The UV index data is stored in the corresponding data register. The UV index determination completes a measurement cycle.<\/p>\n<h3 class=\"wp-block-heading\">General settings<\/h3>\n<p>In addition to the already listed special settings, there are a few general settings:<\/p>\r\n<ul>\r\n \t<li>Continuous or single-shot (forced) mode<\/li>\r\n \t<li>Measurement rate: the SI1145 enters sleep mode after a measurement and wakes up periodically. The measurement rate determines after how many sleep periods a measurement is performed.<\/li>\r\n \t<li>Query for overflows of the A\/D converter in case of too strong light or too high gain<\/li>\r\n<\/ul>\n<h2 class=\"wp-block-heading\">SI1145 modules<\/h2>\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/10\/SI1145__Sensoren_Klein.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"365\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/10\/SI1145__Sensoren_Klein-1024x365.jpg\" alt=\"SI1145 modules\" class=\"wp-image-3646\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/10\/SI1145__Sensoren_Klein-1024x365.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/10\/SI1145__Sensoren_Klein-300x107.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/10\/SI1145__Sensoren_Klein-768x274.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/10\/SI1145__Sensoren_Klein-1320x470.jpg 1320w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>Two examples of SI1145 modules<\/figcaption><\/figure><p>SI1145 modules are available in various versions, e.g. on <a href=\"https:\/\/smile.amazon.de\/s?k=SI1145&amp;__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&amp;ref=nb_sb_noss\" target=\"_blank\" rel=\"noopener noreferrer\">Amazon<\/a> or <a href=\"https:\/\/www.ebay.de\/sch\/i.html?_from=R40&amp;_trksid=m570.l1313&amp;_nkw=SI1145&amp;_sacat=0\" target=\"_blank\" rel=\"noopener noreferrer\">eBay.<\/a> The price range is quite large with approx. 5 to 22 euros depending on the shop. Most modules have voltage control, so you can operate them between 3 and 5 volts. SDA, SCL and INT seem to have pull-up resistors, so you don&#8217;t have to worry about it. In any case, this applies to the modules I have tried.<\/p>\n<h2 class=\"wp-block-heading\">The SI1145_WE Library<\/h2>\n<p>Now to the library. You can find it <a href=\"https:\/\/github.com\/wollewald\/SI1145_WE\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a> on Github, along with the six example sketches that I&#8217;ll introduce in a moment. I have made most of the setting options accessible. Here is the list of public functions:<\/p>\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/06\/list_of_public_functions_v2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"819\" height=\"1024\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/06\/list_of_public_functions_v2-819x1024.png\" alt=\"List of public functions of the SI1145_WE Library\" class=\"wp-image-6646\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/06\/list_of_public_functions_v2-819x1024.png 819w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/06\/list_of_public_functions_v2-240x300.png 240w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/06\/list_of_public_functions_v2-768x960.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2020\/06\/list_of_public_functions_v2.png 852w\" sizes=\"auto, (max-width: 819px) 100vw, 819px\" \/><\/a><figcaption>List of public functions of the SI1145_WE Library<\/figcaption><\/figure><p>If you download the library, you will also get the function list in a better readable PDF format.<\/p>\r\n\r\n<p>If you find bugs or miss features, get in touch. I promise short-term repairs!<\/p>\n<h3 class=\"wp-block-heading\">The example sketches<\/h3>\n\n<h4 class=\"wp-block-heading\">Wiring the SI1145<\/h4>\n<p>For the first five sketches that use only one SI1145, the following wiring can be applied. However, you only need the IR LED if you want to carry out PS measurements.<\/p>\n<figure class=\"wp-block-image\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/SI1145_wiring.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"600\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/SI1145_wiring-1024x600.png\" alt=\"Wiring for the example sketches\" class=\"wp-image-3770\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/SI1145_wiring-1024x600.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/SI1145_wiring-300x176.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/SI1145_wiring-768x450.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/SI1145_wiring.png 1163w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>Wiring for the example sketches (with a sensor). The LED is an IR LED.<\/figcaption><\/figure><p>On the breadboard, it looks like this:<\/p>\n<figure class=\"wp-block-image\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Aufbau_Breadboard.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"614\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Aufbau_Breadboard-1024x614.jpg\" alt=\"Wiring on the breadboard\" class=\"wp-image-3772\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Aufbau_Breadboard-1024x614.jpg 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Aufbau_Breadboard-300x180.jpg 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Aufbau_Breadboard-768x460.jpg 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Aufbau_Breadboard-1320x791.jpg 1320w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Aufbau_Breadboard.jpg 1800w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>Wiring on the breadboard<\/figcaption><\/figure>\n<h4 class=\"wp-block-heading\">Example sketch 1 &#8211; Basics, continuous measurement<\/h4>\n<p>I have added many comments to the sketches. That is why I do not need to write much about it, I suppose. Basically, you have to determine which <code>enableMeasurements()<\/code> measurements you want to activate and whether they run continuously (AUTO) or as a single measurement (FORCE). You can use PAUSE to suspend continuous measurements.<\/p>\r\n\r\n<p>In this first sketch, the SI1145 performs AS IR\/VIS, PS and UV index measurements in continuous mode. Just play with the settings to become familiar with it.<\/p><div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"SI1145_basics_continuous.ino\" data-enlighter-title=\"SI1145_basics_continuous.ino\">#include\u00a0&lt;SI1145_WE.h&gt;\r\n#include\u00a0&lt;Wire.h&gt;\r\n\r\nSI1145_WE\u00a0mySI1145\u00a0=\u00a0SI1145_WE();\r\n\/\/ You can also pass a Wire object like wire2:\r\n\/\/ SI1145_WE mySI1145 = SI1145_WE(&wire2);\r\n\r\nvoid\u00a0setup()\u00a0{\r\n\u00a0\u00a0Serial.begin(9600);\r\n\u00a0\u00a0Wire.begin();\r\n\u00a0\u00a0mySI1145.init();\r\n\r\n\u00a0\u00a0\/*\u00a0in\u00a0case\u00a0you\u00a0want\u00a0to\u00a0change\u00a0the\u00a0I2C\u00a0Address\u00a0*\/\r\n\u00a0\u00a0\/\/mySI1145.setI2CAddress(0x59);\u00a0\r\n\u00a0\u00a0\r\n\u00a0\u00a0mySI1145.enableHighSignalVisRange();\u00a0\/\/\u00a0Gain\u00a0divided\u00a0by\u00a014.5\r\n\u00a0\u00a0mySI1145.enableHighSignalIrRange();\u00a0\/\/\u00a0Gain\u00a0divided\u00a0by\u00a014.5\r\n\u00a0\u00a0\r\n\u00a0\u00a0\/*\u00a0choices:\u00a0PS_TYPE,\u00a0ALS_TYPE,\u00a0PSALS_TYPE,\u00a0ALSUV_TYPE,\u00a0PSALSUV_TYPE\u00a0||\u00a0FORCE,\u00a0AUTO,\u00a0PAUSE\u00a0*\/\r\n\u00a0\u00a0mySI1145.enableMeasurements(PSALSUV_TYPE,\u00a0AUTO);\r\n\u00a0\u00a0\r\n\u00a0\u00a0\/*\u00a0choose\u00a0gain\u00a0value:\u00a00,\u00a01,\u00a02,\u00a03,\u00a04,\u00a05,\u00a06,\u00a07\u00a0*\/\u00a0\r\n\u00a0\u00a0\/\/mySI1145.setAlsVisAdcGain(0);\r\n\u00a0\u00a0\r\n\u00a0\u00a0\/*\u00a0choose\u00a0gain\u00a0value:\u00a00,\u00a01,\u00a02,\u00a03,\u00a04,\u00a05\u00a0*\/\r\n\u00a0\u00a0\/\/mySI1145.setPsAdcGain(0);\r\n\r\n\u00a0\u00a0\/*\u00a0if\u00a0uncommented,\u00a0the\u00a0least\u00a016\u00a0bit\u00a0of\u00a0the\u00a017\u00a0bit\u00a0ADC\u00a0will\u00a0be\u00a0read\u00a0*\/\r\n\u00a0\u00a0\/\/mySI1145.enableHighResolutionVis();\r\n\u00a0\u00a0Serial.println(\"SI1145\u00a0-\u00a0basics\u00a0-\u00a0continuous\");\r\n}\r\n\r\nvoid\u00a0loop()\u00a0{\r\n\u00a0\u00a0byte\u00a0failureCode\u00a0=\u00a00;\r\n\u00a0\u00a0unsigned\u00a0int\u00a0amb_als\u00a0=\u00a00;\r\n\u00a0\u00a0unsigned\u00a0int\u00a0amb_ir\u00a0=\u00a00;\r\n\u00a0\u00a0unsigned\u00a0int\u00a0proximity\u00a0=\u00a00;\r\n\u00a0\u00a0float\u00a0uv\u00a0=\u00a00.0;\r\n\u00a0\u00a0\r\n\u00a0\u00a0amb_als\u00a0=\u00a0mySI1145.getAlsVisData();\r\n\u00a0\u00a0amb_ir\u00a0=\u00a0mySI1145.getAlsIrData();\r\n\r\n\u00a0\u00a0\/*\u00a0uncomment\u00a0if\u00a0you\u00a0want\u00a0to\u00a0perform\u00a0PS\u00a0measurements\u00a0*\/\u00a0\r\n\u00a0\u00a0\/\/\u00a0proximity\u00a0=\u00a0mySI1145.getPsData();\r\n\r\n\u00a0\u00a0uv\u00a0=\u00a0mySI1145.getUvIndex();\r\n\u00a0\u00a0\r\n\u00a0\u00a0Serial.print(\"Ambient\u00a0Light:\u00a0\");\r\n\u00a0\u00a0Serial.println(amb_als);\r\n\u00a0\u00a0Serial.print(\"Infrared\u00a0Light:\u00a0\");\r\n\u00a0\u00a0Serial.println(amb_ir);\r\n\u00a0\u00a0Serial.print(\"UV-Index:\u00a0\");\r\n\u00a0\u00a0Serial.println(uv);\r\n\u00a0\u00a0\/*\u00a0uncomment\u00a0if\u00a0you\u00a0perform\u00a0PS\u00a0measurements\u00a0*\/\r\n\u00a0\u00a0\/\/\u00a0Serial.print(\"Proximity:\u00a0\");\r\n\u00a0\u00a0\/\/\u00a0Serial.println(proximity);\r\n\u00a0\u00a0failureCode\u00a0=\u00a0mySI1145.getFailureMode();\u00a0\u00a0\/\/\u00a0reads\u00a0the\u00a0response\u00a0register\r\n\u00a0\u00a0if((failureCode&amp;128)){\u00a0\u00a0\/\/\u00a0if\u00a0bit\u00a07\u00a0is\u00a0set\u00a0in\u00a0response\u00a0register,\u00a0there\u00a0is\u00a0a\u00a0failure\r\n\u00a0\u00a0\u00a0\u00a0handleFailure(failureCode);\r\n\u00a0\u00a0}\r\n\u00a0\u00a0Serial.println(\"---------\");\r\n\u00a0\u00a0delay(1000);\r\n}\r\n\r\nvoid\u00a0handleFailure(byte\u00a0code){\r\n\u00a0\u00a0String\u00a0msg\u00a0=\u00a0\"\";\r\n\u00a0\u00a0switch(code){\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_INVALID_SETTING:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"Invalid\u00a0Setting\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_PS1_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"PS\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_ALS_VIS_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"ALS\u00a0VIS\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_ALS_IR_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"ALS\u00a0IR\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_AUX_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"AUX\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0default:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"Unknown\u00a0Failure\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0}\r\n\u00a0\u00a0Serial.println(msg);\u00a0\r\n\u00a0\u00a0mySI1145.clearFailure();\r\n}<\/pre>\r\n&nbsp;\r\n\r\n<\/div>\n<h4 class=\"wp-block-heading\">Example sketch 2 &#8211; continuous, interrupt-controlled <\/h4>\n<p>Also in this sketch, the SI1145 runs in automatic mode. However, you will see that the main loop does not contain any delay or that the delay is commented. The speed is controlled by the measurement rate. At the maximum (0xFFFF = 65535) applied here, a measurement takes place approximately every 2 seconds. You can test a different value. E.g. 0x8FFF to land at about one second. By the way, the default in my library is 0x00FF, which corresponds to a measuring frequency of about 8 milliseconds. In FORCED mode, the measurement rate is zero by definition.<\/p>\r\n\r\n<p>The Arduino is &#8220;informed&#8221; about via the interrupt pin if a measured value is available. It is generally recommended doing this in continuous mode. Because if things run badly, then you read the data registers during an update and get the lower byte from the old measured value and the upper byte from the new measured value.<\/p><div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"SI1145_continuous_interrupt_controlled.ino\" data-enlighter-title=\"SI1145_continuous_interrupt_controlled.ino\">#include\u00a0&lt;SI1145_WE.h&gt;\r\n#include\u00a0&lt;Wire.h&gt;\r\nconst\u00a0int\u00a0interruptPin\u00a0=\u00a02;\r\n\r\nSI1145_WE\u00a0mySI1145\u00a0=\u00a0SI1145_WE();\r\n\/\/ You can also pass a Wire object like wire2:\r\n\/\/ SI1145_WE mySI1145 = SI1145_WE(&wire2);\r\n\r\nvoid\u00a0setup()\u00a0{\r\n\u00a0\u00a0Serial.begin(9600);\r\n\u00a0\u00a0Wire.begin();\r\n\u00a0\u00a0pinMode(interruptPin,\u00a0INPUT_PULLUP);\r\n\u00a0\u00a0mySI1145.init();\r\n\u00a0\u00a0\/\/mySI1145.enableHighSignalVisRange();\r\n\u00a0\u00a0\/\/mySI1145.enableHighSignalIrRange();\r\n\u00a0\u00a0\r\n\u00a0\u00a0\/*\u00a0SI1145\u00a0wakes\u00a0up\u00a0periodically\u00a0-\u00a0a\u00a0measurement\u00a0rate\u00a0of\u00a0x\u00a0means\u00a0that\u00a0every\u00a0x\u00a0\r\n\u00a0\u00a0\u00a0*\u00a0\u00a0wake\u00a0up\u00a0a\u00a0measurement\u00a0is\u00a0done;\u00a0chose\u00a0between\u00a00\u00a0and\u00a065535\u00a0-\u00a0if\u00a0you\u00a0chose\u00a0a\u00a0low\u00a0value\u00a0\r\n\u00a0\u00a0\u00a0*\u00a0\u00a0you\u00a0should\u00a0uncomment\u00a0the\u00a0delay\u00a0in\u00a0the\u00a0loop\u00a0*\/\r\n\u00a0\u00a0mySI1145.setMeasurementRate(0xFFFF);\r\n\u00a0\u00a0\r\n\u00a0\u00a0\/*\u00a0choices:\u00a0PS_TYPE,\u00a0ALS_TYPE,\u00a0PSALS_TYPE,\u00a0ALSUV_TYPE,\u00a0PSALSUV_TYPE\u00a0||\u00a0FORCE,\u00a0AUTO,\u00a0PAUSE\u00a0*\/\r\n\u00a0\u00a0mySI1145.enableMeasurements(PSALSUV_TYPE,\u00a0AUTO);\r\n\r\n\u00a0\u00a0\u00a0\/*\u00a0choose\u00a0gain\u00a0value:\u00a00,\u00a01,\u00a02,\u00a03,\u00a04,\u00a05,\u00a06,\u00a07\u00a0*\/\u00a0\r\n\u00a0\u00a0mySI1145.setAlsVisAdcGain(0);\r\n\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\/*\u00a0choose\u00a0gain\u00a0value:\u00a00,\u00a01,\u00a02,\u00a03,\u00a04,\u00a05\u00a0*\/\r\n\u00a0\u00a0mySI1145.setPsAdcGain(0);\r\n\u00a0\u00a0Serial.println(\"SI1145\u00a0-\u00a0basics,\u00a0interrupt\u00a0controlled\");\r\n}\r\n\r\nvoid\u00a0loop()\u00a0{\r\n\u00a0\u00a0byte\u00a0failureCode\u00a0=\u00a00;\r\n\u00a0\u00a0unsigned\u00a0int\u00a0amb_als\u00a0=\u00a00;\r\n\u00a0\u00a0unsigned\u00a0int\u00a0amb_ir\u00a0=\u00a00;\r\n\u00a0\u00a0unsigned\u00a0int\u00a0proximity\u00a0=\u00a00;\r\n\u00a0\u00a0float\u00a0uv\u00a0=\u00a00.0;\r\n\u00a0\u00a0\r\n\u00a0\u00a0mySI1145.clearAllInterrupts();\r\n\r\n\u00a0\u00a0\/*\u00a0wait\u00a0until\u00a0a\u00a0measurement\u00a0is\u00a0completed\u00a0-&gt;\u00a0interrupt\u00a0goes\u00a0LOW\u00a0*\/\r\n\u00a0\u00a0while(digitalRead(interruptPin)){\r\n\u00a0\u00a0\/*\u00a0just\u00a0wait\u00a0for\u00a0interruptpin\u00a0to\u00a0go\u00a0LOW;\u00a0if\u00a0you\u00a0have\u00a0not\u00a0set\u00a0up\u00a0the\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0interrupt\u00a0correctly\u00a0you\u00a0might\u00a0wait\u00a0forever!\u00a0*\/\u00a0\u00a0\r\n\u00a0\u00a0}\u00a0\r\n\u00a0\u00a0\r\n\u00a0\u00a0amb_als\u00a0=\u00a0mySI1145.getAlsVisData();\r\n\u00a0\u00a0amb_ir\u00a0=\u00a0mySI1145.getAlsIrData();\r\n\u00a0\u00a0proximity\u00a0=\u00a0mySI1145.getPsData();\r\n\u00a0\u00a0uv\u00a0=\u00a0mySI1145.getUvIndex();\r\n\u00a0\u00a0\r\n\u00a0\u00a0Serial.print(\"Ambient\u00a0Light:\u00a0\");\r\n\u00a0\u00a0Serial.println(amb_als);\r\n\u00a0\u00a0Serial.print(\"Infrared\u00a0Light:\u00a0\");\r\n\u00a0\u00a0Serial.println(amb_ir);\r\n\u00a0\u00a0Serial.print(\"UV-Index:\u00a0\");\r\n\u00a0\u00a0Serial.println(uv);\r\n\u00a0\u00a0Serial.print(\"Proximity:\u00a0\");\r\n\u00a0\u00a0Serial.println(proximity);\r\n\u00a0\u00a0\r\n\u00a0\u00a0failureCode\u00a0=\u00a0mySI1145.getFailureMode();\u00a0\u00a0\/\/\u00a0reads\u00a0the\u00a0response\u00a0register\r\n\u00a0\u00a0if((failureCode&amp;128)){\u00a0\u00a0\/\/\u00a0if\u00a0bit\u00a07\u00a0is\u00a0set\u00a0in\u00a0response\u00a0register,\u00a0there\u00a0is\u00a0a\u00a0failure\r\n\u00a0\u00a0\u00a0\u00a0handleFailure(failureCode);\r\n\u00a0\u00a0}\r\n\u00a0\u00a0Serial.println(\"---------\");\r\n\u00a0\u00a0\r\n\u00a0\u00a0\/\/Measuring\u00a0frequency\u00a0in\u00a0this\u00a0sketch\u00a0is\u00a0controlled\u00a0by\u00a0setMeasurementRate\r\n\u00a0\u00a0\/\/delay(500);\u00a0\r\n}\r\n\r\nvoid\u00a0handleFailure(byte\u00a0code){\r\n\u00a0\u00a0String\u00a0msg\u00a0=\u00a0\"\";\r\n\u00a0\u00a0switch(code){\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_INVALID_SETTING:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"Invalid\u00a0Setting\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_PS1_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"PS\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_ALS_VIS_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"ALS\u00a0VIS\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_ALS_IR_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"ALS\u00a0IR\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_AUX_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"AUX\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0default:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"Unknown\u00a0Failure\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0}\r\n\u00a0\u00a0Serial.println(msg);\u00a0\r\n\u00a0\u00a0mySI1145.clearFailure();\r\n}<\/pre>\r\n&nbsp;\r\n\r\n<\/div>\n<h4 class=\"wp-block-heading\">Example sketch 3 &#8211; forced ALS<\/h4>\n<p>You may have noticed that the VIS readings fluctuate quite a lot when the SI1145 is not in High Signal Range mode. This can be mitigated by averaging several readings.<\/p>\r\n\r\n<p>In this example sketch, 50 readings are taken for one data point. This is happening here in Forced Mode. Each individual measurement must be started via <code>startSingleMeasurement()<\/code>. With <code>getAlsVisData()<\/code> and <code>getAlsIrData()<\/code> the data registers are read. However, these functions do not check whether the measurements have already been completed. You could insert a delay, but you would have to make sure you are on the safe side and would apply a more or less large buffer. The fastest way to perform the measurements succeeding is to control them by interrupts. The measured values are collected immediately after provision and the next measurement can begin.<\/p><div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"SI1145_forced_ALS.ino\" data-enlighter-title=\"SI1145_forced_ALS.ino\">#include\u00a0&lt;SI1145_WE.h&gt;\r\n#include\u00a0&lt;Wire.h&gt;\r\nconst\u00a0int\u00a0interruptPin\u00a0=\u00a02;\r\n\r\nSI1145_WE\u00a0mySI1145\u00a0=\u00a0SI1145_WE();\r\n\/\/ You can also pass a Wire object like wire2:\r\n\/\/ SI1145_WE mySI1145 = SI1145_WE(&wire2);\r\n\r\nvoid\u00a0setup()\u00a0{\r\n\u00a0\u00a0Serial.begin(9600);\r\n\u00a0\u00a0Wire.begin();\r\n\u00a0\u00a0pinMode(interruptPin,\u00a0INPUT_PULLUP);\r\n\u00a0\u00a0mySI1145.init();\r\n\u00a0\u00a0\/\/mySI1145.enableHighSignalVisRange();\r\n\u00a0\u00a0\/\/mySI1145.enableHighSignalIrRange();\r\n\u00a0\u00a0\r\n\u00a0\u00a0\/*\u00a0choices:\u00a0PS_TYPE,\u00a0ALS_TYPE,\u00a0PSALS_TYPE,\u00a0ALSUV_TYPE,\u00a0PSALSUV_TYPE\u00a0||\u00a0FORCE,\u00a0AUTO,\u00a0PAUSE\u00a0*\/\r\n\u00a0\u00a0mySI1145.enableMeasurements(ALS_TYPE,\u00a0FORCE);\r\n\r\n\u00a0\u00a0\u00a0\/*\u00a0choose\u00a0gain\u00a0value:\u00a00,\u00a01,\u00a02,\u00a03,\u00a04,\u00a05,\u00a06,\u00a07\u00a0*\/\u00a0\r\n\u00a0\u00a0mySI1145.setAlsVisAdcGain(0);\r\n\r\n\u00a0\u00a0\/\/mySI1145.enableHighResolutionVis();\r\n\u00a0\u00a0Serial.println(\"SI1145\u00a0-\u00a0forced\u00a0ALS\");\r\n}\r\n\r\nvoid\u00a0loop()\u00a0{\r\n\u00a0\u00a0byte\u00a0failureCode\u00a0=\u00a00;\r\n\u00a0\u00a0unsigned\u00a0long\u00a0amb_als\u00a0=\u00a00;\r\n\u00a0\u00a0unsigned\u00a0long\u00a0amb_ir\u00a0=\u00a00;\r\n\u00a0\u00a0\u00a0\r\n\u00a0\u00a0for(int\u00a0i=0;\u00a0i&lt;50;\u00a0i++){\r\n\u00a0\u00a0\u00a0\u00a0mySI1145.clearAllInterrupts();\r\n\u00a0\u00a0\u00a0\u00a0mySI1145.startSingleMeasurement();\r\n\u00a0\u00a0\u00a0\u00a0while(digitalRead(interruptPin)){\r\n\u00a0\u00a0\u00a0\u00a0\/*\u00a0just\u00a0wait\u00a0for\u00a0interruptpin\u00a0to\u00a0go\u00a0LOW;\u00a0if\u00a0you\u00a0have\u00a0not\u00a0set\u00a0up\u00a0the\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0interrupt\u00a0correctly\u00a0you\u00a0might\u00a0wait\u00a0forever!\u00a0*\/\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0amb_als\u00a0+=\u00a0mySI1145.getAlsVisData();\r\n\u00a0\u00a0\u00a0\u00a0amb_ir\u00a0+=\u00a0mySI1145.getAlsIrData();\r\n\u00a0\u00a0}\r\n\u00a0\u00a0amb_als\u00a0\/=\u00a050;\r\n\u00a0\u00a0amb_ir\u00a0\/=\u00a050;\r\n\u00a0\u00a0Serial.print(\"Ambient\u00a0Light:\u00a0\");\r\n\u00a0\u00a0Serial.println(amb_als);\r\n\u00a0\u00a0Serial.print(\"Infrared\u00a0Light:\u00a0\");\r\n\u00a0\u00a0Serial.println(amb_ir);\r\n\u00a0\u00a0failureCode\u00a0=\u00a0mySI1145.getFailureMode();\u00a0\u00a0\/\/\u00a0reads\u00a0the\u00a0response\u00a0register\r\n\u00a0\u00a0if((failureCode&amp;128)){\u00a0\u00a0\u00a0\/\/\u00a0if\u00a0bit\u00a07\u00a0is\u00a0set\u00a0in\u00a0response\u00a0register,\u00a0there\u00a0is\u00a0a\u00a0failure\r\n\u00a0\u00a0\u00a0\u00a0handleFailure(failureCode);\r\n\u00a0\u00a0}\r\n\u00a0\u00a0Serial.println(\"---------\");\r\n\u00a0\u00a0delay(1000);\r\n}\r\n\r\nvoid\u00a0handleFailure(byte\u00a0code){\r\n\u00a0\u00a0String\u00a0msg\u00a0=\u00a0\"\";\r\n\u00a0\u00a0switch(code){\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_INVALID_SETTING:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"Invalid\u00a0Setting\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_PS1_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"PS\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_ALS_VIS_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"ALS\u00a0VIS\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_ALS_IR_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"ALS\u00a0IR\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_AUX_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"AUX\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0default:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"Unknown\u00a0Failure\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0}\r\n\u00a0\u00a0Serial.println(msg);\u00a0\r\n\u00a0\u00a0mySI1145.clearFailure();\r\n}<\/pre>\r\n&nbsp;\r\n\r\n<\/div>\n<h4 class=\"wp-block-heading\">Sample sketch 4 &#8211; advanced proximity<\/h4>\n<p>This example sketch is doing PS measurements. Since PS measurements also vary quite a lot, I carry out ten individual measurements. To increase the range, you can increase the LED current with <code>setLEDcurrent()<\/code>. <strong>However, you have to make sure that your LED can handle the current.<\/strong> The same applies to the installation of resistors, if necessary.<\/p>\r\n\r\n<p>The increase in the IR-LED current is accompanied by a higher baseline, i.e. values without object within range. This is because the IR LED also radiates directly to the sensor. Try to shield the IR LED and the sensor, e.g. just with a piece of cardboard or plastic. The measurement signal of an object then stands out much more clearly from the baseline.<\/p><div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"SI1145_advanced_proximity.ino\" data-enlighter-title=\"SI1145_advanced_proximity.ino\">#include\u00a0&lt;SI1145_WE.h&gt;\r\n#include\u00a0&lt;Wire.h&gt;\r\nconst\u00a0int\u00a0interruptPin\u00a0=\u00a02;\r\n\r\nSI1145_WE\u00a0mySI1145\u00a0=\u00a0SI1145_WE();\r\n\/\/ You can also pass a Wire object like wire2:\r\n\/\/ SI1145_WE mySI1145 = SI1145_WE(&wire2);\r\n\r\nvoid\u00a0setup()\u00a0{\r\n\u00a0\u00a0Serial.begin(9600);\r\n\u00a0\u00a0Wire.begin();\r\n\u00a0\u00a0pinMode(interruptPin,\u00a0INPUT_PULLUP);\r\n\u00a0\u00a0mySI1145.init();\r\n\r\n\u00a0\u00a0\/*\u00a0choices:\u00a0PS_TYPE,\u00a0ALS_TYPE,\u00a0PSALS_TYPE,\u00a0ALSUV_TYPE,\u00a0PSALSUV_TYPE\u00a0||\u00a0FORCE,\u00a0AUTO,\u00a0PAUSE\u00a0*\/\r\n\u00a0\u00a0mySI1145.enableMeasurements(PS_TYPE,\u00a0FORCE);\r\n\u00a0\u00a0\r\n\u00a0\u00a0\/*\u00a0choose\u00a0gain\u00a0value:\u00a00,\u00a01,\u00a02,\u00a03,\u00a04,\u00a05\u00a0*\/\r\n\u00a0\u00a0mySI1145.setPsAdcGain(0);\r\n\u00a0\u00a0mySI1145.enableInterrupt(PS_INT);\r\n\u00a0\u00a0\r\n\u00a0\u00a0\/*\u00a0choose\u00a0LEDCurrent:\u00a0value\u00a0between\u00a01\u00a0(=\u00a05.6\u00a0mA)\u00a0and\u00a015\u00a0(=\u00a0359\u00a0mA)\r\n\u00a0\u00a0\u00a0*\u00a0ensure\u00a0your\u00a0LED\u00a0is\u00a0compatible\u00a0*\/\r\n\u00a0\u00a0mySI1145.setLEDCurrent(10);\r\n\r\n\u00a0\u00a0\/*\u00a0select\u00a0PS\u00a0diode:\u00a0SMALL_DIODE\u00a0or\u00a0LARGE_DIODE\u00a0(default)\r\n\u00a0\u00a0\u00a0*\u00a0LARGE_DIODE\u00a0is\u00a0more\u00a0sensitive,\u00a0but\u00a0might\u00a0lead\u00a0to\u00a0\r\n\u00a0\u00a0\u00a0*\u00a0overflow\u00a0e.g.\u00a0in\u00a0sunlight\u00a0*\/\r\n\u00a0\u00a0\/\/mySI1145.selectPsDiode(SMALL_DIODE);\r\n\u00a0\u00a0Serial.println(\"SI1145\u00a0-\u00a0advanced\u00a0proximity\");\r\n}\r\n\r\nvoid\u00a0loop()\u00a0{\r\n\u00a0\u00a0byte\u00a0failureCode\u00a0=\u00a00;\r\n\u00a0\u00a0unsigned\u00a0long\u00a0proximity\u00a0=\u00a00;\r\n\u00a0\u00a0\u00a0\r\n\u00a0\u00a0\/*\u00a010\u00a0proximity\u00a0measurements\u00a0are\u00a0done\u00a0to\u00a0increase\u00a0repeatibility\u00a0*\/\r\n\u00a0\u00a0for(int\u00a0i=0;\u00a0i&lt;10;\u00a0i++){\r\n\u00a0\u00a0\u00a0\u00a0mySI1145.clearAllInterrupts();\r\n\u00a0\u00a0\u00a0\u00a0mySI1145.startSingleMeasurement();\r\n\u00a0\u00a0\u00a0\u00a0while(digitalRead(interruptPin)){\r\n\u00a0\u00a0\u00a0\u00a0\/*\u00a0just\u00a0wait\u00a0for\u00a0interruptpin\u00a0to\u00a0go\u00a0LOW;\u00a0if\u00a0you\u00a0have\u00a0not\u00a0set\u00a0up\u00a0the\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0interrupt\u00a0correctly\u00a0you\u00a0might\u00a0wait\u00a0forever!\u00a0*\/\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0proximity\u00a0+=\u00a0mySI1145.getPsData();\r\n\u00a0\u00a0}\r\n\u00a0\u00a0proximity\u00a0\/=\u00a010;\r\n\u00a0\u00a0\u00a0\r\n\u00a0\u00a0Serial.print(\"Proximity:\u00a0\");\r\n\u00a0\u00a0Serial.println(proximity);\r\n\u00a0\r\n\u00a0\u00a0failureCode\u00a0=\u00a0mySI1145.getFailureMode();\u00a0\u00a0\/\/\u00a0reads\u00a0the\u00a0response\u00a0register\r\n\u00a0\u00a0if((failureCode&amp;128)){\u00a0\/\/\u00a0if\u00a0bit\u00a07\u00a0is\u00a0set\u00a0in\u00a0response\u00a0register,\u00a0there\u00a0is\u00a0a\u00a0failure\r\n\u00a0\u00a0\u00a0\u00a0handleFailure(failureCode);\r\n\u00a0\u00a0}\r\n\u00a0\u00a0Serial.println(\"---------\");\r\n\u00a0\u00a0delay(1000);\r\n}\r\n\r\nvoid\u00a0handleFailure(byte\u00a0code){\r\n\u00a0\u00a0String\u00a0msg\u00a0=\u00a0\"\";\r\n\u00a0\u00a0switch(code){\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_INVALID_SETTING:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"Invalid\u00a0Setting\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_PS1_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"PS\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_ALS_VIS_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"ALS\u00a0VIS\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_ALS_IR_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"ALS\u00a0IR\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_AUX_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"AUX\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0default:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"Unknown\u00a0Failure\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0}\r\n\u00a0\u00a0Serial.println(msg);\u00a0\r\n\u00a0\u00a0mySI1145.clearFailure();\r\n}<\/pre>\r\n&nbsp;\r\n\r\n<\/div>\n<h4 class=\"wp-block-heading\">Example sketch 5 &#8211; lux calculation<\/h4>\n<p>Here is the example sketch for lux calculation. Just play a bit with the equations and different light sources.<\/p><div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"SI1145_lux_calculation.ino\" data-enlighter-title=\"SI1145_lux_calculation.ino\">#include\u00a0&lt;SI1145_WE.h&gt;\r\n#include\u00a0&lt;Wire.h&gt;\r\nconst\u00a0int\u00a0interruptPin\u00a0=\u00a02;\r\n\r\nSI1145_WE\u00a0mySI1145\u00a0=\u00a0SI1145_WE();\r\n\/\/ You can also pass a Wire object like wire2:\r\n\/\/ SI1145_WE mySI1145 = SI1145_WE(&wire2);\r\n\r\nvoid\u00a0setup()\u00a0{\r\n\u00a0\u00a0Serial.begin(9600);\r\n\u00a0\u00a0Wire.begin();\r\n\u00a0\u00a0pinMode(interruptPin,\u00a0INPUT_PULLUP);\r\n\u00a0\u00a0mySI1145.init();\r\n\u00a0\u00a0\r\n\u00a0\u00a0\/*\u00a0choices:\u00a0PS_TYPE,\u00a0ALS_TYPE,\u00a0PSALS_TYPE,\u00a0ALSUV_TYPE,\u00a0PSALSUV_TYPE\u00a0||\u00a0FORCE,\u00a0AUTO,\u00a0PAUSE\u00a0*\/\r\n\u00a0\u00a0mySI1145.enableMeasurements(ALS_TYPE,\u00a0FORCE);\r\n\u00a0\u00a0\r\n\u00a0\u00a0\/*\u00a0if\u00a0gain\u00a0is\u00a0changed,\u00a0this\u00a0must\u00a0be\u00a0considered\u00a0in\u00a0lux\u00a0calculation\u00a0*\/\u00a0\r\n\u00a0\u00a0mySI1145.setAlsVisAdcGain(0);\r\n\u00a0\u00a0\r\n\u00a0\/*\u00a0if\u00a0gain\u00a0is\u00a0changed,\u00a0this\u00a0must\u00a0be\u00a0considered\u00a0in\u00a0lux\u00a0calculation\u00a0*\/\u00a0\r\n\u00a0\u00a0mySI1145.setPsAdcGain(0);\r\n\u00a0\r\n\u00a0\u00a0Serial.println(\"SI1145\u00a0-\u00a0lux\u00a0calculation\");\r\n}\r\n\r\nvoid\u00a0loop()\u00a0{\r\n\u00a0\u00a0byte\u00a0failureCode\u00a0=\u00a00;\r\n\u00a0\u00a0unsigned\u00a0long\u00a0amb_als\u00a0=\u00a00;\r\n\u00a0\u00a0unsigned\u00a0long\u00a0amb_ir\u00a0=\u00a00;\r\n\u00a0\u00a0float\u00a0lx\u00a0=\u00a00.0;\r\n\u00a0\u00a0\u00a0\r\n\u00a0\u00a0for(int\u00a0i=0;\u00a0i&lt;50;\u00a0i++){\r\n\u00a0\u00a0\u00a0\u00a0mySI1145.clearAllInterrupts();\r\n\u00a0\u00a0\u00a0\u00a0mySI1145.startSingleMeasurement();\r\n\u00a0\u00a0\u00a0\u00a0while(digitalRead(interruptPin)){\r\n\u00a0\u00a0\u00a0\u00a0\/*\u00a0just\u00a0wait\u00a0for\u00a0interruptpin\u00a0to\u00a0go\u00a0LOW;\u00a0if\u00a0you\u00a0have\u00a0not\u00a0set\u00a0up\u00a0the\u00a0\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0interrupt\u00a0correctly\u00a0you\u00a0might\u00a0wait\u00a0forever!\u00a0*\/\u00a0\u00a0\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0amb_als\u00a0+=\u00a0mySI1145.getAlsVisData();\r\n\u00a0\u00a0\u00a0\u00a0amb_ir\u00a0+=\u00a0mySI1145.getAlsIrData();\r\n\u00a0\u00a0}\r\n\u00a0\u00a0amb_als\u00a0\/=\u00a050;\r\n\u00a0\u00a0amb_ir\u00a0\/=\u00a050;\r\n\u00a0\u00a0lx\u00a0=\u00a0calcLux(amb_als,amb_ir);\u00a0\r\n\u00a0\u00a0Serial.print(\"Ambient\u00a0Light:\u00a0\");\r\n\u00a0\u00a0Serial.println(amb_als);\r\n\u00a0\u00a0Serial.print(\"Infrared\u00a0Light:\u00a0\");\r\n\u00a0\u00a0Serial.println(amb_ir);\r\n\u00a0\u00a0Serial.print(\"Lux:\u00a0\");\r\n\u00a0\u00a0Serial.println(lx);\r\n\r\n\u00a0\u00a0failureCode\u00a0=\u00a0mySI1145.getFailureMode();\u00a0\u00a0\/\/\u00a0reads\u00a0the\u00a0response\u00a0register\r\n\u00a0\u00a0if((failureCode&amp;128)){\u00a0\u00a0\u00a0\/\/\u00a0if\u00a0bit\u00a07\u00a0is\u00a0set\u00a0in\u00a0response\u00a0register,\u00a0there\u00a0is\u00a0a\u00a0failure\r\n\u00a0\u00a0\u00a0\u00a0handleFailure(failureCode);\r\n\u00a0\u00a0}\r\n\u00a0\u00a0Serial.println(\"---------\");\r\n\u00a0\u00a0delay(1000);\r\n}\r\n\r\nvoid\u00a0handleFailure(byte\u00a0code){\r\n\u00a0\u00a0String\u00a0msg\u00a0=\u00a0\"\";\r\n\u00a0\u00a0switch(code){\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_INVALID_SETTING:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"Invalid\u00a0Setting\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_PS1_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"PS\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_ALS_VIS_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"ALS\u00a0VIS\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_ALS_IR_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"ALS\u00a0IR\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0case\u00a0SI1145_RESP_AUX_ADC_OVERFLOW:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"AUX\u00a0ADC\u00a0Overflow\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0\u00a0\u00a0default:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0msg\u00a0=\u00a0\"Unknown\u00a0Failure\";\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0break;\r\n\u00a0\u00a0}\r\n\u00a0\u00a0Serial.println(msg);\u00a0\r\n\u00a0\u00a0mySI1145.clearFailure();\r\n}\r\n\r\nfloat\u00a0calcLux(uint16_t\u00a0vis,\u00a0uint16_t\u00a0ir){\r\n\u00a0\u00a0const\u00a0unsigned\u00a0int\u00a0vis_dark\u00a0=\u00a0256;\u00a0\/\/\u00a0empirical\u00a0value\r\n\u00a0\u00a0const\u00a0unsigned\u00a0int\u00a0ir_dark\u00a0=\u00a0250;\u00a0\/\/\u00a0empirical\u00a0value\r\n\u00a0\u00a0const\u00a0float\u00a0gainFactor\u00a0=\u00a01.0;\r\n\u00a0\u00a0const\u00a0float\u00a0visCoeff\u00a0=\u00a05.41;\u00a0\/\/\u00a0application\u00a0notes\u00a0AN523\r\n\u00a0\u00a0const\u00a0float\u00a0irCoeff\u00a0=\u00a00.08;\u00a0\/\/\u00a0application\u00a0notes\u00a0AN523\r\n\u00a0\u00a0const\u00a0float\u00a0visCountPerLux\u00a0=\u00a00.319;\u00a0\/\/\u00a0for\u00a0incandescent\u00a0bulb\u00a0(datasheet)\r\n\u00a0\u00a0const\u00a0float\u00a0irCountPerLux\u00a0=\u00a08.46;\u00a0\/\/\u00a0for\u00a0incandescent\u00a0bulb\u00a0(datasheet)\r\n\u00a0\u00a0const\u00a0float\u00a0corrFactor\u00a0=\u00a00.18;\u00a0\/\/\u00a0my\u00a0empirical\u00a0correction\u00a0factor\r\n\u00a0\u00a0\r\n\u00a0\u00a0\/\/\u00a0According\u00a0to\u00a0application\u00a0notes\u00a0AN523:\u00a0\r\n\u00a0\u00a0float\u00a0lux\u00a0=\u00a0((vis\u00a0-\u00a0vis_dark)\u00a0*\u00a0visCoeff\u00a0-\u00a0(ir\u00a0-\u00a0ir_dark)\u00a0*\u00a0irCoeff)\u00a0*\u00a0gainFactor;\r\n\r\n\u00a0\u00a0\/\/\u00a0the\u00a0equation\u00a0above\u00a0does\u00a0not\u00a0consider\u00a0the\u00a0counts\/Lux\u00a0depending\u00a0on\u00a0light\u00a0source\u00a0type\r\n\u00a0\u00a0\/\/\u00a0I\u00a0suggest\u00a0the\u00a0following\u00a0equation\r\n\u00a0\u00a0\/\/\u00a0float\u00a0lux\u00a0=\u00a0(((vis\u00a0-\u00a0vis_dark)\u00a0\/\u00a0visCountPerLux)\u00a0*\u00a0visCoeff\u00a0-\u00a0((ir\u00a0-\u00a0ir_dark)\u00a0\/\u00a0irCountPerLux)\u00a0*\u00a0irCoeff)\u00a0*\u00a0gainFactor\u00a0*\u00a0corrFactor;\r\n\u00a0\u00a0\r\n\u00a0\u00a0return\u00a0lux;\r\n}<\/pre>\r\n&nbsp;\r\n\r\n<\/div>\n<h4 class=\"wp-block-heading\">Example sketch 6 &#8211; Using two SI1145 modules<\/h4>\n<p>In the last example I would like to show how to control two SI1145 modules with a microcontroller. To achieve this, you first supply only one of the sensors with power, change its address and then switch the second one. Since the SI1145 draws less than 1mA of power, you can power it directly via an Arduino pin. Alternatively, you take a transistor as a switch.<\/p>\n<figure class=\"wp-block-image\"><a href=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Two_SI1145_wiring.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"503\" src=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Two_SI1145_wiring-1024x503.png\" alt=\"Circuit for two SI1145 modules\" class=\"wp-image-3809\" srcset=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Two_SI1145_wiring-1024x503.png 1024w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Two_SI1145_wiring-300x147.png 300w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Two_SI1145_wiring-768x377.png 768w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Two_SI1145_wiring-1320x649.png 1320w, https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Two_SI1145_wiring.png 1506w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption>Circuit for two SI1145 modules<\/figcaption><\/figure><div class=\"scroll-paragraph-long\">\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-group=\"SI1145_using_two_sensors.ino\" data-enlighter-title=\"SI1145_using_two_sensors.ino\">#include &lt;SI1145_WE.h&gt;\r\n#include &lt;Wire.h&gt;\r\nconst int sensor2EnablePin = 10;\r\n\r\nSI1145_WE sensor1 = SI1145_WE();\r\nSI1145_WE sensor2 = SI1145_WE();\r\n\/\/ You can also pass a Wire object like wire2:\r\n\/\/ SI1145_WE sensor1 = SI1145_WE(&wire2);\r\n\r\nvoid setup() {\r\n  pinMode(sensor2EnablePin, OUTPUT);\r\n  Serial.begin(9600);\r\n  Wire.begin();\r\n  sensor1.init();\r\n  sensor1.setI2CAddress(0x59); \/\/ change from 0x60 to 0x59\r\n  digitalWrite(sensor2EnablePin, HIGH);\r\n  sensor2.init(); \/\/ gets the standard address 0x60\r\n  \r\n  sensor1.enableMeasurements(ALS_TYPE, AUTO);\r\n  sensor2.enableMeasurements(ALS_TYPE, AUTO);\r\n  \r\n  Serial.println(\"SI1145 - using two sensors\");\r\n}\r\n\r\nvoid loop() {\r\n  byte failureCode = 0;\r\n  unsigned int amb1_als = 0, amb2_als = 0;\r\n   \r\n  amb1_als = sensor1.getAlsVisData();\r\n  amb2_als = sensor2.getAlsVisData();\r\n\r\n  Serial.print(\"Ambient Light Sensor 1: \");\r\n  Serial.println(amb1_als);\r\n\r\n  Serial.print(\"Ambient Light Sensor 2: \");\r\n  Serial.println(amb2_als);\r\n \r\n  Serial.println(\"---------\");\r\n  delay(1000);\r\n}<\/pre>\r\n&nbsp;\r\n\r\n<\/div>\n<h2 class=\"wp-block-heading\">Acknowledgement<\/h2>\n<p>I would like to thank <a href=\"https:\/\/www.adafruit.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">Adafruit<\/a> for the <a href=\"https:\/\/github.com\/adafruit\/Fritzing-Library\/blob\/master\/parts\/Adafruit%20SI1145%20Digital%20UV%20Index%20%2B%20IR%20%2B%20Visible%20Light%20Sensor.fzpz\" target=\"_blank\" rel=\"noopener noreferrer\">Fritzing scheme<\/a> for the SI1145.<\/p>","protected":false},"excerpt":{"rendered":"<p>I present my library for the SI1145 module. The essential functions of the SI1145 have been implemented. Example sketches are explained in detail.<\/p>\n","protected":false},"author":1,"featured_media":8221,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[573,572],"tags":[910,801,903,911,895],"class_list":["post-9543","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-distance-light-movement","category-sensors","tag-lux-calculation","tag-proximity-detection-en","tag-si1145-en-2","tag-si1145-library","tag-uv-index-en"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SI1145 ALS, IR, UV and PS sensor &#8226; Wolles Elektronikkiste<\/title>\n<meta name=\"description\" content=\"I present my library for the SI1145 module. The essential functions of the SI1145 have been implemented. Example \u2070sketches are explained in detail.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SI1145 ALS, IR, UV and PS sensor &#8226; Wolles Elektronikkiste\" \/>\n<meta property=\"og:description\" content=\"I present my library for the SI1145 module. The essential functions of the SI1145 have been implemented. Example \u2070sketches are explained in detail.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor\" \/>\n<meta property=\"og:site_name\" content=\"Wolles Elektronikkiste\" \/>\n<meta property=\"article:published_time\" content=\"2020-11-14T11:02:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-05-16T08:39:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Beitragsbild_klein.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1002\" \/>\n\t<meta property=\"og:image:height\" content=\"1002\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Wolfgang Ewald\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Wolfgang Ewald\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor\"},\"author\":{\"name\":\"Wolfgang Ewald\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\"},\"headline\":\"SI1145 ALS, IR, UV and PS sensor\",\"datePublished\":\"2020-11-14T11:02:54+00:00\",\"dateModified\":\"2021-05-16T08:39:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor\"},\"wordCount\":2158,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\"},\"image\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/Beitragsbild_klein.jpg\",\"keywords\":[\"Lux calculation\",\"Proximity detection\",\"SI1145\",\"SI1145 library\",\"UV index\"],\"articleSection\":[\"Distance, light, movement\",\"Sensors\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor\",\"name\":\"SI1145 ALS, IR, UV and PS sensor &#8226; Wolles Elektronikkiste\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/Beitragsbild_klein.jpg\",\"datePublished\":\"2020-11-14T11:02:54+00:00\",\"dateModified\":\"2021-05-16T08:39:13+00:00\",\"description\":\"I present my library for the SI1145 module. The essential functions of the SI1145 have been implemented. Example \u2070sketches are explained in detail.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor#primaryimage\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/Beitragsbild_klein.jpg\",\"contentUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/11\\\/Beitragsbild_klein.jpg\",\"width\":1002,\"height\":1002},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\\\/si1145-als-ir-uv-und-ps-sensor#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Startseite\",\"item\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SI1145 ALS, IR, UV and PS sensor\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#website\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en\",\"name\":\"Wolles Elektronikkiste\",\"description\":\"Die wunderbare Welt der Elektronik\",\"publisher\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/en#\\\/schema\\\/person\\\/b774e4d64b4766889a2f7c6e5ec85b46\",\"name\":\"Wolfgang Ewald\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\",\"url\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\",\"contentUrl\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\",\"width\":512,\"height\":512,\"caption\":\"Wolfgang Ewald\"},\"logo\":{\"@id\":\"https:\\\/\\\/wolles-elektronikkiste.de\\\/wp-content\\\/uploads\\\/2019\\\/03\\\/cropped-Logo-1.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SI1145 ALS, IR, UV and PS sensor &#8226; Wolles Elektronikkiste","description":"I present my library for the SI1145 module. The essential functions of the SI1145 have been implemented. Example \u2070sketches are explained in detail.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor","og_locale":"en_US","og_type":"article","og_title":"SI1145 ALS, IR, UV and PS sensor &#8226; Wolles Elektronikkiste","og_description":"I present my library for the SI1145 module. The essential functions of the SI1145 have been implemented. Example \u2070sketches are explained in detail.","og_url":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor","og_site_name":"Wolles Elektronikkiste","article_published_time":"2020-11-14T11:02:54+00:00","article_modified_time":"2021-05-16T08:39:13+00:00","og_image":[{"width":1002,"height":1002,"url":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Beitragsbild_klein.jpg","type":"image\/jpeg"}],"author":"Wolfgang Ewald","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Wolfgang Ewald","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor#article","isPartOf":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor"},"author":{"name":"Wolfgang Ewald","@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46"},"headline":"SI1145 ALS, IR, UV and PS sensor","datePublished":"2020-11-14T11:02:54+00:00","dateModified":"2021-05-16T08:39:13+00:00","mainEntityOfPage":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor"},"wordCount":2158,"commentCount":0,"publisher":{"@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46"},"image":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor#primaryimage"},"thumbnailUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Beitragsbild_klein.jpg","keywords":["Lux calculation","Proximity detection","SI1145","SI1145 library","UV index"],"articleSection":["Distance, light, movement","Sensors"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor#respond"]}]},{"@type":"WebPage","@id":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor","url":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor","name":"SI1145 ALS, IR, UV and PS sensor &#8226; Wolles Elektronikkiste","isPartOf":{"@id":"https:\/\/wolles-elektronikkiste.de\/en#website"},"primaryImageOfPage":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor#primaryimage"},"image":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor#primaryimage"},"thumbnailUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Beitragsbild_klein.jpg","datePublished":"2020-11-14T11:02:54+00:00","dateModified":"2021-05-16T08:39:13+00:00","description":"I present my library for the SI1145 module. The essential functions of the SI1145 have been implemented. Example \u2070sketches are explained in detail.","breadcrumb":{"@id":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor#primaryimage","url":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Beitragsbild_klein.jpg","contentUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/11\/Beitragsbild_klein.jpg","width":1002,"height":1002},{"@type":"BreadcrumbList","@id":"https:\/\/wolles-elektronikkiste.de\/en\/si1145-als-ir-uv-und-ps-sensor#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Startseite","item":"https:\/\/wolles-elektronikkiste.de\/en"},{"@type":"ListItem","position":2,"name":"SI1145 ALS, IR, UV and PS sensor"}]},{"@type":"WebSite","@id":"https:\/\/wolles-elektronikkiste.de\/en#website","url":"https:\/\/wolles-elektronikkiste.de\/en","name":"Wolles Elektronikkiste","description":"Die wunderbare Welt der Elektronik","publisher":{"@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/wolles-elektronikkiste.de\/en?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/wolles-elektronikkiste.de\/en#\/schema\/person\/b774e4d64b4766889a2f7c6e5ec85b46","name":"Wolfgang Ewald","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png","url":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png","contentUrl":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png","width":512,"height":512,"caption":"Wolfgang Ewald"},"logo":{"@id":"https:\/\/wolles-elektronikkiste.de\/wp-content\/uploads\/2019\/03\/cropped-Logo-1.png"}}]}},"_links":{"self":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts\/9543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/comments?post=9543"}],"version-history":[{"count":0,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/posts\/9543\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/media\/8221"}],"wp:attachment":[{"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/media?parent=9543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/categories?post=9543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wolles-elektronikkiste.de\/en\/wp-json\/wp\/v2\/tags?post=9543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}