Multiplex IR LED's?

Grumpy_Mike:

Do shift registers take inputs

There are shift registers that output parallel data from a serial input and other types that output serial data from parallel inputs.
But these are digital inputs, for your sensors you need an analogue input so go with the 4051.

Alright cool, :slight_smile:

I guess I can use shift registers and some transistors to make my matrix, I found an example here: http://www.instructables.com/files/orig/F7J/52X0/G1ZGOSRQ/F7J52X0G1ZGOSRQ.jpg

I find It kind of hard to follow your description but I think I know what you mean. Do I use the PNP current source or FET to power the LED's ad is it in a cmos chip or is it handmade? Also what do I do for a current sink, do I need one aswell as a current source? Ill draw a diagram up when I get home

Most instructables are very poor, that one is no exception. You should never use a common collector transistor configuration to source current, it shows the person who drew the circuit dosn't know what they are doing.
You can get away with just a current sink if you only source one LED at a time from each pin. Otherwise you need both source and sink drivers. A PNP transistor or p-channel logic level FET shoul be used for the source.
For the sink you can use NPN transistors or n-channel logic level FETs

Nvm my previous post I think I understand this now

Using these 74HC595's http://www.jaycar.com.au/productView.asp?ID=ZC4895&keywords=595&form=KEYWORD
And Hopefully if I can these ULN2803's http://australianrobotics.com.au/products/darlington-driver-8-channel-uln2803-dip (I might not be able to use it because I need to be able to pay by check)
if not this pricy one http://www.altronics.com.au/index.asp?area=item&id=Z3010

I was able to come up with a way that uses alot of shift registers and no multiplexing, and a way that uses heaps less shift registers and multiplexing

Anyway this is the multiplexing way I believe should work, I dont really know:

I guess to use this I will use the shift out command explained here (Not with same pins): - YouTube
and here:
http://www.arduino.cc/en/Tutorial/ShiftOut

I believe I can make this so only 1 LED is on at a time, that should work correct? FOr instance, if I do:
void setup() {
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
}
void loop() {
digitalWrite(2, LOW);
shiftout(0, 1, MSBFIRST, 0);
shiftout(0, 1, MSBFIRST, 1);
shiftout(0, 1, MSBFIRST, 1);
digitalWrite(2, HIGH);
delay(10);
digitalWrite(2, LOW);
}
And the pins are:
Data 0
Clock 1
Latch 2

That should output Column 1, Row 1, which is the bottom left, then If I change it to this:
shiftout(0, 1, MSBFIRST, 4);
shiftout(0, 1, MSBFIRST, 0);
shiftout(0, 1, MSBFIRST, 3);

it would be Row 3 and Column 12, which is near the middle to the very right.

If this is correct I Yaaaay :stuck_out_tongue: ( I have not put in resistors because the darlington array made me weary of how it works, if I did put resistors in, should I just need 1 per row/column, and have them at 90 Ohms [R=V/I, R=(5-3.2)/0.02, R=90], Or will they get hot?)

Also I figured out how to use the photodiodes, by this guy: http://www.instructables.com/id/Infrared-Proximity-Sensing-Coffee-Table-Module/

I guess you place them in reverse bias and they can be used as voltage dividers :slight_smile:

Thanks again MIke :smiley:

Grumpy_Mike:
Most instructables are very poor, that one is no exception. You should never use a common collector transistor configuration to source current, it shows the person who drew the circuit dosn't know what they are doing.
You can get away with just a current sink if you only source one LED at a time from each pin. Otherwise you need both source and sink drivers. A PNP transistor or p-channel logic level FET shoul be used for the source.
For the sink you can use NPN transistors or n-channel logic level FETs

Oh LOL I must have been typing my post at the same time as you :stuck_out_tongue:

What do you mean by NPN transistors or N-Channel Logic level FETs, on your site you mention them as sources dont you? And yes I will only have 1 LED on at a time, yet it will be blinking supa fast so u cant tell :stuck_out_tongue:

And yes I will only have 1 LED on at a time, yet it will be blinking supa fast so u cant tell

No you won't, there are too many to do this and the on / off ratio will be too high.

Do not use pins 0 & 1, these are used by the serial communications and you will have difficulty uploading sketches.

As the 595 can only supply enough current for 1 LED you will have to drive that circuit to multiplex by column rather than the more conventional row.

What do you mean by NPN transistors

A bit fundamental this one, I suggest you shouldn't be doing a project like this if you don't know.
For some education see:-
http://www.kpsec.freeuk.com/trancirc.htm

Also I figured out how to use the photodiodes, by this guy: http://www.instructables.com/id/Infrared-Proximity-Sensing-Coffee-Table-Module/

Most of the people who write instructables are in fact idiots. The only people more stupid are the people who read them, just look at some of the inane comments you get. Try not to get your facts from this source.

Grumpy_Mike:
A bit fundamental this one, I suggest you shouldn't be doing a project like this if you don't know.
For some education see:-
Transistor Circuits

Sorry that wasnt really what I meant, I do know what they do, just I keep getting confused, when you use them on your site, it looks very different to how I thought they are used

Grumpy_Mike:
Most of the people who write instructables are in fact idiots. The only people more stupid are the people who read them, just look at some of the inane comments you get. Try not to get your facts from this source.

I understand this, you keep saying it :P, The only thing is that they have working examples sometimes, and that is easier to understand to see it in action than just to read text. I only keep linking back to examples from their because the way many people do it there looks much easier than other options, whether its good or bad is another question

Grumpy_Mike:
No you won't, there are too many to do this and the on / off ratio will be too high.

Do not use pins 0 & 1, these are used by the serial communications and you will have difficulty uploading sketches.

As the 595 can only supply enough current for 1 LED you will have to drive that circuit to multiplex by column rather than the more conventional row.

Oh, well that seems like I always have much to do this :stuck_out_tongue:

Ok, now Im really confused. I thought I am doing a column scan cuircut, do you mean row scanning or am I doing the matrix wrong? Can you give me an example? Or .... is it my example code?

f I did put resistors in, should I just need 1 per row/column,

You need the resistor in the line that is going to light up just 1 LED. In your case this is the lines from the first shift register. That first shift register should have the whole column of LEDs you want to turn on have a ones in the correct place for the pattern.
The other two should have the walking one on them.
We seemed to have switched now to an 8 by 12 array is this new? It never appeared in any of the other requirements.

he only thing is that they have working examples sometimes

I keep telling you that by and large they don't work, that is what leads many beginners astray and make us here pull out hair out. If you insist on looking at instructables then I am afraid I can't help you any more.

when you use them on your site, it looks very different to how I thought they are used

So your thinking was wrong then.

do you mean row scanning

No.

is it my example code

Yes it simply dose nothing very much. Also when posting code use the # icon next to the quote to stop the code being mangled by the forum software.

Grumpy_Mike:

f I did put resistors in, should I just need 1 per row/column,

You need the resistor in the line that is going to light up just 1 LED.

Sorry I just switched because I didnt think that it would make much of a difference, I bought a pack of 100 LEDs because they were cheap, so I just thought I may as well use as many as I can. I can use just 8x8 though

Grumpy_Mike:

he only thing is that they have working examples sometimes

I keep telling you that by and large they don't work, that is what leads many beginners astray and make us here pull out hair out. If you insist on looking at instructables then I am afraid I can't help you any more.

Sorry, I will stop looking there

Grumpy_Mike:

when you use them on your site, it looks very different to how I thought they are used

So your thinking was wrong then.

do you mean row scanning

No.

My bad, Im still a noob at this :stuck_out_tongue:

Grumpy_Mike:

is it my example code

Yes it simply dose nothing very much. Also when posting code use the # icon next to the quote to stop the code being mangled by the forum software.

In your case this is the lines from the first shift register.That first shift register should have the whole column of LEDs you want to turn on have a ones in the correct place for the pattern.
The other two should have the walking one on them.
We seemed to have switched now to an 8 by 12 array is this new? It never appeared in any of the other requirements.

Sorry bout the code I forgot there was a button for it :3

Im really confused right now,If I want the matrix to turn on simply 1 LED (the bottom left) and keep it on, what do I do, do I make the first shift registers data [1,0,0,0,0,0,0,0], the first column(bottom left is selected) then at the same time have the second 1 in the row have [1,0,0,0,0,0,0,0] as its data, and the last all 0's

