GY-302 BH1750 Light Intensity Module Documentation
The GY-302 BH1750 Light Intensity Module is a digital light sensor module that measures the ambient light intensity in lux. It is based on the BH1750FVI, a digital ambient light sensor from Rohm Semiconductor. The module provides a simple way to measure light intensity in various applications, including IoT projects, robotics, and home automation.
Measures light intensity in lux (0-65535 lux)
Digital output via I2C interface
Adjustable measurement resolution (1-128 lux) and measurement time (50-200 ms)
Low power consumption (3.5 A typical)
Operating voltage: 2.4-5.5 V
VCC: Power supply (2.4-5.5 V)
GND: Ground
SCL: I2C clock line
SDA: I2C data line
ADDR: I2C address selection pin (default: 0x23)
### Example 1: Basic Light Intensity Measurement (Arduino)
This example demonstrates how to use the GY-302 BH1750 Light Intensity Module with an Arduino board to measure the ambient light intensity.
```c++
#include <Wire.h>
#define BH1750_ADDRESS 0x23
void setup() {
Serial.begin(9600);
Wire.begin();
}
void loop() {
uint16_t lux = readLightIntensity();
Serial.print("Light Intensity: ");
Serial.print(lux);
Serial.println(" lux");
delay(1000);
}
uint16_t readLightIntensity() {
Wire.beginTransmission(BH1750_ADDRESS);
Wire.write(0x00); // Command to start measurement
Wire.endTransmission();
Wire.requestFrom(BH1750_ADDRESS, 2);
uint16_t lux = Wire.read() << 8 | Wire.read();
return lux;
}
```
### Example 2: IoT Application with ESP32 and Wi-Fi (MicroPython)
This example demonstrates how to use the GY-302 BH1750 Light Intensity Module with an ESP32 board and MicroPython to send the measured light intensity to a remote server using Wi-Fi.
```python
import machine
import ubinascii
from machine import I2C, Pin
import ujson
import wlan
# Initialize I2C and Wi-Fi
i2c = I2C(scl=machine.Pin(22), sda=machine.Pin(21))
wlan.connect('your_wifi_ssid', 'your_wifi_password')
# Define the GY-302 BH1750 module
bh1750 = I2C(BH1750_ADDRESS, freq=400000)
while True:
# Measure light intensity
bh1750.write(b'x00') # Command to start measurement
lux = bh1750.read(2, 'B')[0] << 8 | bh1750.read(2, 'B')[1]
# Create a JSON payload
payload = {'device_id': 'ESP32_BH1750', 'light_intensity': lux}
payload_json = ujson.dumps(payload)
# Send the payload to the remote server
url = 'http://your_remote_server.com/light_intensity'
headers = {'Content-Type': 'application/json'}
response = wlan.post(url, headers, payload_json)
print(response.json())
# Wait for 1 minute before taking the next measurement
machine.sleep(60000)
```
Note: Ensure you replace the placeholders (`your_wifi_ssid`, `your_wifi_password`, and `your_remote_server.com`) with your actual Wi-Fi credentials and remote server URL.