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/07/06 16:38] – ktokarz | 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. |
| - | + | There are three main types of optocouplers: | |
| - | An optocoupler is a device that combines light-emitting and receiving devices in one package. | + | |
| * an **optocoupler of a closed pair configuration** is enclosed in the dark resin and is used to transfer signals using light. This type of optocoupler is not a sensor itself but is used for ensuring electrical isolation between two circuits; | * an **optocoupler of a closed pair configuration** is enclosed in the dark resin and is used to transfer signals using light. This type of optocoupler is not a sensor itself but is used for ensuring electrical isolation between two circuits; | ||
| - | * a **slotted optocoupler** has an open space between the light source and the sensor, light can be obstructed by external objects and thus can influence the sensor signal. It can be used to detect the presence of flat objects, measure rotation speed, vibrations or serve as a bounce-free switch; | + | * a **slotted optocoupler** has an open space between the light source and the sensor; external objects |
| - | * a **reflective pair configuration** the light signal is perceived as a reflection from the object surface. This configuration is used for proximity detection, surface colour detection and tachometer. | + | * a **reflective pair configuration**, the light signal is perceived as a reflection from the object' |
| - | < | + | A symbol, sample optocoupler and its connection to the microcontroller are present in figures {{ref> |
| - | {{ : | + | < |
| - | < | + | {{ : |
| + | < | ||
| </ | </ | ||
| - | < | + | < |
| - | {{ : | + | {{ : |
| - | < | + | < |
| </ | </ | ||
| - | < | + | < |
| - | {{ : | + | {{ : |
| - | < | + | < |
| </ | </ | ||
| 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 35: | Line 37: | ||
| //Begin serial communication | //Begin serial communication | ||
| Serial.begin(9600); | Serial.begin(9600); | ||
| - | //Initialize | + | //Initialise |
| pinMode(optoPin, | pinMode(optoPin, | ||
| } | } | ||
| Line 62: | 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 | + | 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 |
| + | The sample device is present in figure {{ref> | ||
| - | < | + | < |
| - | {{ : | + | {{ : |
| - | < | + | < |
| + | </ | ||
| + | |||
| + | <figure tcs2> | ||
| + | {{ : | ||
| + | < | ||
| </ | </ | ||
| Line 81: | 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 93: | 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(" | ||