Then to make multiple LED's on, say a diagonal line from bottom left to top right, how would that work?

Like I say in my page you have an array containing the bit pattern of what you want to display. Then you have a refresh routine to put that memory onto the LEDs. You seprate the refresh program from what you want to display.
Have a read of that page again.

Grumpy_Mike:
Like I say in my page you have an array containing the bit pattern of what you want to display. Then you have a refresh routine to put that memory onto the LEDs. You seprate the refresh program from what you want to display.
Have a read of that page again.

I understand what you are saying, but then what would I use to get enough amps flowing per column? Wont the shift register go kaboom if I power more than 1 LED, should I be using current sources? If I do it this way 160mA can be flowing through each time, can the ULN2803's take that on 1 pin?

Do you mean have it do this (Psuedocode):

// if this is the byte data: byte displayData [ ] = { B11111111, B10000001, B10111101, B10100101, B10100101, B10111101, B10000001, B11111111 }; //Example taken from your site

loop start(){

if refresh is due then refresh

loop end}

refresh(){

byte tempData;

    for each column do this{
        
        tempData= displayData[columnNumber];
        write latch pin low
        shiftOut(datapin,clockpin,MSBFIRST,tempData);
        write latch pin high

    }

end refresh}

If this makes sense tell me, if not ill write it in arduino code, also FETs are way too expensive! So I wont be using them if I need a current source :stuck_out_tongue:

The code is nearly right but you only do one column per refresh not all of them.
You are only sourcing one LED's current per shift register pin so that is fine but check on the data sheet that the total package current is OK, it depends on what type of shift register you get, that is given by the letters before the 595 bit, you might have to use LS or HS type. The darlingtons are good for 500mA per pin.

I also forgot to ask, how would I generate a 38khz wave for the IR Emitters so the detectors can sense the IR signals?

You love springing surprises don't you. You said at the start that the IR carried no data, now you are saying they are modulated!!!
Well modulation is data, what sort of sensor do you have, part number? This changes again how you should do things.

Grumpy_Mike:
The code is nearly right but you only do one column per refresh not all of them.
You are only sourcing one LED's current per shift register pin so that is fine but check on the data sheet that the total package current is OK, it depends on what type of shift register you get, that is given by the letters before the 595 bit, you might have to use LS or HS type. The darlingtons are good for 500mA per pin.

OOOOOOOohhhh omg I understand now :smiley:

Firstly, the datasheet for the 595s Im getting say the max continuous output current is 35mA I think, http://www.jaycar.com.au/products_uploaded/ZC4895.pdf But I dont know if thats per pin or not?

Ok now to the good part :P, I think I have got it, and I wrote up the code, not psuedocode:
This works if the ULN2803 inverts I have read that it does but im still not sure, on your site It says they do or is that for the FET's?

const int latchPin = 4;
const int clockPin = 3;
const int dataPin = 2;

byte displayData [ ] = {
B11111111,
B10000001,
B10111101,
B10100101,
B10100101,
B10111101,
B10000001,
B11111111,
B11011011,
B11111111,
B11111111,
B11111111};
int rowCount = 0;

long int refreshDue;
long int refreshTime = 10; 

void setup() {
  pinMode(dataPin, OUTPUT); //Data
  pinMode(clockPin, OUTPUT); //Clock
  pinMode(latchPin, OUTPUT); //Latch
}
void loop() {
  if(millis() >= refreshDue){
    refreshDue = millis() + refreshTime;
    refreshDisplay();
  }
}

