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/11/20 18:13] ekontoturboen: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 ==
  
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 89: 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 103: 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.1700504021.txt.gz · Last modified: 2023/11/20 18:13 by ekontoturbo
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