Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:hardware2:sensors_optical [2023/10/02 20:29] pczekalskien:iot-open:hardware2:sensors_optical [2023/11/23 10:38] (current) pczekalski
Line 1: Line 1:
-==== 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.\\ 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; //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 () 
Line 64: Line 64:
 </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 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>tcs1}} and the connection circuit in figure {{ref>tcs2}}.  The sample device is present in figure {{ref>tcs1}} and the connection circuit in figure {{ref>tcs2}}. 
Line 72: Line 72:
 <caption>TCS34725 RGB colour sensor module</caption> <caption>TCS34725 RGB colour sensor module</caption>
 </figure> </figure>
-<todo @pczekalski>add schematic, replace image</todo> 
  
 <figure tcs2> <figure tcs2>
-{{ :en:iot-open:hardware2:tcs34725_schematic.png?200 | }}+{{ :en:iot-open:hardware2:tcs34725_schematic.png?200 | Connection of the TCS34725 and microcontroller}}
 <caption>Connection of the TCS34725 and microcontroller</caption> <caption>Connection of the TCS34725 and microcontroller</caption>
 </figure> </figure>
Line 90: Line 89:
 void setup(void) { void setup(void) {
   Serial.begin(9600);   Serial.begin(9600);
-  Wire.begin(5,4); //SCL SDA +  Wire.begin(5,4);           //SCL SDA 
-  pinMode(21, OUTPUT);  //Pin 21 controls LED +  pinMode(21, OUTPUT);       //Pin 21 controls LED 
-  digitalWrite(21,LOW); //Turn off onboard 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");
Line 104: Line 103:
   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
en/iot-open/hardware2/sensors_optical.1696278583.txt.gz · Last modified: 2023/10/02 20:29 by pczekalski
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0