📜 ⬆️ ⬇️

Old friends are upside-down, or how the LED can be a photosensor

Indeed, on the basis of any LED, you can build a very handy illumination sensor like the one that measures illumination on the street to automatically turn on the lamp near the entrance in the evening.
The post could be titled "amazing next" - despite the fact that upon careful consideration, the principle of action becomes clear quite quickly, not everyone knows about the use of LEDs.
I saw the method here: www.arduino.cc/playground/Learning/LEDSensor , quickly checked - it works!
This is how it clings to Arduino / Freeduino:
image
The idea is simple - if you apply a reverse voltage to the LED (pin 2 == 1, pin 3 == 0), then this will charge the parasitic capacitance of the legs of the microcontroller. If you now switch the 2nd leg to the input, and do not forget to turn off the pull-up resistor, the capacitance will be discharged by the reverse current of the photodiode, which depends on the light, and after a while the leg will switch to the log. 0. Parasitic capacitance is of course small, but then the reverse current of the LED is small, and the microcontroller is devilishly fast! :) Therefore, the discharge time can be easily measured.
Here is a source code illustrating this approach:
 --- LED_Sensor.pde ---
 void setup () {
   Serial.begin (9600);
 }

 void loop ()
 {
   long int j;

   // Apply reverse voltage - this will charge its own output capacity 2
   pinMode (2, OUTPUT);
   pinMode (3, OUTPUT);
   digitalWrite (2, HIGH);
   digitalWrite (3, LOW);
  
   pinMode (2, INPUT);  // Switch the 2nd output to the input
   digitalWrite (2, LOW);  // and disable the pull-up resistor on it

   // Consider how long it will take for the capacity to discharge to logic.  0
   for (j = 0; j <128000; j ++) {
     if (digitalRead (2) == 0) break;
   }
   Serial.println (j, DEC);  // Display the value of the counter in the COM port
   delay (100);  // Pause not to overfill the COM port buffer
 }
 --- 
Another advantage of the method is that no one bothers to use the same LED for its intended purpose.

')

Source: https://habr.com/ru/post/55470/


All Articles