LEDs as sensors, newbie needs help!

Hello,

I'm currently working on an interface using the bi-directionality of an LED array. They would display a target which the finger has to touch and sense it to locate if the target has been accurately touched...

I have watched Han's video (http://cs.nyu.edu/~jhan/ledtouch/index.html) and have looked at patents for using leds as sensors, but unfortunately I'm quite new to all of this and am a bit lost...

If by any chance you know of a program that does the same thing (array of led translated to screen) or that you have it as 'old work' and that you have moved on to something else, could you please point to me where I could find them?
This kind of thing is very helpful (for anyone who is interested) http://www.provolot.com/projectlog/2007/05/bidirectional_led_sensing_proc.html

I've got very limited knowledge of processing (and arduino coding in general) and a few lines of working code would therefore help me greatly.

with best wishes,

Ymtees

If by any chance you know of a program

Anyone giving you a piece of code is doing you a disservice. Go figure out what mechanism is at work and how to perform the various functions needed in your mcu.

That's called learning.

Copy-and-paste is for people without a brain.

once you've done it it's quite easy to understand

here's some quick and dirty code i rushed but i've tried to explain each action, there are better ways but this explains the principal

// LED with current limit resistor connected to digital pin 2 & 3
// LED - to pin 2 & LED + to pin 3

void setup()
{
  Serial.begin(9600);
  
}

void loop()
{
  long t=0;
// --------- LED Forward Voltage ------------  
  pinMode(2, OUTPUT);    // LED - to pin 2
  pinMode(3, OUTPUT);    // LED + to pin 3
  digitalWrite(2, LOW);  // Make pin 2 0v
  digitalWrite(3, HIGH); // Make pin3 VCC
  delay(10);
// ------------------------------------------

// --- Now Reverse Polarity to charge LED ---
  pinMode(2, OUTPUT);    // LED - to pin 2
  pinMode(3, OUTPUT);    // LED + to pin 3
  digitalWrite(2, HIGH); // Make pin 2 VCC
  digitalWrite(3, LOW);  // Make pin3 0v 
// ------------------------------------------  
  
// --------- Now Discharge the LED ----------
  pinMode(2, INPUT);     // make pin 2 input
  pinMode(3, OUTPUT);    // pin 3 still output
  digitalWrite(2, LOW);  // make pin 2 low, it is now input
  digitalWrite(3, LOW);  // Make pin3 0v 
  
// now count how many loops until pin 2 becomes logic low and LED is discharged  
  while(digitalRead(2) == HIGH)
    {
      t++;
    }
  Serial.println(t); // report to serial
// ------------------------------------------  
}

dhenry:
Anyone giving you a piece of code is doing you a disservice. Go figure out what mechanism is at work and how to perform the various functions needed in your mcu.

That's called learning.

Copy-and-paste is for people without a brain.

I understand I may be sounding as though I want someone to do the work for me, sorry about that, I am keen to learn but am afraid lack of guidance makes it seem as though there is a world I need to understand before I can do the smallest things. A piece of code, which I can decipher, would help me learn as I tweak it, making the whole processing more interactive, focused, and relevant to what I am trying to learn.

Thank you for your reply.

Ymtees

Have you read the page about my experiments with this?
http://www.thebox.myzen.co.uk/Workshop/LED_Sensing.html

here is an example of a guy that made a cube with LED sensors, not only did he use LEDs for sensors, he charlieplexed the the cube.

Have you read the page about my experiments with this?
LED Sensing

Very interesting Mike, i've never taken the time to look that deeply into it, I dont get much time usually, so left it as a cool led hack, although i did see some guy had make two units that could talk to each other at short range

P18F4550, Hippynerd, Grumpy_Mike,

