| Both sides previous revisionPrevious revisionNext revision | Previous revision |
| en:iot-open:hardware2:sensors_optical [2023/08/18 20:29] – pczekalski | en:iot-open:hardware2:sensors_optical [2023/11/23 10:38] (current) – pczekalski |
|---|
| ==== Optical Sensors ==== | ====== Optical Sensors ====== |
| | {{:en:iot-open:czapka_b.png?50| General audience classification icon }}{{:en:iot-open:czapka_e.png?50| General audience classification icon }}\\ |
| | == 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.\\ |
| | There are three main types of optocouplers: |
| An optocoupler is a device that combines light-emitting and receiving devices in one package. Mostly it is a combination of the infrared light-emitting diode (LED) and a phototransistor. There are three main types of optocouplers: | |
| * 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 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**, the light signal is perceived as a reflection from the object's 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's surface. This configuration is used for proximity detection, surface colour detection and tachometer. |
| |
| <figure label> | A symbol, sample optocoupler and its connection to the microcontroller are present in figures {{ref>optocoupler1}}, {{ref>optocoupler2}} and {{ref>optocoupler3}}. |
| {{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:optocoupler.jpg?75 | title}} | <figure optocoupler1> |
| | {{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:optocoupler.jpg?100 | Optocoupler symbol}} |
| <caption>An optocoupler symbol</caption> | <caption>An optocoupler symbol</caption> |
| </figure> | </figure> |
| |
| <figure label> | <figure optocoupler2> |
| {{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:elitr9909_c.jpg?100 | title}} | {{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:elitr9909_c.jpg?100 | ELITR9909 reflective optocoupler sensor}} |
| <caption>ELITR9909 reflective optocoupler sensor</caption> | <caption>ELITR9909 reflective optocoupler sensor</caption> |
| </figure> | </figure> |
| |
| <figure label> | <figure optocoupler3> |
| {{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:sch_apz_shemas_optocoupler.png?200 | title}} | {{ :en:iot-open:getting_familiar_with_your_hardware_rtu_itmo_sut:arduino_and_arduino_101_intel_curie:sch_apz_shemas_optocoupler.png?200 | Arduino Uno and optocoupler schematics}} |
| <caption>Arduino Uno and optocoupler schematics.</caption> | <caption>Arduino Uno and optocoupler schematics</caption> |
| </figure> | </figure> |
| |
| An example code: | An example code: |
| <code c> | <code c> |
| int optoPin = A0; //Initialize an analogue A0 pin for optocoupler | int optoPin = A0; //Initialize an analogue A0 pin for optocoupler |
| int optoReading; //The analogue value reading from the optocoupler | int optoReading; //The analogue value reading from the optocoupler |
| |
| int objecttreshold = 1000; //Object threshold definition | int objecttreshold = 1000; //Object threshold definition |
| int whitetreshold = 150; //White colour threshold definition | int whitetreshold = 150; //White colour threshold definition |
| |
| void setup () | void setup () |
| //Begin serial communication | //Begin serial communication |
| Serial.begin(9600); | Serial.begin(9600); |
| //Initialize the analogue pin of the optocoupler as an input | //Initialise the analogue pin of the optocoupler as an input |
| pinMode(optoPin, INPUT); | pinMode(optoPin, INPUT); |
| } | } |
| </code> | </code> |
| |
| ===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 scheme 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 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>tcs1}} and the connection circuit in figure {{ref>tcs2}}. |
| |
| <figure label> | <figure tcs1> |
| {{ :en:iot-open:hardware2:tcs34725.jpg?100 | title}} | {{ :en:iot-open:hardware2:20230925_114221_-_kopia.jpg?200 | TCS34725 RGB colour sensor module}} |
| <caption>TCS34725 RGB colour sensor module./caption> | <caption>TCS34725 RGB colour sensor module</caption> |
| | </figure> |
| | |
| | <figure tcs2> |
| | {{ :en:iot-open:hardware2:tcs34725_schematic.png?200 | Connection of the TCS34725 and microcontroller}} |
| | <caption>Connection of the TCS34725 and microcontroller</caption> |
| </figure> | </figure> |
| |
| void setup(void) { | void setup(void) { |
| Serial.begin(9600); | Serial.begin(9600); |
| | Wire.begin(5,4); //SCL SDA |
| | pinMode(21, OUTPUT); //Pin 21 controls LED |
| | digitalWrite(21,LOW); //Turn off onboard LED |
| if (rgb_sensor.begin()) { //Initialise RGB sensor | if (rgb_sensor.begin()) { //Initialise RGB sensor |
| Serial.println("RGB sensor present"); | Serial.println("RGB sensor present"); |
| uint16_t r, g, b, unfiltered, lux; | uint16_t r, g, b, unfiltered, lux; |
| |
| rgb_sensor.getRawData(&r, &g, &b, &unfiltered); //read RGB and unfiltered light intensity | rgb_sensor.getRawData(&r, &g, &b, &unfiltered); |
| lux = rgb_sensor.calculateLux(r, g, b); //calculate illuminance in Lux | //read RGB and unfiltered light intensity |
| | lux = rgb_sensor.calculateLux(r, g, b); |
| | //calculate illuminance in Lux |
| |
| Serial.print("Lux: "); //print calculated Lux value | Serial.print("Lux: "); //print calculated Lux value |