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 14:15] – 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. |
| - | + | 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; external objects can obstruct light 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 can obstruct light 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 **reflective pair configuration**, | * a **reflective pair configuration**, | ||
| - | \\ | + | |
| - | < | + | A symbol, sample optocoupler and its connection to the microcontroller are present in figures {{ref> |
| + | < | ||
| {{ : | {{ : | ||
| < | < | ||
| </ | </ | ||
| - | < | + | < |
| {{ : | {{ : | ||
| < | < | ||
| </ | </ | ||
| - | < | + | < |
| {{ : | {{ : | ||
| < | < | ||
| Line 25: | 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 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 schemes 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> | ||
| - | < | + | < |
| - | {{ : | + | {{ : |
| < | < | ||
| </ | </ | ||
| - | <todo @pczekalski>add schematic, replace image</todo> | + | |
| + | <figure tcs2> | ||
| + | {{ : | ||
| + | < | ||
| + | </figure> | ||
| <code c> | <code c> | ||
| #include < | #include < | ||
| 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(" | ||