Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 16 of 16

Thread: How does that work?

  1. #1
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,960

    Question How does that work?

    A small mini project after work


    How does that work?



    Just a little challenge - without anything to win, just for fun.





    p.s. Yes I know, that a resistor should be used. Just don't do this at home.

    - Please no answers from electronic or computer engineers, professionals etc. - I know that you know it -
    Last edited by Frank B; 01-18-2021 at 09:30 PM.

  2. #2
    Senior Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    203
    I'm none of those so here goes.
    Code reads a (green) Led pin as if an antenna picking up stray garbage looking for a trigger, and if we get one then code does some PinMode shuffling, say pulling one end of the Led low and pulsing the other end with low duty-cycle subsequently PinModes get shuffled back to antenna mode to see if we have another trigger?

  3. #3
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,960
    Hm, so the "garbage" is less when I remove my hands?
    What kind of "garbage" do you think, is it?

  4. #4
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    226
    Its using the LED as a photodiode.
    https://www.instructables.com/LEDs-as-light-sensors/

    By checking the input light in the off period of the LED

    edit. thats why it's flashing

  5. #5
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,960
    Very warm.
    But it is pure digital. No ADC(?!)

    Oh man I should have used pins without ADC..

  6. #6
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    226
    well you can always do capacitive sensing with just digital pins by pulsing the output and see the time dilation, and also do a crude ADC this way.

  7. #7
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,960
    ... ok.. I guess it was too easy.. again... my last question of this kind (turn speakers on) was answered in record time, too :-(

    Code:
    const unsigned p1 = 17; // LED-Anode
    const unsigned p2 = 16; // LED-Kathode
    
    
    unsigned measure()
    {
      unsigned long long m;  
    
    
      //discharge any remaining load
      pinMode(p2, OUTPUT);
      digitalWriteFast(p2, LOW);
      delay(1);
      
      //Load the LED capacitance:
      digitalWriteFast(p1, LOW); //Anode: GND
      digitalWriteFast(p2, HIGH); //Kathode: 3V
      delay(50);
      
      //Now measure the time it needs to discharge through the 
      //high-impendance input:
      m = millis();
      pinMode(p2, INPUT);
      while (digitalReadFast(p2) && (millis() - m < 100) ) {;}
      m = millis() - m;
      
      return m;
    }
    
    
    void ledsON() {
      digitalWriteFast(LED_BUILTIN, HIGH);
      digitalWriteFast(p1, HIGH);//Anode: 3V
      digitalWriteFast(p2, LOW); //Kathode: GND
    }
    
    
    void setup() {
      pinMode(LED_BUILTIN, OUTPUT);
      pinMode(p1, OUTPUT);
    }
    
    
    void loop() {
      if (measure() > 10) {
        ledsON();
        delay(20);
      }
      else {
        digitalWriteFast(LED_BUILTIN, LOW);
      }
    }
    Important: kathode on pin 16 (or edit the code).
    Additional question for the experts: Why?
    Last edited by Frank B; 01-19-2021 at 07:28 AM.

  8. #8
    Senior Member manicksan's Avatar
    Join Date
    Jun 2020
    Location
    Sweden
    Posts
    226
    "time dilation" is not the right word here as that is something else.
    (have just been watching some SciFi series and was a little confused)

    "time difference" is the proper word

    have pin16 some special functionality in the MCU

    otherwise the direction of the led need the cathode to be low and the anode to be high,
    also used to read the led (in photodiode mode)

  9. #9
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,960
    No you can use any pin.
    Important is just the direction of the LED. You need to swap "+" and "-" measure the capacitance this way. The "capacitor" discharges slower or faster depending on the amount of light.
    The program does this by swapping "-" and "+" on the pins into the opposite direction.
    This is also the reason why the LED on Pin13 can't be used - or maybe - I just did it wrong?

    I'm not *that* sure why So this is a real question.

    At least, this thread answers the question why all chips are black.
    Last edited by Frank B; 01-18-2021 at 10:43 PM.

  10. #10
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,960
    So, real question : Is there a way to use the builtin LED on pin13? I suspect, not, because we can't charge the capacitance? Or is there maybe any other effect that can be measured?

  11. #11
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    1,369
    Very nice!

    At least, this thread answers the question why all chips are black.
    Back in the days when people had weird hair cuts, wore flared trousers and CCD chips where extremely expensive there was some hype about opening DRAM chips and using them as CCDs. The idea is the same as with your experiment: The DRAM capacitors unload faster when illuminated. I never succeeded but others did. Here a nice article about such a project (german) http://www.kurzschluss.com/kuckuck/kuckuck.html (google translation: https://translate.google.com/?sl=de&...l&op=translate)

    Here a picture taken with a 64kB DRAM:
    Click image for larger version. 

Name:	Screenshot 2021-01-19 075015.jpg 
Views:	10 
Size:	53.8 KB 
ID:	23341

  12. #12
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    13,482
    My EE buddy did that for a high school science project in 1980. Put his TRS-80 on a wheeled robot platform he built - focused light on an open top chip and navigated based on the chip's view of the world.

  13. #13
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,960
    Yes, I remember there were articles in some magazines, including ELEKTOR about using CMOS memories as camera.
    It is, however, interesting how good a simple LED works as sensor.

  14. #14
    Senior Member
    Join Date
    Jul 2020
    Posts
    712
    All pn junctions are photodiodes and LEDs, if the material is transparent at the relevant wavelength, since photons generate
    electron-hole pairs and recombination can emit a photon (although the probability for this strongly depends on quantum
    properties like whether there is a direct band-gap in that material).

    Silicon is not direct-bandgap and thus doesn't work well as an LED, but it will work as a photodiode (even when you don't
    want it to, which is why packages are black epoxy or sealed metal cans).

  15. #15

  16. #16
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,960
    Oh, that means it indeed works with the inbuilt LED. Seems that the measuring just needs to be 1000 times faster? (us vs. ms)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •