LED Control

I have posted this within an existing thread but wanted to give it more visibility in order to get a consensus.

I'm new here so forgive me if some of these questions are basic but I want to use an arduino board to control 4 LEDs individually. The 4 Leds are each connected to their own light dependent resistor (LDR) & I want the output resistance for each LDR to be the same for each numeric setting of a dial (representing a volume setting).

The problem is that LDRs are not very tightly engineered within spec. So, I thought that some way of using an arduino to:

  • firstly calibrate each LDR and store a value for the current needed for each LED to output the same resistance at each volume setting.
  • During use as a volume control, this table could then be looked up and the correct current applied to each LDR to achieve the same output resistance across all 4 LEDs.

Problem is, I don't know how feasible this is with the existing hardware?

  • Which board is most suited to these needs?
  • What bits & pieces do I need?
  • How would a number stored in an array be used to drive a particular current through an LED?

I guess for 4 LDRs & 99 vol settings and a byte to store each current setting then 400 byte array is needed. This needs to be stored in non-volatile memory. Two modes needed - a calibration mode & normal mode.

Ok, I've found out that I use

  • analogread (pin) to read a voltage from a pin
  • analogwrite (pin value) to write a PWM value to a pin which can control the brightness of an LED. So I guess I could retrieve a stored value from a 4*100 array & write it to the LED on that pin.

During calibration phase I need a way of using the resistor value of the LDR to generate a voltage between 0 and 5V. I guess a voltage divider would work which could be disconnected after calibration was finished?

Am I missing anything?

If this was to be extended to muti-channel use, say 7 channels - I would need 14 out pins & 14 in pins - do I need an pin extender?

I need as clean a power supply to the LED as I can get so I'm worried about the PWM signal driving the LED causing some distortion coming through to the LDR. Will putting a capacitor across this PWM signal clean it up sufficiently or should I be looking at a Voltage controlled current source?

I'm worried about the PWM signal driving the LED causing some distortion coming through to the LDR.

Don't it won't. LDRs can't respond to anything that fast.

Other things to watch out for are that LRDs have a bit of a memory and their characteristics change with how they are stored even when off. So if they are stored in a dark draw the will be slightly different to when they are stored in the open. This might mean that the calibration will not be as good as you hoped it might be.

should I be looking at a Voltage controlled current source?

What other source of current is there that is not voltage controlled?

Have a look at this:-
http://www.thebox.myzen.co.uk/Tutorial/Power_Supplies.html

Thanks Grumpy,

Don't it won't. LDRs can't respond to anything that fast.

The application for this is as an audio volume control. The signal passes through & is varied according to the LDR resistance. If this fluctuates, in any way, it will be heard. From others who use this the quality of the PS is important & effects the ultimate sound.

I guess it's just a case of trying it?

Thanks for the link. A voltage controlled current source (VCCS) is a special type of circuit where a variable voltage controls a current output like here: http://electronicdesign.com/Articles/Print.cfm?ArticleID=9018 and this is probably what I'll use if the PWM signal causes audible distortion in the LDR

his is probably what I'll use if the PWM signal causes audible distortion in the LDR

No need - all you have to do is put a capacitor across the LED or the LDR or both to smooth out any signals injected into the audio

Thanks Grumpy,
What would be the most suitable board variation for this bearing in mind I may want to extend this to 20+ pin control? I'm figuring 7 channels for vol control (7*2 pins) and another 6 pins for source selection.

I don't know the full range & I want to keep it inexpensive.

I want to keep it inexpensive.

With that many PWM outputs you need to look at either the Mega or the ordinary one (Decimila) with extra hardware to get more PWM outputs.

However I would do the experiment on one channel before committing to buying on spec.

Which of these look good to start with? http://www.nkcelectronics.com/arduino-diecimila.html or
http://www.nkcelectronics.com/seeeduino-fully-assembled--arduino-compatible.html

And later add the extension hardware?

I would go for the former. It has it's processor in a socket and so it is easy to change if you damage it. The latter is a soldered surface mount chip which require a lot of skill and specialised tools to replace.

Thanks Grumpy,
This is the sort of invaluable information I knew you would have as you are a God member.

Thank you!

Another option is the Freeduino, but you have to solder it yourself. http://www.nkcelectronics.com/freeduino-arduino-diecimila-compatible-board-complete-kit.html

And you can change the components to audiophile components :slight_smile:

BTW, excellent project you are starting. Keep us posted.

Thanks glt,
I'm not sure that I'll need any audiophile components as the signal will not be going through any board components. Are there any other advantages?

I saw this board which I know doesn't have headers soldered in (I'll probably be soldering in wires anyway)but what else is it missing or other implications does it have - only $20 Arduino Pro 168 - 3.3V/8MHz - DEV-08783 - SparkFun Electronics

Edit: would it make it more difficult to extend for extra PWM pins? What is the add-on card to use for this extra PWM functionality?

I was just kidding about the audiophile components, but you know how audiophiles are... That board is half speed (uses the internal 8 MHz clock). And you need usb to serial to program it. (In theory you can program with serial port, but I have not tried it). There is a Serial Freeduino for even less money).

I should pay more attention to the emoticons!
But I know what you mean about audiophiles _ I twant the best sound but I try to keep it sane both in terms of the money I spend & the lengths I will go to.
I may have a USB to serial board somewhere - I'll have a look - I'll check out the Serial Freeduino.

Is that the only downside to them? - I don't think I need the speed? Although if this was to do all the preamp functions you & Linux-works have designed, glt, would it need the speed/power?

Edit: glt, I meant to ask - did you get the datasheet for the Sabre DACs yet - could I get a copy?

No, no spec yet. I think if it is available it would be posted in the ESS website (I don't have any connections with the company). One more thing: I think serial duinos require external power...

Oh I thought I saw Dustin Forman (ESS SAbre designer) reply to a post of yours looking for the datasheet - thought he might have emailed it. Strange that it's not in the public domain? You'll need it for s/w control of the chip - this would be another great application for the arduino as you already identified.

External PS is fine - I'm envisaging the final design to be a standalone preamp with all the functionality you already have but a vol control based on LDRs. So own PS needed just like a preamp.

USB power is good when you are developing the application... One less wire to worry about.

Ah, yes I understand!

Can I ask some basic Qs

  • what are shields?
  • what do I need to extend the no of pins that can do PWM?

what are shields?

A shield is a plug-in expansion or interface card for the Arduino. It plugs on top of the Arduino, and so it looks like it's shielding the Arduino from the sun (or something).