would it be possible to have an arduino use led's as sensors? like this ---> https://www.robotshop.com/letsmakerobots/node/272
If so how would I code it ?
would it be possible to have an arduino use led's as sensors? like this ---> https://www.robotshop.com/letsmakerobots/node/272
If so how would I code it ?
i never tested it before,
i never tested it before, but just wait for TCG read, he is using arduino now… maybe he do…
Good question. You should
Good question. You should give it a try and let us know First thing I’d do is hook up a voltmeter to the LED and try shining a bright light at it and seeing just what kind of difference in voltage there is between dark and bright light. And don’t assume that the positive will necessarily come out on the anode of the LED – I remember reading something about reverse-biasing an LED to get a more significant voltage change when using it as a light sensor.
I imagine the voltage change will be pretty small, so you might end up needing to run it through an op-amp to amplify the signal up to something your microcontroller can discern. And once you’re adding an op-amp, you’ve basically already built all of the regular Herbie circuit anyway, so you start to wonder if it’s worth adding a microcontroller at all.
But if what you really want to do is read LEDs as sensors with a microcontroller, then that might be the way you need to do it. It’d be worth just hooking up an LED to an analog pin and seeing if you can get any useful reading from it, and if not, then try using an op-amp. You could run each LED through an op-amp wired up in a traditional fashion, using the LED into the non-inverting input and running negative feedback from the output into the inverting input. Or you could run two LEDs into the op-amp the way the Herbie circuit does, and in that case, the way I understand it, you’d see 0V on the output when one LED sees all the light, and you’d see +V (whatever voltage you’re feeding the op-amp) when the other LED is seeing all the light, and you’d see voltages in between those values when the light is distributed between the two LEDs.
But op-amps are one aspect of electronics that I really don’t understand yet. I’ve been reading books trying to get a grasp for how they work, but basically I still have no idea how you’d want to wire one up to amplify the signal from an LED
Here’s a good page I just found that has lots of links about using LEDs as sensors. The first link on that page, Forum Discussion: How is it done?, has some interesting discussion about other people’s experiments. It sounds like you CAN get some sort of reading from an LED hooked straight into an analog input, provided you reverse bias it first to charge it up. But they also suggest using an op-amp for a more useful signal. Sounds like a good place to start. You should post the results of any experiments you do, because I’m interested in how this works.i will take a serius look at
i will take a serius look at it when i get time, thanks for the info.
Re: good question
Thanks for the info, I will do some testing and get back to you
~Matt
Here is the code.
Here is the code that I got from the Arduino page some where. It is modified to use different IO pins, allow overflow of the counter when it gets really dark and optimized some pinMode settings.
Regards,
-Pandit
//
// This example shows one way of using an LED as a light sensor.
// You will need to wire up your components as such:
//
// + digital2 (N side)
// |
// <
// > 100 ohm resistor
// <
// |
// |
// -----
// / \ LED, maybe a 5mm, clear plastic is good
// -----
// |
// |
// + digital3 (P side)
//
// What we are going to do is apply a positive voltage at digital2 and
// a low voltage at digital3. This is backwards for the LED, current will
// not flow and light will not come out, but we will charge up the
// capacitance of the LED junction and the Arduino pin.
//
// Then we are going to disconnect the output drivers from digital2 and
// count how long it takes the stored charge to bleed off through the
// the LED. The brighter the light, the faster it will bleed away to
// digital3.
//
// Then just to be perverse we will display the brightness back on the
// same LED by turning it on for a millisecond. This happens more often
// with brighter lighting, so the LED is dim in a dim room and brighter
// in a bright room. Quite nice.
//
// (Though a nice idea, this implementation is flawed because the refresh
// rate gets too long in the dark and it flickers disturbingly.)
//
#define LED_N_SIDE 4 // original code uses pin 2
#define LED_P_SIDE 5 // original code uses pin 3
void setup()
{
pinMode(LED_P_SIDE, OUTPUT); // P side is alway output pin (drive low or high)
pinMode(LED_N_SIDE, OUTPUT); // N side is output or input but starts with output
}
void loop()
{
unsigned int waitDischarge, extenLimit;
// Apply reverse voltage, charge up the pin and led capacitance
digitalWrite(LED_N_SIDE,HIGH);
digitalWrite(LED_P_SIDE,LOW);
delayMicroseconds(30000);
// Isolate the pin 2 end of the diode
pinMode(LED_N_SIDE,INPUT);
digitalWrite(LED_N_SIDE,LOW); // turn off internal pull-up resistor
// Count how long it takes the diode to bleed back down to a logic zero
for ( waitDischarge = 0, extenLimit = 0; waitDischarge < 65534; waitDischarge++) {
if ( digitalRead(LED_N_SIDE)==0) break;
// If counter has reach the limit but internal capacitor of the LED has not
// fully dischaged yet, reset the loop count to extend the discharge time
if ((waitDischarge == 65533) && (extenLimit < 10)) {
waitDischarge = 0; // reset wait discharge loop count.
extenLimit++; // make sure that we do not stay here forever
}
}
// You could use ‘waitDischarge’ for something useful, but here we are just using the
// delay of the counting. In the dark it counts higher and takes longer,
// increasing the portion of the loop where the LED is off compared to
// the 30000 microseconds where we turn it on.
// Turn the light on for 30000 microseconds
digitalWrite(LED_P_SIDE,HIGH);
digitalWrite(LED_N_SIDE,LOW);
pinMode(LED_N_SIDE,OUTPUT);
delayMicroseconds(30000);
// we could turn it off, but we know that is about to happen at the loop() start
}
Sweet…
thanks I will try that
~Matt