/*
Arduino | hardware-help
2x BH1750 on the same card
PneusCrevés [CHEM] - Monday, May 18, 2026 9:16 AM
Hello, i have a project and i need some help.
I need to control the opacity of a window (ITO glass with a
Prussian blue coating for the curious) and i want to use BH1750 sensors.
The principle is simple (but I am a beginner):
one sensor measures the outside light level (Lo) and
the other the inside light level (Li).
The user then turns the potentiometer to allow the desired amount
of light to pass through (between 0% and 90%) by sending a
voltage (between 0 and 2V) inside the glass.
Also, i would like the display module to show both the external
brightness (Lo) and the brightness calculated by multiplying
the potentiometer value (percentage) by Lo.
I2C scanner from:
https://learn.adafruit.com/scanning-i2c-addresses/arduino
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const long LUMENS_OUTSIDE = 20000; // for test only, get value from BH1750
const int POT_PIN = A0;
const int VOUT_PIN = 3;
LiquidCrystal_I2C lcd(0x27, 16, 2);
void scanI2C() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for (address = 1; address < 127; address++ ) {
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address < 16) Serial.print("0");
Serial.print(address, HEX);
Serial.println(" !");
nDevices++;
} else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16) Serial.print("0");
Serial.println(address, HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
} else {
Serial.println("done\n");
}
}
void showSplash() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Lumen Controller");
lcd.setCursor(5, 1);
lcd.print("V1.0.0");
Serial.println("Lumen Controller V1.00");
delay(2000);
lcd.clear();
}
void setup() {
Wire.begin();
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(VOUT_PIN, OUTPUT);
scanI2C();
showSplash();
}
void loop() {
char loBuffer[16];
char liBuffer[16];
char potBuffer[16];
int rawPotVal = analogRead(POT_PIN);
int percentValue = map(rawPotVal, 0, 1023, 0, 90);
int pwmValue = map(rawPotVal, 0, 1023, 0, 255);
snprintf(potBuffer, 16, "%3d%%", percentValue);
lcd.setCursor(12, 1);
lcd.print(potBuffer);
long loValue = LUMENS_OUTSIDE; // do measurement here
snprintf(loBuffer, 16, "Lo:%6ld lm", loValue);
lcd.setCursor(0, 0);
lcd.print(loBuffer);
long liValue = loValue * percentValue * 0.01; // for test
snprintf(liBuffer, 16, "Li:%6ld lm", liValue);
lcd.setCursor(0, 1);
lcd.print(liBuffer);
analogWrite(VOUT_PIN, pwmValue);
}
Set
PWM to 0 - 2v control