In this post I will make a smart light sensor that we will later use to integrate with our IoT projects.
To do this, we will need the following items (if you wish to support us you can buy them using our referral links):
The BH1750 is a digital light sensor modules that uses I2C to communicate and provides a digital value in lux between 1 and 65535 lx. For full technical details please refer to the datasheet.
First we will have to connect the BH1750 Light sensor to the NodeMCU board as follows:
NodeMCU <-> BH1750
GND <-> GND
5V <-> VCC
D3 (gpio0) <-> SDA
D4 (gpio2) <-> SCL
Connect the microusb cable to WeMos/NodeMCU and open nodeMCU-flasher. In the first tab (Operation) select the COM port for your device. In the second tab (Config) select the Tasmota .bin file.
On the advanced tab, please make sure the settings are matching:
Click on “Flash” and get your phone ready .
When the upload is done, the board will create an access point for you to connect to. Search for a “sonoff-…” open wifi network and connect to it. Open your favorite browser and type http://192.168.4.1
You will get a wifi setup page as shown in the picture below. Enter your wifi network details and click save.
For further configuration you will have to find your device on your network. You can scan the entire network or take a look at the dhcp list on your router.
Once you find the local IP address of the device, you can connect to it from a browser and here you will get the configuration page.
Go to Configuration -> Configure Module page -> Change Module type to “18 Generic” and click Save.
Go to Configure Module page again and now you should be able to set as follows:
- Module Type : 18 Generic
- D3 GPIO0 : 06 I2C SDA
- D4 GPIO2 : 05 I2C SCL
Once the settings are saved and the device reboots, you should see the BH1750 Illuminance:
In this post we will learn how to use the device in a Node-RED workflow to alert us or perform an action as needed when the light value changes.