BH1750 Lux Sensor Problems



  • 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


  • Hardware Contributor

    @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.



  • @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).


  • Hardware Contributor

    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



  • @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.



  • 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 !


Log in to reply
 

Suggested Topics

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts