Hi folks,
can you help me out, getting started with a (hopefully) straight forward issue?
I have an Arduino Uno R3 and I've bought a BH1750 sensor and loaded a BH1750 library into the Arduino IDE (GitHub - claws/BH1750: An Arduino library for the digital light sensor breakout boards containing the BH1750FVI IC ). I followed the example code to test.
#include <Wire.h>
#include <BH1750.h>
BH1750 lightMeter;
void setup(){
Serial.begin(9600);
Wire.begin();
lightMeter.begin();
Serial.println(F("BH1750 Test"));
}
void loop() {
float lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);
}
Compiling and uploading results in the serial monitor outputting
16:12:11.182 -> [BHROR: received NACK on transmit of address
16:12:11.182 -> BH1750 Test
16:12:11.182 -> [BH1750] Device is not configured!
16:12:11.182 -> Light: -2.00 lx
I suspected the soldering at first (not pretty), but I don't think that is the issue - tested it with a multimeter. The wiring seems also correct.
I am new to this, and not sure what the next step is to find out what's wrong. Do you have any ideas?
Cheers, Georg
PaulRB
July 19, 2024, 2:24pm
2
Try running the i2c scanner sketch. You should find it somewhere in the IDE example sketch menus.
Just did that:
13:47:59.400 -> I2C Scanner
13:47:59.400 -> Scanning...
13:47:59.433 -> I2C device found at address 0x23 !
13:47:59.465 -> done
This seems the wanted result...
1 Like
I should add, that it's the GY302-module (no pull up resistors needed).
You need to call bool BH1750::configure(Mode mode)
Give this a try
void setup(){
Serial.begin(9600);
Wire.begin();
lightMeter.begin();
lightMeter.configure(BH1750::CONTINUOUS_HIGH_RES_MODE); // or one of the other modi.
Serial.println(F("BH1750 Test"));
}
void loop() {
float lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);
}
Options for mode
BH1750::CONTINUOUS_HIGH_RES_MODE:
BH1750::CONTINUOUS_HIGH_RES_MODE_2:
BH1750::CONTINUOUS_LOW_RES_MODE:
BH1750::ONE_TIME_HIGH_RES_MODE:
BH1750::ONE_TIME_HIGH_RES_MODE_2:
BH1750::ONE_TIME_LOW_RES_MODE:
You might give my BH1750 library a try, has some options that might be interesting.
PaulRB
July 20, 2024, 3:52pm
6
Try @robtillaart 's library and maybe one other like from Adafruit or Sparkfun.
If you have another Arduino or compatible, or a RPi of some kind, try those.
Then try re-soldering
If none of these ideas help, I think maybe you got a bad sensor.
Thanks to both of you!
While the initial hint (calling configure) had no effect, using @robtillaart 's library (example sketch) works.
I'm still a little confused as to why the other library didn't work, but very happy, to be up and running.
Thanks again!
1 Like
You can post your entire working sketch?
system
Closed
February 10, 2025, 2:25pm
9
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.