This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:hardware2:sensors_optical [2023/11/20 18:13] – ekontoturbo | en:iot-open:hardware2:sensors_optical [2023/11/23 10:38] (current) – pczekalski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Optical Sensors ====== | ====== Optical Sensors ====== | ||
| + | {{: | ||
| == Optocoupler == | == Optocoupler == | ||
| Line 27: | Line 27: | ||
| An example code: | An example code: | ||
| <code c> | <code c> | ||
| - | int optoPin = A0; // | + | int optoPin = A0; |
| - | int optoReading; | + | int optoReading; |
| int objecttreshold = 1000; //Object threshold definition | int objecttreshold = 1000; //Object threshold definition | ||
| - | int whitetreshold = 150; //White colour threshold definition | + | int whitetreshold = 150; |
| void setup () | void setup () | ||
| Line 89: | Line 89: | ||
| void setup(void) { | void setup(void) { | ||
| Serial.begin(9600); | Serial.begin(9600); | ||
| - | Wire.begin(5, | + | Wire.begin(5, |
| - | pinMode(21, OUTPUT); | + | pinMode(21, OUTPUT); |
| - | digitalWrite(21, | + | digitalWrite(21, |
| if (rgb_sensor.begin()) { // | if (rgb_sensor.begin()) { // | ||
| Serial.println(" | Serial.println(" | ||
| Line 103: | Line 103: | ||
| uint16_t r, g, b, unfiltered, lux; | uint16_t r, g, b, unfiltered, lux; | ||
| - | rgb_sensor.getRawData(& | + | rgb_sensor.getRawData(& |
| - | lux = rgb_sensor.calculateLux(r, | + | //read RGB and unfiltered light intensity |
| + | lux = rgb_sensor.calculateLux(r, | ||
| + | //calculate illuminance in Lux | ||
| Serial.print(" | Serial.print(" | ||