The BH1750 and BMP180 are popular sensors used to measure light intensity and atmospheric pressure, respectively. By combining these sensors with Arduino, you can create projects that monitor environmental conditions and respond to changes in light and pressure.
BH1750 Light Sensor
The BH1750 is a digital light sensor that provides precise measurements of ambient light intensity. It offers a wide measurement range and high sensitivity, making it suitable for various applications.
Hardware Setup
- Connect the VCC pin of the BH1750 to the 5V pin on the Arduino.
- Connect the GND pin of the BH1750 to the ground pin on the Arduino.
- Connect the SCL pin of the BH1750 to the SCL pin on the Arduino.
- Connect the SDA pin of the BH1750 to the SDA pin on the Arduino.
Arduino Code
C++
#include <Wire.h>
#define BH1750_ADDRESS 0x23
void setup() {
Wire.begin();
}
void loop() {
Wire.beginTransmission(BH1750_ADDRESS);
Wire.write(0x10); // Power-on mode
Wire.endTransmission();
delay(180);
Wire.beginTransmission(BH1750_ADDRESS);
Wire.write(0x12); // Read high/low byte data
Wire.endTransmission(false);
uint16_t data = Wire.read() << 8 | Wire.read();
float lux = (data * 1.2) / 1.05;
Serial.print("Light intensity: ");
Serial.print(lux);
Serial.println(" lux");
delay(1000);
}
BMP180 Barometric Sensor
The BMP180 is a digital barometric pressure sensor that provides accurate measurements of atmospheric pressure. It can also be used to calculate altitude and temperature.
Hardware Setup
- Connect the VCC pin of the BMP180 to the 5V pin on the Arduino.
- Connect the GND pin of the BMP180 to the ground pin on the Arduino.
- Connect the SCL pin of the BMP180 to the SCL pin on the Arduino.
- Connect the SDA pin of the BMP180 to the SDA pin on the Arduino.
Arduino Code
C++
#include <Wire.h>
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
void setup() {
Wire.begin();
if (!bmp.begin()) {
Serial.println("Could not find BMP085 sensor, check wiring.");
while (1);
}
}
void loop() {
float temperature = bmp.readTemperature();
float pressure = bmp.readPressure();
float altitude = bmp.readAltitude(SEALEVELPRESSURE_HPA);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Pressure: ");
Serial.print(pressure);
Serial.println(" Pa");
Serial.print("Altitude: ");
Serial.print(altitude);
Serial.println(" m");
delay(1000);
}