Garden light, humidity, temperature monitor with working SHT10 sensor 99% done and I need your help!



  • Hi everyone I am working on my latest project a garden soil humidity/temperature monitor and light sensor. The problem is I am stuck. I got the SHT10 sensor working flawlessly to report the soil humidity and temperature but the light sensor seems to report once when powered up then never again. Also it always seems to be the same value regardless of light conditions (54612 ). I am thinking my sketch is wrong as I am not the best programmer can some one check it for me please and tell me where i went wrong. Also photos of the project attached. at the bottom

    #include <SPI.h>
    #include <MySensor.h>
    #include "SHT1x.h"
    #include <BH1750.h>
    #include <Wire.h>
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define CHILD_ID_LIGHT 2
    #define dataPin 6
    #define sckPin 7 //serial clock

    unsigned long SLEEP_TIME = 30000;
    SHT1x th_sensor(dataPin, sckPin);
    float lastTemp;
    float lastHum;
    BH1750 lightSensor;
    MySensor gw;
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    MyMessage msg(CHILD_ID_LIGHT, V_LIGHT_LEVEL);
    boolean metric = true;
    uint16_t lastlux;
    void setup()
    {
    gw.begin();

    // Send the Sketch Version Information to the Gateway
    gw.sendSketchInfo("Humidity", "1.0");
    gw.sendSketchInfo("Light Lux Sensor", "1.0");

    // Register all sensors to gw (they will be created as child devices)
    gw.present(CHILD_ID_HUM, S_HUM);
    gw.present(CHILD_ID_TEMP, S_TEMP);
    gw.present(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
    lightSensor.begin();
    metric = gw.getConfig().isMetric;
    }

    void loop()
    {

    float temperature = th_sensor.readTemperatureF();

    if (isnan(temperature)) {
    Serial.println("Failed reading temperature");
    } else if (temperature != lastTemp) {
    lastTemp = temperature;
    if (!metric) {
    temperature = th_sensor.readTemperatureC();
    }
    gw.send(msgTemp.set(temperature, 1));
    Serial.print("T: ");
    Serial.println(temperature);
    }

    float humidity = th_sensor.readHumidity();
    if (isnan(humidity)) {
    Serial.println("Failed reading humidity");
    } else if (humidity != lastHum) {
    lastHum = humidity;
    gw.send(msgHum.set(humidity, 1));
    Serial.print("H: ");
    Serial.println(humidity);
    }
    uint16_t lux = lightSensor.readLightLevel();// Get Lux value
    Serial.println(lux);
    if (lux != lastlux) {
    gw.send(msg.set(lux));
    lastlux = lux;
    }

    gw.sleep(SLEEP_TIME); //sleep a bit

    }

    [URL=http://s1074.photobucket.com/user/ajachierno/media/20160719_1810421_zpsg1gccgpd.jpg.html][IMG]http://i1074.photobucket.com/albums/w405/ajachierno/20160719_1810421_zpsg1gccgpd.jpg[/IMG][/URL]

    [URL=http://s1074.photobucket.com/user/ajachierno/media/20160719_1810321_zpsa9tm5mp4.jpg.html][IMG]http://i1074.photobucket.com/albums/w405/ajachierno/20160719_1810321_zpsa9tm5mp4.jpg[/IMG][/URL]

    [URL=http://s1074.photobucket.com/user/ajachierno/media/20160719_1659381_zpsmaqne2x9.jpg.html][IMG]http://i1074.photobucket.com/albums/w405/ajachierno/20160719_1659381_zpsmaqne2x9.jpg[/IMG][/URL]

    [URL=http://s1074.photobucket.com/user/ajachierno/media/20160719_1657091_zpscjtpxuiu.jpg.html][IMG]http://i1074.photobucket.com/albums/w405/ajachierno/20160719_1657091_zpscjtpxuiu.jpg[/IMG][/URL]



  • @ajachierno said:

    Also it always seems to be the same value regardless of light conditions (54612 ). I am thinking my sketch is wrong

    Your sketch looks correct to me, but if the lux sensor is always reporting the same value, then it will only send the message once as you have seen. Are you sure the lux sensor is wired correctly?


  • Hardware Contributor

    Hello,

    first please use the code tags around your code it's easier to read, it's with the </> button at the right of the toolbar when you type your message.

    The code seems ok to me too, this value means there is a i2c communication problem with the sensor. So either your sensor is dead, or it is not correctly wired.

    What I would do :

    1. try the example from the BH1750 library to concentrate on the sensor readings and avoid any problem that could be related to MySensors. Just make the test with arduino + BH1750 sensor and nothing else.
    2. check (and double check :)) your wiring to the SDA / SCL pins
    3. if you still can't read a value connect the ADDR pin of the BH1750 board to GND and try again
    4. if you still can't read a value, now you are sure your sensor is correctly connected, try i2c scanner sketch, it will tell you if it finds any i2c devices on the i2c bus. If it fails to see your sensor then you can assume it's dead...

    http://playground.arduino.cc/Main/I2cScanner



  • Thank you Corbin and NCA78, I had assumed it was my code since I am not very good at it. However it turned out to be a bad sensor. I will post some additional information and pictures in the project section this evening now that everything is working. Thank you again for your help.


Log in to reply
 

Suggested Topics

55
Online

11.4k
Users

11.1k
Topics

112.7k
Posts