Thanks a lot for pointing it out to me, I'm following Grumpy_Mike's example and it works, although results sometimes flicker heavily, with a 10 segment display I bought yesterday (http://www.maplin.co.uk/10-segment-display-2128). Might have been because it was night and there wasn't any 'natural' light.
Grumpy_Mike, thank you for posting both the arduino and the processing code, I'm deciphering it slowly! :slight_smile:

I've been told that to achieve my purpose, it would be better (and less complicated) to use a phototransistor in the middle of collated 2x2 or 4x4 arrays for location of a finger quickly touching the screen. If you've got any thoughts, please shoot! :slight_smile:

Best,

Ymtees

Bang!

Yes I think a photo transistor would be much easier to use, there is not all that software faffing about with charging and timing the discharging rate.

dhenry:

If by any chance you know of a program

Anyone giving you a piece of code is doing you a disservice. Go figure out what mechanism is at work and how to perform the various functions needed in your mcu.
That's called learning.
Copy-and-paste is for people without a brain.

A pretty ill concieved and ill considered bit of ppoor opinion if ever I have seen one
Everyone learns first by following example and then with experience experimenting to push the envelope a bit further.
In fact thats natures way.

I would ignore such statements
This is a board for posting questions to seek answers not criticism
Unfortunately it is full of these types

If you follow Mike's LED post and use normal led's there is a program posted here somewhere that gives the code for a function to read the time it takes for an LED to dissipate its charge to zero . If you can't find it by searching this thread then say so and I will go find it.

Surprisingly the LED used only as a light sensor can be reversed . No resistor is needed. However you are working with wire and capacitance and they vary widely from manufacturer to manufacturer . If you want a longer lead on an LED the only success I have had is with a single core shielded coax type cable with the shield as one of the wires,connected to negative , and the core as the other. Two wire shielded cable does not work and neither does twisted pair.. I think they pull in radio wave voltage in the area

The above single wire/shield works on the coax theory that the signal going into the coax comes out the same at the other end provided the capacitance in the cable does not vary so you should be able to use any length.

@ dhenry I understand you wear shoes make of candy so your day does have some 'Sweet Spots' in it...
You seem to "Open Mouth, Insert Foot"... quite often. Really noticeably so.. Too.
Hint... Is this the way that you wish to be treated...?
Did it ever occur to you that the word "Mechanism" Might not be understood in the context used...
OR that You ARE NOT A Gift From God, sent to save the Arduino Forum, Quite the reverse... IMO

Anyone giving you a piece of code is doing you a disservice. Go figure out what mechanism is at work and how to perform the various functions needed in your mcu.

That's called learning.

Copy-and-paste is for people without a brain.

From previous code snippets you have posted and your comments about their provenance it would appear that your statement above lacks some credibility ... AS usual...

Bob

although results sometimes flicker heavily

Because the code is poorly written.

All you need to do is to understand how this thing works, and code for it. The code posted earlier can serve as a good starting point: you will need to specify charge / discharge / measurement pins - for 6 leds, you need at most 7 pins.

The trick, with this approach, is to use time-out, so the measurement time isn't too long when it is dark.

A better approach is to use the adc module (aka charge transfer): it is much faster, offers higher resolution and is considerably simpler.

Charge transfer -adc module
I suspect I have seen a post on this somewhere here but I have searched here for "charge transfer " and "LED charge transfer " and "adc module " and the only thing that comes up is the above post.

I have done the same searches on DuckDuckGo and not seen anything I could directly associate with an LED or even a capacitor apart from Franklin flying a kite?

Would you please elaborate on this hopefully with a reference point so I can see what you are talking about.

A pretty ill concieved and ill considered bit of ppoor opinion if ever I have seen one
Everyone learns first by following example and then with experience experimenting to push the envelope a bit further.

Despite my normally impeccable judgement, strangely, I find myself agreeing with tyTower.

Hi everyone, I have been unactive due to sickness (someone actually coughed in my face and it was downhill from there).

Thanks for the advice (and to dhenry!) I'm on it.

I've had a bit of fun with a 10 segment display (http://www.maplin.co.uk/10-segment-display-2128) and Mike's code, giving ok results.

What I need to do now is be able to locate something the shape of a ping-pong ball falling on a 50x50mm surface. I'm going to search which sensor (phototransistor, or led) does this best and how to process data to locate it. FUN TIMES (I'm actually looking forward to it :))

The aim later is to have a large horizontal surface, an led or led-phototransistor array, with points appearing in a cluster (leds) and a kid aiming a ping pong ball at it, with the array recording how accurate his throw was. (It's for kids who've suffered strokes, hand-eye coordination + fun + aim)

Hope it's not too much info. anyway, thanks for the support, it's awesome! :slight_smile: