Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. BH1750 Lux Sensor Problems

BH1750 Lux Sensor Problems

Scheduled Pinned Locked Moved Troubleshooting
6 Posts 2 Posters 4.4k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Toine33
    wrote on last edited by
    #1

    Hey Guys,

    I am trying for an while now but i cant make it work.
    The problem is that when i use this sketch i cant get usable data out of the BH1750

    #define MY_DEBUG
    #define MY_RS485
    #define MY_RS485_DE_PIN 2
    #define MY_RS485_BAUD_RATE 19200
    #define MY_RS485_HWSERIAL Serial
    #define MY_NODE_ID 5
    
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <BH1750.h>
    #include <Wire.h>
    
    #define CHILD_ID_LIGHT 25
    unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
    
    BH1750 lightSensor;
    
    // V_LIGHT_LEVEL should only be used for uncalibrated light level 0-100%.
    // If your controller supports the new V_LEVEL variable, use this instead for
    // transmitting LUX light level.
    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    // MyMessage msg(CHILD_ID_LIGHT, V_LEVEL);  
    uint16_t lastlux;
    
    void setup()  
    { 
      lightSensor.begin();
    }
    
    void presentation()  {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Node 5", "1.0");
    
      // Register all sensors to gateway (they will be created as child devices)
      present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
    }
    
    void loop()      
    {     
      uint16_t lux = lightSensor.readLightLevel();// Get Lux value
      Serial.println(lux);
      if (lux != lastlux) {
          send(msg.set(lux));
          lastlux = lux;
      }
    
      wait(SLEEP_TIME);
    }
    

    The output i am receiving is 65534 LUX and it never changes..

    The weird part is when i use this sketch without changing wiring i am receiving good changing data like 110 Lux etc etc

    #include <Wire.h>
    #include <BH1750.h>
    
    BH1750 lichtMeter;
    
    void setup(){
      Serial.begin(9600);
      lichtMeter.begin();
    }
     
     
    void loop() {
      uint16_t lux = lichtMeter.readLightLevel();
      Serial.print("Licht: ");
      Serial.print(lux);
      Serial.println(" lux");
      delay(500);
    }
    
    #include <Wire.h>
    #include <BH1750.h>
     
    BH1750 lichtMeter;
     
    void setup(){
      Serial.begin(9600);
      lichtMeter.begin();
    }
     
     
    void loop() {
      uint16_t lux = lichtMeter.readLightLevel();
      Serial.print("Licht: ");
      Serial.print(lux);
      Serial.println(" lux");
      delay(500);
    }
    

    Hardware:
    Arduino nano - Node - RS485

    N 1 Reply Last reply
    0
    • T Toine33

      Hey Guys,

      I am trying for an while now but i cant make it work.
      The problem is that when i use this sketch i cant get usable data out of the BH1750

      #define MY_DEBUG
      #define MY_RS485
      #define MY_RS485_DE_PIN 2
      #define MY_RS485_BAUD_RATE 19200
      #define MY_RS485_HWSERIAL Serial
      #define MY_NODE_ID 5
      
      
      #include <SPI.h>
      #include <MySensors.h>
      #include <BH1750.h>
      #include <Wire.h>
      
      #define CHILD_ID_LIGHT 25
      unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
      
      BH1750 lightSensor;
      
      // V_LIGHT_LEVEL should only be used for uncalibrated light level 0-100%.
      // If your controller supports the new V_LEVEL variable, use this instead for
      // transmitting LUX light level.
      MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
      // MyMessage msg(CHILD_ID_LIGHT, V_LEVEL);  
      uint16_t lastlux;
      
      void setup()  
      { 
        lightSensor.begin();
      }
      
      void presentation()  {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Node 5", "1.0");
      
        // Register all sensors to gateway (they will be created as child devices)
        present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
      }
      
      void loop()      
      {     
        uint16_t lux = lightSensor.readLightLevel();// Get Lux value
        Serial.println(lux);
        if (lux != lastlux) {
            send(msg.set(lux));
            lastlux = lux;
        }
      
        wait(SLEEP_TIME);
      }
      

      The output i am receiving is 65534 LUX and it never changes..

      The weird part is when i use this sketch without changing wiring i am receiving good changing data like 110 Lux etc etc

      #include <Wire.h>
      #include <BH1750.h>
      
      BH1750 lichtMeter;
      
      void setup(){
        Serial.begin(9600);
        lichtMeter.begin();
      }
       
       
      void loop() {
        uint16_t lux = lichtMeter.readLightLevel();
        Serial.print("Licht: ");
        Serial.print(lux);
        Serial.println(" lux");
        delay(500);
      }
      
      #include <Wire.h>
      #include <BH1750.h>
       
      BH1750 lichtMeter;
       
      void setup(){
        Serial.begin(9600);
        lichtMeter.begin();
      }
       
       
      void loop() {
        uint16_t lux = lichtMeter.readLightLevel();
        Serial.print("Licht: ");
        Serial.print(lux);
        Serial.println(" lux");
        delay(500);
      }
      

      Hardware:
      Arduino nano - Node - RS485

      N Offline
      N Offline
      Nca78
      Hardware Contributor
      wrote on last edited by
      #2

      @toine33 said in BH1750 Lux Sensor Problems:

      V_LIGHT_LEVEL

      Hello, do you get this with the serial print or in your controler from MySensors ?

      Because the light level in Lux should be with a V_LEVEL message and not V_LIGHT_LEVEL which expects a value from 0 to 100%. This could mess with the value reported on the controller side.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Toine33
        wrote on last edited by
        #3

        @Nca78

        I have tried both and still no luck, the weird part is that it is working without the MySenors part.
        When i am adding Mysensors libary it stops working.
        The node can present itself succesfull on the gateway and also creates the child ID 25 (LUX Sensor).

        1 Reply Last reply
        0
        • N Offline
          N Offline
          Nca78
          Hardware Contributor
          wrote on last edited by
          #4

          I'm not familiar at all with RS485 but are your sure this is not messing up with the MY_DEBUG and the Serial.println() in the code ?

          @toine33 said in BH1750 Lux Sensor Problems:

          #define MY_RS485_HWSERIAL Serial

          T 1 Reply Last reply
          0
          • N Nca78

            I'm not familiar at all with RS485 but are your sure this is not messing up with the MY_DEBUG and the Serial.println() in the code ?

            @toine33 said in BH1750 Lux Sensor Problems:

            #define MY_RS485_HWSERIAL Serial

            T Offline
            T Offline
            Toine33
            wrote on last edited by
            #5

            @nca78

            I Realy have no clue at the moment, i have tried almost everything for what i can think of.
            Also removed the serial print but still no luck.
            For the rest of the node's i never had issues.

            I have tried different sensors / Different arduino's but as soon when i am activating the mysensors part it stops responding.

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Toine33
              wrote on last edited by
              #6

              I guess i found it now,
              Looks like that V_LEVEL and V_LIGHT_LEVEL are both not behaving as expected,
              I have changed these now to V_TEXT after that the sensors was finaly working within domoticz.

              Also i had some cabeling issues, looks like the sensor doesnt like an cable length off 2 meter on 4x 0,44mm2 wire..
              Tommorow i am going to place the arduino closer to the weather station and i guess everything would be fine again then !

              Here my latest sketch:

              #define MY_DEBUG
              #define MY_RS485
              #define MY_RS485_DE_PIN 2
              #define MY_RS485_BAUD_RATE 19200
              #define MY_RS485_HWSERIAL Serial
              #define MY_NODE_ID 5
              
              
              #include <MySensors.h>  
              #include <BH1750.h>
              #include <Wire.h>
              
              #define CHILD_ID_LIGHT 25
              unsigned long SLEEP_TIME = 25000; // Sleep time between reads (in milliseconds)
              
              BH1750 lightSensor;
              
              // V_LIGHT_LEVEL should only be used for uncalibrated light level 0-100%.
              // If your controller supports the new V_LEVEL variable, use this instead for
              // transmitting LUX light level.
              // MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
              MyMessage msg(CHILD_ID_LIGHT, V_TEXT);  
              uint16_t lastlux;
              
              void setup()  
              { 
                lightSensor.begin();
              }
              
              void presentation()  {
                // Send the sketch version information to the gateway and Controller
                sendSketchInfo("Node 5", "1.0");
              
                // Register all sensors to gateway (they will be created as child devices)
                present(CHILD_ID_LIGHT, S_BINARY);
              }
              
              void loop()      
              {     
                uint16_t lux = lightSensor.readLightLevel();// Get Lux value
               // Serial.println(lux);
               // if (lux != lastlux) {
                    send(msg.set(lux));
                   // lastlux = lux;
               // }
              
                wait(SLEEP_TIME);
              }
              

              @Nca78
              Thanks for your help !

              1 Reply Last reply
              1

              Hello! It looks like you're interested in this conversation, but you don't have an account yet.

              Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

              With your input, this post could be even better 💗

              Register Login
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              30

              Online

              12.1k

              Users

              11.2k

              Topics

              113.4k

              Posts


              Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • MySensors
              • OpenHardware.io
              • Categories
              • Recent
              • Tags
              • Popular