Skip to content

Commit

Permalink
updates to light sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
tigoe committed Feb 13, 2019
1 parent 4deb7b8 commit 5e2a86e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 11 additions & 1 deletion LightSensors/APDS9301_basic/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ Sparkfun has a decent[ APDS9301 library](https://github.com/sparkfun/APDS-9301_B

If you change the integration time setting the sketch will change the delay for when it reads the sensor accordingly. Changing the integration time will change the values you get on channels 0 and 1, but it shouldn't make a huge difference in the overall lux reading. That reading is based on the ratio of CH0 to CH1, as described on page 4 of the [APS9301 datasheet](https://cdn.sparkfun.com/assets/3/2/c/0/8/AV02-2315EN0.pdf).

If you change the gain settings, you should also see a change in the CH0 and CH1 readings, but not the overall lux reading.
If you change the gain settings, you should also see a change in the CH0 and CH1 readings, but not the overall lux reading.

The datasheet details the calculation of lux value based on the channel 0 and 1 levels, as follows (p. 4):

| CH1/CH0| Sensor Lux Formula|
|-----|-----|
| 0 < CH1/CH0 ≤ 0.50 | Sensor Lux = (0.0304 x CH0) – (0.062 x CH0 x ((CH1/CH0)<sup>1.4</sup>)) |
0.50 < CH1/CH0 ≤ 0.61 | Sensor Lux = (0.0224 x CH0) – (0.031 x CH1)|
0.61 < CH1/CH0 ≤ 0.80 | Sensor Lux = (0.0128 x CH0) – (0.0153 x CH1)|
0.80 < CH1/CH0 ≤ 1.30 | Sensor Lux = (0.00146 x CH0) – (0.00112 x CH1)|
CH1/CH0>1.30| Sensor Lux = 0|
8 changes: 5 additions & 3 deletions LightSensors/TCS34725_RGBSensor/TCS34725_RGBSensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_700MS, TCS347

void setup(void) {
Serial.begin(9600);
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
// start sensor:
while (!tcs.begin()) {
Serial.println("Looking for sensor...");
Expand All @@ -25,17 +27,17 @@ void setup(void) {
}

void loop(void) {
// every 2 seconds, read sensor:
// every 2 seconds, read sensor:
if (millis() % 2000 < 2) {
uint16_t r, g, b, c, colorTemp, lux;
tcs.getRawData(&r, &g, &b, &c);
colorTemp = tcs.calculateColorTemperature_dn40(r, g, b, c);
lux = tcs.calculateLux(r, g, b);
String reading = "CT: ";
reading += String(colorTemp);
reading += "\nLux: ";
reading += " Lux: ";
reading += lux;
reading += "R: " + String(r);
reading += " R: " + String(r);
reading += " G: " + String(g);
reading += " B: " + String(b);
Serial.println(reading);
Expand Down

0 comments on commit 5e2a86e

Please sign in to comment.