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/10/02 20:08] – pczekalski | en:iot-open:hardware2:sensors_optical [2023/11/23 10:38] (current) – pczekalski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ==== Optical Sensors ==== | + | ====== Optical Sensors |
| - | + | {{: | |
| - | ===Optocoupler=== | + | == Optocoupler == |
| An optocoupler is a device that combines light-emitting and receiving devices in one package. Mainly, it combines the infrared light-emitting diode (LED) and a phototransistor.\\ | An optocoupler is a device that combines light-emitting and receiving devices in one package. Mainly, it combines the infrared light-emitting diode (LED) and a phototransistor.\\ | ||
| 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 64: | Line 64: | ||
| </ | </ | ||
| - | ===Colour Sensor=== | + | == Colour Sensor == |
| This type of sensor gives information about the colour of the light illuminating the sensor surface. Because computers often use RGB (red, green, blue) colour schemes, the sensor returns three values representing the intensity of three components. Colour sensors usually contain white LEDs to illuminate the surface, which colour should be distinguished by them. The colour sensor uses an SPI or TWI interface to send readings. Some models of colour sensors include an additional gesture detector which recognises simple gestures (up, down, left, right).\\ | This type of sensor gives information about the colour of the light illuminating the sensor surface. Because computers often use RGB (red, green, blue) colour schemes, the sensor returns three values representing the intensity of three components. Colour sensors usually contain white LEDs to illuminate the surface, which colour should be distinguished by them. The colour sensor uses an SPI or TWI interface to send readings. Some models of colour sensors include an additional gesture detector which recognises simple gestures (up, down, left, right).\\ | ||
| The sample device is present in figure {{ref> | The sample device is present in figure {{ref> | ||
| <figure tcs1> | <figure tcs1> | ||
| - | {{ : | + | {{ : |
| < | < | ||
| </ | </ | ||
| - | <todo @pczekalski> | ||
| <figure tcs2> | <figure tcs2> | ||
| + | {{ : | ||
| < | < | ||
| </ | </ | ||
| Line 89: | Line 89: | ||
| void setup(void) { | void setup(void) { | ||
| Serial.begin(9600); | Serial.begin(9600); | ||
| + | Wire.begin(5, | ||
| + | pinMode(21, OUTPUT); | ||
| + | digitalWrite(21, | ||
| if (rgb_sensor.begin()) { // | if (rgb_sensor.begin()) { // | ||
| Serial.println(" | Serial.println(" | ||
| Line 101: | 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(" | ||