How does that work?

Status
Not open for further replies.

Frank B

Senior Member
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:
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?
 
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.
 
... 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:
"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)
 
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:
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?
 
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...schluss.com/kuckuck/kuckuck.html&op=translate)

Here a picture taken with a 64kB DRAM:
Screenshot 2021-01-19 075015.jpg
 
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.
 
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.
 
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).
 
Oh, that means it indeed works with the inbuilt LED. Seems that the measuring just needs to be 1000 times faster? (us vs. ms)
 
Status
Not open for further replies.
Back
Top