Arduino based LDR volume and source selection controller

Hello,

I needed a remote controlled, very high audio quality attenuator for a preamplifier that I built. After considering the various options, I decided to design my own LDR volume controller.

It took a lot of effort, but it works well now, I'm pleased with the result. I would like to share the project with the DIY community, in case someone is interested.

So, here it is:
- customizable impedance, between 5kohm and 50kohm
- customizable number of attenuation steps, between 20 and 80
- you do not need matched LDRs
- LOG attenuation curve
- you can display your own welcome messages on the LCD screen
- the firmware is easy to update and modify
- remote controlled with any Apple remote
- big LCD screen, the volume level is displayed with 4-char high digits, easy to see from a distance
- the screen auto-dims to a customizable level after some inactivity time
- rotary encoder with push button
- controls up to 6 input and output stereo channels
- I/O switching is done with best quality latching relays with Silver-Palladium contacts, to avoid any degradation of the musical signal
- you can name each input and output channel
- the controller remembers the settings after power off
- can control a delay relay to soft-start a tube preamplifier
- achieves a large attenuation range by increasing series resistance at very high attenuation level and by increasing shunt resistance at very low attenuation level
- the calibration compensates for the load impedance effect
- the on-board calibration relays are best quality and they are powered only during calibration
- the LDR LEDs are working at low current (7 mA maximum), they will last a very long time
- the controller is isolated from the audio ground to avoid noise and loops
- separate linear analog and digital low noise power supplies
- power supplies on separate board, to keep the power transformer far from audio circuits
- easy to calibrate anytime from a menu – no need to plug jumpers or an external module
- better audio quality than R-2R relay attenuators (no multiple relay contacts and solder joints in the signal path, no noisy relay coils)

It is Arduino based - there are more powerful microcontrollers available, but the Arduino is much easier to work with, any amateur can easily update and customize the software.

The DACs are simply the PWM outputs switched to 31250 Hz (instead of the 500 Hz default value) and easily filtered to clean DC by two R-C cells.

The whole thing should cost around 100€ to build, much cheaper than the equivalent commercial solutions available.
I ordered the PCBs from ShenZhen2U ?PCB|Source|Assembly|Components-ShenZhen2U , where 10 pieces of 2 layer PCBs cost 10€.
You can even make the power supply and I/O boards yourself, to save some money, with the toner transfer method or even "by hand", because they are simple and single layer.

If you only need the volume control without channel switching, don't order the I/O board and parts and configure the software for either zero I/O (the volume will be displayed in the middle of the LCD in this case) or one input or output (if you still want to display a channel name).

Project status: built and confirmed.

The latest version (23 November 2015) of the project package is here: http://www.diyaudio.com/forums/anal...urce-selection-controller-11.html#post4526605

Improved firmware by Wineds is here: http://www.diyaudio.com/forums/anal...urce-selection-controller-15.html#post4590382

Firmware modified to support both 2004 and 1602 LCD by Howarthcd: http://www.diyaudio.com/forums/analog-line-level/278667-arduino-based-ldr-volume-source-selection-controller-27.html#post4725171

Zdr's custom code for OLED and LCD displays + bugfixes: http://www.diyaudio.com/forums/analog-line-level/278667-arduino-based-ldr-volume-source-selection-controller-55.html#post4889131
 

Attachments

  • LDR Controller.zip
    813.7 KB · Views: 3,072
  • P8020026.JPG
    P8020026.JPG
    48.3 KB · Views: 15,072
  • ctrl.jpg
    ctrl.jpg
    161.9 KB · Views: 15,210
  • mainboard.jpg
    mainboard.jpg
    252.8 KB · Views: 14,617
Last edited:
  • Like
Reactions: 1 user
The Arduino is quite limited, it doesn't even have DAC outputs. But with some hacks, it can brilliantly do the job!

As said before, the PWM outputs are switched to 31250Hz, and thus easily filtered, making an 8 bit DAC. To overcome the low precision of this "DAC", the software can switch the driver MOSfets between two working ranges: low current and high current. This is enough to control the LDR current with acceptable precision.

The ADC inputs are oversampled to 12 bit (instead of the default 10 bit).

The target resistance values are computed for each LDR and each attenuation step. The code then searches for the needed current which gets the measured resistance as close to the target resistance as possible.

During normal use, the current through each LDR is permanently measured and fed back to the DAC control code in order to compensate for temperature drifts.
 
To overcome the low precision of this "DAC", the software can switch the driver MOSfets between two working ranges: low current and high current. This is enough to control the LDR current with acceptable precision.

Talking about the precision: the controller can approach the target LDR resistance within 0.1% at 1K, 1.5% at 10K and 5% at 50K
 
Last edited:
Cool design. Wondering what the benefits of LDRs are over conventional active volco chips such as the PGA2311? I remember reading that they produce a small amount of distortion as current rises through them, although I have only ever used them in instrument compressors where it's not an issue. Matching them was a bit of a pain though for stereo :( .

Maybe this thing could be put inside the power amplifier as well, that Arduino could be put to good use as a muting control at startup and a heatsink temperature monitor.

The possibilities are endless! Nice PCB BTW :) !
 
Cool design. Wondering what the benefits of LDRs are over conventional active volco chips such as the PGA2311? I remember reading that they produce a small amount of distortion as current rises through them, although I have only ever used them in instrument compressors where it's not an issue. Matching them was a bit of a pain though for stereo :( .

Maybe this thing could be put inside the power amplifier as well, that Arduino could be put to good use as a muting control at startup and a heatsink temperature monitor.

The possibilities are endless! Nice PCB BTW :) !

Only issue with PGA2311 is to separate the analog and digital ground plans -- as seen in the data sheet. I would guess you would want an interrupt so that you aren't continuously clocking the device.

I did some analysis of the Silonex, Vactrol and Fairchild several years ago:
 

Attachments

  • LDRComparison.gif
    LDRComparison.gif
    29.1 KB · Views: 3,811
Hello Vincent,

I´ve only one objection in your design: the use of the chinese display; it is not really long term availability and for some people really hard to purchase.

My idea is to modify your design by adding a LCD touchscreen display over the I2C interface (A4 and A5 pins from Arduino): one board with µC, LDR, IO´s interconnected with a 1mm ZIF connector, or other type, to a second board with supplies and LCD (the encoder is superfluous).

The candidate for this display would be from ELECTRONIC ASSEMBLY. I´ve used successfully this type of LCD with touchscreen in military application, but sorry, I´m not programmer!

They provide also OLED displays but in this case only over SPI.

ELECTRONIC ASSEMBLY - root LCD Module

Ok, you have to do some firmware modification to implement the LCD.

I know that a lot of people will then positivelly interested in a GB...

Regards,
Jean-Paul
 

Attachments

  • ATTENUATOR-CTRL_redesign.pdf
    63.8 KB · Views: 911