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]