The BH1750 fails to be configured

34 Views Asked by At

I am using a Nodemecu8266 and I wanted to use the BH1750 along with it. I tried all the possible connections and it gives me the same error eveyrtime. I also imported the library. There is something wrong with the configuration "[BH1750] Device is not configured!. Light Intensity: -2.00" This is my code:

 #include <ESP8266WiFi.h>
 #include <Wire.h>
 #include <BH1750.h>

 // WiFi credentials const char* ssid = "network"; const char* password
 = "mypassword";
 
 // Analog pin connected to the pH sensor const int pH_pin = A0;
 
 // Create an instance of the BH1750 class BH1750 lightSensor;
 
 void setup() {   Serial.begin(9600);
 
      // Connect to WiFi   WiFi.begin(ssid, password);
      Serial.println("Connecting to WiFi...");   while (WiFi.status() != WL_CONNECTED) {
     delay(1000);
     Serial.println("Connecting...");   }   Serial.println("Connected to WiFi");
 
   // Initialize the BH1750 sensor   lightSensor.begin(); }
 
 void loop() {   // Read analog pH value   int pH_value =
 analogRead(pH_pin);
      // Convert analog value to pH   float pH = analogToPH(pH_value);
      // Print pH value to serial monitor   Serial.print("pH Value: ");   Serial.println(pH);
 
   // Read light intensity   float lightIntensity =
 lightSensor.readLightLevel();

   // Print light intensity to serial monitor   Serial.print("Light
 Intensity: ");   Serial.println(lightIntensity);
      delay(1000); // Delay for stability, adjust as needed }

 float analogToPH(int analogValue) {   // You need to calibrate this
 function based on your sensor's characteristics   // This is a simple
 linear approximation, you may need a more sophisticated method
      float pH = map(analogValue, 0, 1023, 0, 14); // Assuming pH range is 0-14   return pH; }
0

There are 0 best solutions below