Zonnestroompanelen in Nederland

duurzaamheid achter de meter

(36) Photometry via the Internet: BH1750 and Wemos D1 mini ESP 8266

Introduction
This paper deals with building an IOT (Internet of Things) photometer which measures the amount of sunlight energy received per square meter and reports at intervals to a server on the internet. Slightly deeper into detail: we apply here a BH1750 photometric sensor mounted on an I2C breakout board. This makes it easy to wire the sensor to a Wemos D1 mini microcontroller board. The latter has an ESP8266 chip on board that connects at intervals via the home wifi network – router to a server at thingspeak.com where data are stored in a private area (channel). Via the internet browser on any smartphone, tablet or computer the live and logged data in the channel can be approached. Data can be downloaded. The concept is shown in figure 1.

Figure 1: Concept of the IOT photometer system. A BH1750 photometer sensor measures luminance. Data are processed by the Wemos D1 mini, displayed and sent via a wifi connection to a server on the internet. The smartphone, or a tablet or pc is used to display the data graphically.

Because the dimensions of all the components are modest the assembled photometer-microcontroller-display fits a box with modest dimensions.

Materials and electronics required for construction
1x BH1750 I2C breakout board, 1x Wemos D1 mini ESP8266 microcontroller board, 1x TM1637 4-character, 7-segment led display breakout board, 2x 4.7 kΩ resistor, 1x 7×5 cm prototyping board (PCB), pin headers, 2x 2-pin JST connector sockets, 2x 2-pin JST male terminal wires (micro JST type for connecting the 7-segment display to the main assembly), wire, 5V micro usb power supply, housing box.

Figure 2: Lineup of the main components of the BH1750 internet photometer. The box is a water resistant outdoor electrical junction box. It has a transparent lid that is better visible in figure 4. The JST connectors and the usb power supply are not shown. The BH1750 and the Wemos D1 are mounted on pin headers soldered onto the PCB.

Construction
The BH1750 I2C breakout board has five pins, marked Vcc (power supply; 3.3V), GND, SCL, SDA and ADDR. The ADDR pin is not used in the current project.
Because the breakout board uses the I2C protocol wiring it to the Wemos D1 mini is very easy. Vcc is connected with the 3.3V pin of the Wemos (note that all I2C sensors are 3.3V devices), GND goes to GND, while the SCL and SDA pins are connected to pins D1 and D2 of the Wemos, respectively (fig. 3). Pull-up resistors with a value of 4.7 kΩ are soldered on the PCB between SCL and 3.3V and between SDA and 3.3V (they are visible in figure 3A; compulsory only when multiple I2C devices are connected to an Arduino type board). That is all, and the sensor is now ready for implementation. In the present construction the BH1750 breakout board is mounted on a pin header. This solution facilitates replacement. Also the Wemos D1 mini is mounted on a pin header ‘cradle’ on the PCB. By contrast the 7-segment display is mounted with two nylon nuts onto a strip of flexible plastic which, in turn, is loosely fastened to the box with two screws. To achieve maximal flexibility, JST terminal wires are soldered to the four pins of the displays’ breakout board while two female JST sockets are positioned on the PCB board (see for final assembly figure 4). Care is taken that pin CLK of the display be connected to pin D7 of the Wemos and pin DIO of the display to D6 of the Wemos (figure 3).

Figure 3: Wiring diagram. The SCL and SDA pins of the BH1750 are wired to, respectively D1 and D2 of the Wemos mini. Pins CLK and DIO of the 7-segment led display are wired to pins D7 and D6 of the D1 mini, respectively. Note the pull up resistors on pins SCL and SDA of the BH1750 breakout board.

Figure 4: Construction and assembly into the box. A. Wemos D1 and BH1750 photometer in position. The JST connectors marked ‘1’ and ‘2’ are soldered in place (‘1’ = Vcc and GND; ‘2’ = DIO and CLK). Note the pull up resistors center left on the PCB. This assembly is fully functional. B, the 7-segment display and the green led are in fact ‘functional decorations’ to inform the owner that the assembly is active. Note the ‘shader’, a piece of styrofoam placed between the BH1750 and the other components to shield the BH1750 sensor from light generated by the led, Wemos and display. The only screws used are the silver screws left and right to the display that keep it in position. The display presses against the transparent lid. The PCB is kept in place by the two pillars, the usb cable and the plastic strip with the 7-segment display.

Results and discussion
The photometer produces a stream of luminance data and reports/logs to a channel on Thingspeak.com. On my smartphone, tablet or pc I can check the current solar irradiation any time during the day or week. One argument to outsource data logging to the internet is the easiness. Stored data files can be downloaded any time on any platform in comma delimited format (csv), and imported into and processed in any spreadsheet that supports csv.
The primary output of the BH1750 sensor is in Lux. Lux is expressed in lumen per square meter. Lumen is the measure for luminous energy per unit of time. If you divide the luminous energy by 683.0 an approximation is obtained of the amount of energy (expressed in Watts) per surface unit (square meter). This value holds only for light with a wavelength of 555 nm. Yet the W/m2 unit calculated from the luminance is a valuable unit because the goal of the current project is to compare general illumination with the output of my solar panels,no more or less than that. I get with the photometer a rough indication how much sunshine there has been on a particular day. The real production of the solar panels (kWh/day) is reported by the software embedded in the solar grid tie inverters that convert the DC power delivered by the panels into AC to feed that into the public grid. My solar panels produce a certain amount of Watts for each square meter of panel surface, depending of the amount of sunshine they receive at that moment.
In a previous report I compared the output of the BH1750 with that of the kWh meter attached to my solar panels. In that report I used a NodeMCU microcontroller board. The Wemos D1 mini in the present construction is fully pin compatible with the NodeMCU although is is much smaller while for that matter the designers have sacrificed some pins. The very small footprint of a Wemos D1 mini, together with its power as a IOT device and programmability via the Arduino IDE, make this microcontroller board irresistible to the experimenter.
Software for this project was developed first on an Arduino Nano, then transferred to NodeMCU ESP8266 and finally copied to the Wemos D1 mini. A sketch is attached to this paper. Because the green led on the board interfered with the blue built-in led of the Wemos, flashing of the green led – originally designed to occur when data is being transmitted to Thingspeak – is not implemented in the current sketch

The availability of the Wemos D1 mini made it possible to construct the photometer inside a modestly dimensioned box, which here is a weatherproof outdoor electrical equipment box with transparent lid, dimensions 100x100x50 mm. There are two openings to allow cables runing through; one of these openings accomodates the 5V usb power supply while the other is plugged.

Figure 5. Various ways of displaying data at the http://www.thingspeak.com website. Plots of the last approximate 50 data points (‘actual’) or of data (Lux) acquired during a longer period (‘few days back’). The most recent reported luminance can be displayed on a gauge-like widget. Every 5 minutes a sample (equal to the averaged measurements taken during the previous interval is reported by the Wemos to the Thingspeak server.

Conclusion
The BH1750 is a sensor that is easy to implement in the Wemos D1 mini environment. It measures light approximately the same way as the human eye does. For that matter I use this sensor as a nice, yet qualitative, indicator for the amount of light available, in my case sunshine, the feedstock for my solar panels. The photometer sits in a weatherproof casing and as such can be used – with some precautions – outdoors.

Sketch: Wemos_BH_1750_7_seg_TM1637_display_wifi.ino (zipped file)

References:
Floris Wouterlood – Exploring the Internet of Things with a NodeMCU ESP8266 microcontroller board and a photometric sensor. TheSolarUniverse, November 17, 2017