Overview
In this project, we will make an IoT ESP8266 Based Lux Meter or Light Meter using BH1750 Ambient Light Sensor & monitor it on Blynk Application. Using this sensor we can calculate the amount of light in lux units and check the brightness of the surrounding light. This sensor has a wide range of applications and can be used to adjust the LCD brightness on the Mobile Phone by detecting the environmental light. It can also be used to turn ON/OFF Street Lights based on darkness.
Earlier, we made Lux/light Meter using BH1750 Sensor & Arduino. We also made Solar Irradiance Meter. The Light Intensity in lux is displayed on a 16×2 LCD Display. Now instead of LCD Display, we will send the data to Blynk Application. Using the Blynk application, we can monitor the Light intensity of a particular location from anywhere in the world. For that, we need to use some hardware like NodeMCU ESP8266 & BH1750 Ambient Light Sensor Module.
Bill of Materials
The components required for this project are as follows. All the components can be easily purchased from Amazon.
| S.N. | Components Name | Quantity | Purchase Links |
|---|---|---|---|
| 1 | NodeMCU ESP8266 Board | 1 | Amazon | AliExpress |
| 2 | BH1750 Ambient Light Sensor | 1 | Amazon | AliExpress |
| 3 | Connecting Wires | 10 | Amazon | AliExpress |
| 4 | Breadboard | 1 | Amazon | AliExpress |
BH1750 Ambient Light Sensor
This is a BH1750 light intensity sensor breakout board that is a digital Ambient Light Sensor IC with an I2C bus interface. This IC is best suited to get the ambient light data in mobile phones to manipulate the screen brightness based on the environment lighting. This sensor can accurately measure the LUX value of light up to 65535. It consumes a very low amount of current & uses a photodiode to sense the light.
BH1750 works with a supply voltage of 2.4V to 3.6V. BH1750FVI is the main module of the sensor which requires 3.3V for working. So, a voltage regulator is used in the circuit. SDA and SCL are the pins used for I2C communication with the I2C address 0x23. 4.7kΩ of pullup resistors are used with these pins.
BH1750 NodeMCU ESP8266 Circuit Diagram
Now, let us interface the BH1750 Ambient Light Sensor with NodeMCU ESP8266 Board. The connection is fairly simple. Connect the I2C Pin of BH1750, i.e. SDA & SCL to D1 & D2 of NodeMCU Board Respectively.
Connect the 3.3V pin of BH1750 to NodeMCU 3.3V pin & GND to GND. The circuit can be easily assembled on a breadboard as shown in the image below.
Blynk Application Setup
The IoT Based Lux Meter Project is incomplete without the Blynk Application. Blynk is designed for the Internet of Things. It can control hardware remotely, it can display sensor data, it can store data, visualize it, and do many other cool things.
Download and install the Blynk Application from Google Play Store. IOS users can download from the App Store. Once the installation is completed, open the app & sign-up using your Email id and Password.
Create your UI by dragging dropping and filling up details along with the virtual pin assignment. Once the UI is created, you can ask for the authentication Token by sending the mail. You will need the Authentication Token for the code.
Source Code/Program
The source code or program for IoT Lux Meter using BH1750 ESP8266 & Blynk is given below. You can upload this code to the NodeMCU Board. Before compiling the sketch, you need to add following library to the Arduino IDE.
- Download: Blynk Library
- Download: BH1750 Library
From the code part, change the wifi SSID, Password & Blynk Authentication Code.
|
1 2 3 |
char auth[] = "******************************"; char ssid[] = "******************************"; char pass[] = "******************************"; |
The complete code is given below.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
#include <Wire.h> // adds I2C library #include <BH1750.h> // adds BH1750 library file #define BLYNK_PRINT Serial #include <Blynk.h> #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> char auth[] = "_YONn2J3C8pxB1iIItsalCkS2diOjW9E"; // You should get Auth Token in the Blynk App. char ssid[] = "Alexahome"; // Your WiFi credentials. char pass[] = "loranthus"; BH1750 lightMeter; void setup() { Wire.begin(); Serial.begin(9600); Blynk.begin(auth, ssid, pass); lightMeter.begin(); } void loop() { Blynk.run(); float lux = lightMeter.readLightLevel(); Serial.print("Light Meter: "); Serial.print(lux); Serial.println(" lx"); Blynk.virtualWrite(V2, lux); delay(1000); } |
Monitoring Light Intensity in Blynk Application
Once the code is uploded, the NodeMCU Board will connect to the wifi using the assigned Wifi SSID & Password. Once, the Nodemcu connects to the Wifi, it will start uploading the data to Blynk Server.
You can monitor the Light Intensity data on the Blynk Application as shown in the image below.