void refreshDisplay(){

  if (rowCount>=12)rowCount=0;
  
  byte rowData;
  byte col1Data;
  byte col2Data;
  
  rowData = displayData[rowCount];
  
  if (rowCount<=7){
    col2Data=B00000000;
    col1Data=byte(rowCount+1);
  }else if (rowCount>=8{
    col2Data=byte((rowCount-8)+1);
    col1Data=B00000000;
  }
  
  digitalWrite(latchPin, LOW);
  shiftout(dataPin, clockPin, MSBFIRST, col2Data);
  shiftout(dataPin, clockPin, MSBFIRST, col1Data);
  shiftout(dataPin, clockPin, MSBFIRST, rowData);
  digitalWrite(latchPin, HIGH);

  rowCount ++;
  
}

(I also used alot of your code, thanks bro :P)

There is one minor flaw in this code...
instead of refreshing left to right, or right to left (which is what I wanted)
it refreshes or the bit walks like this (_ means that its not used shift register pin)
00000001 0000 _ _ _ _
00000010 0000 _ _ _ _
00000100 0000 _ _ _ _
00001000 0000 _ _ _ _
00010000 0000 _ _ _ _
00100000 0000 _ _ _ _
01000000 0000 _ _ _ _
10000000 0000 _ _ _ _
00000000 0001 _ _ _ _
00000000 0010 _ _ _ _
00000000 0100 _ _ _ _
00000000 1000 _ _ _ _

Also I believe you mean HC, I cant find any HS595's anywere :stuck_out_tongue:

P.S: I saw your post whilst I was posting a reply to the other one :P, I dont mean to spring the surprise, I was using just a photodiode and hoping it would work, when I realised the part that I ordered from sparkfun wasnt a photodiode but rather a reciever Lol, fail, so then I just thought since the instructable I was following before was a load of crap and I might as well actually use the reciever it could give me a better result :slight_smile:
This is the part: TSOP38, can be found here: IR Receiver Diode - TSOP38238 - SEN-10266 - SparkFun Electronics
But I might have to order from somewhere else as they only take credit card and use something like this: http://www.jaycar.com.au/productView.asp?ID=ZD1952&form=CAT2&SUBCATID=976#1
which is way too overpriced for me :frowning:
I would prefer to use this: http://www.electus.co.nz/productView.asp?ID=6149&CATID=33&keywords=&SPECIAL=&form=CAT&SUBCATID=140 but I dont know how to use it with the emitter, all examples use reciever breakouts and stuff :frowning:

Thanks Mike :smiley:

With your code, have the walking 1 variable as a global like the rowCount. Change it each time by a:-

walk1 = walk1 << 1;

Reset it to 1 when you reset the rowCount. Then there is no need to calculate the col2Data or col1Data simply output the walk1 value:-

  shiftout(dataPin, clockPin, MSBFIRST, walk1 >> 8);
  shiftout(dataPin, clockPin, MSBFIRST, walk1);
  shiftout(dataPin, clockPin, MSBFIRST, rowData);

You better say what your application is because I suspect that the sensor you have is not suitable. Look at the data sheet and you will see that you can't carry on giving it pulses and expect the output to say at one level. If you want to just detect when a beam is broken you need the TSOP4038 sensor.

Grumpy_Mike:
With your code, have the walking 1 variable as a global like the rowCount. Change it each time by a:-

walk1 = walk1 << 1;

Reset it to 1 when you reset the rowCount. Then there is no need to calculate the col2Data or col1Data simply output the walk1 value:-

  shiftout(dataPin, clockPin, MSBFIRST, walk1 >> 8);

shiftout(dataPin, clockPin, MSBFIRST, walk1);
  shiftout(dataPin, clockPin, MSBFIRST, rowData);

Ahh thats what the >> and << operators do, I see, yes that narrows down the code alot, thanks :slight_smile:

Grumpy_Mike:
You better say what your application is because I suspect that the sensor you have is not suitable. Look at the data sheet and you will see that you can't carry on giving it pulses and expect the output to say at one level. If you want to just detect when a beam is broken you need the TSOP4038 sensor.

I just want to detect a broken beam yea :slight_smile:

Ok so you need to change your sensor.

Grumpy_Mike:
Ok so you need to change your sensor.

Damn, so I get a TSOP4038, I found this one on an Australian site which I might be able to buy it off: http://www.x-on.com.au/details-new.asp?i=549879&t=7&p=

My only problem is, everywhere people mention that the IR Emitters need to be pulsing at 38khz for the IR Detectors to pick it up... So how do I do that?

You setup one of the timers to change the PWM frequency to 38KHz and drive the LEDs from that pin.

Grumpy_Mike:
You setup one of the timers to change the PWM frequency to 38KHz and drive the LEDs from that pin.

But how can one output drive 6 or more Ir emitters? With a transitor or something?