Arduino based LDR volume and source selection controller

I'm still to finish building this, but in your testing, is the volume control linear or more log-like? I'm curious with how the sampling and cutting up of the volume levels with the microcontroller links to the very non linear response you get with LDRs
 
Last edited:
Vincent, how low is the units output impedance?

Hello,

The output impedance, like a normal potentiometer, goes between 0 (at 0% and 100% attenuation) and nominal_impedance/4 (when the series and shunt parts of the potentiometer are equal).
This unit's nominal impedance can be selected from 5K to 50K, and for the recommended 10K impedance, the maximum output impedance would be 2.5K.

Can i control the volume with a simple potentiometer too?
You mean control this unit with a potentiometer instead of the rotary encoder or IR remote? No, not without changing a lot of code.
 
I'm still to finish building this, but in your testing, is the volume control linear or more log-like? I'm curious with how the sampling and cutting up of the volume levels with the microcontroller links to the very non linear response you get with LDRs

The volume control follows a logarithmic scale, to fit the human ear response. See the graph below, it's the Excel I used to tweak the LOG law used.

The actual calculation is done by the function float getAttFromStep(byte step), line 908 in the code, which returns the attenuation needed (logarithmic, between 0 and 1) depending of the volume step (linear, between 0 and VOL_MAX_STEP).

I then calculate the LDR series and shunt resistances needed to obtain that attenuation (line 972). Then the calibration routine searches for the current needed to set the LDRs at the resistances calculate at the previous step. Easy. :)
 

Attachments

  • law.png
    law.png
    29.9 KB · Views: 1,492
Everything seems to be working. I will try a listening test tonight...

Nice! :)

A remark - the controller detects when it is being powered down, and it mutes the outputs and saves the current volume into the memory. To do that, it uses the charge stored in the D+ PSU capacitor.
I can't tell what value of capacitor you used, but if it is only 2200µ, it may or it may not work as intended. I'm using 3900µ, the biggest value I could find in E5-13 form factor.
 
Nice! :)

A remark - the controller detects when it is being powered down, and it mutes the outputs and saves the current volume into the memory. To do that, it uses the charge stored in the D+ PSU capacitor.
I can't tell what value of capacitor you used, but if it is only 2200µ, it may or it may not work as intended. I'm using 3900µ, the biggest value I could find in E5-13 form factor.

Thanks Vincent. Yes it is 2200uF. But I have tried a few power cycles and it seems to remember the volume setting so far... Only issue so far is the IR remote. It seems prone to getting stuck in the volume up mode regardless of what button I press. But I don't have an apple remote. I am using an Android app to emulate one on my phone.

The pot tracking seems very good. I checked it with a DMM on the bench and both channels seem to track well over the attenuation range. Well done!

The documentation was excellent and it was quite easy to setup. Calibration did seem to take a long time though - maybe 5+ minutes?

I think the BOM is one 5 pin header set short? Also I had to adjust the trimpot on the back of the LCD to get a visible display (took me a while to guess this was reason for a blank display).

Now I have to think if I will order some of your I/O relay boards...

Thank you once again!
 
Last edited:
Only issue so far is the IR remote. It seems prone to getting stuck in the volume up mode regardless of what button I press. But I don't have an apple remote. I am using an Android app to emulate one on my phone.

My phone does not have an IR emitter, so I can't test this, but my aluminum Apple remote works well... In fact, many other remotes could work, but you would have to measure and update the specific IR codes in the software.

I think the BOM is one 5 pin header set short? Also I had to adjust the trimpot on the back of the LCD to get a visible display (took me a while to guess this was reason for a blank display).

Indeed, I missed a couple of pin headers: one two-pin and one 5 pin! :eek:
I will update the BOM. I should also add a note about adjusting the LCD contrast with the trimpot on the back! Thanks!
 
My phone does not have an IR emitter, so I can't test this, but my aluminum Apple remote works well... In fact, many other remotes could work, but you would have to measure and update the specific IR codes in the software.



Indeed, I missed a couple of pin headers: one two-pin and one 5 pin! :eek:
I will update the BOM. I should also add a note about adjusting the LCD contrast with the trimpot on the back! Thanks!

Vincent, I have also tried a genuine apple remote and the symptoms are the same as using my phone to emulate. It can get stuck in either volume up or volume down depending on the preceding keypress. Using debug mode with print statements to the serial monitor, most of the time getIRkey() returns 0 via line 1227 (i.e. a "repeat"). So the last valid ir decode just gets repeated.

Looks a bit like a timing issue? I guess I need to check with HifiDunio? I note your nano is v3 and mine is 3.1. Could that make a difference?
 
Last edited:
Vincent, I have also tried a genuine apple remote and the symptoms are the same as using my phone to emulate. It can get stuck in either volume up or volume down depending on the preceding keypress. Using debug mode with print statements to the serial monitor, most of the time getIRkey() returns 0 via line 1227 (i.e. a "repeat"). So the last valid ir decode just gets repeated.

Looks a bit like a timing issue? I guess I need to check with HifiDunio? I note your nano is v3 and mine is 3.1. Could that make a difference?

That's weird. Are you getting IR noise from some external source, like an energy saving lamp?
We'll debug this, but now I'm away from home for a week and I can't really look into it.
The Arduino version should not make a difference.
If you add a PRINTLN(duration); line 1224, what does it say during the spurious repeats?
 
If I wanted to install the volume knob in a different box than the rest of the electronics, what's the maximum distance (cable length) between the two boxes?

I am asking this because I am thinking to put the volume control close to the power amps, which are close to the speakers.

I quote from an encoder FAQ found online:

Q: How far away can I place my
encoder from my system?
A: There is no set answer to this question.
Many factors play a role in determining
the maximum length of cable that can be
used to connect the units together. The
largest problem with running long lengths
of cable is that the cable becomes more
susceptible to noise. This is due to the
capacitance of the cable, the cable acting
as an antenna, and the loss of power
through the cable. The maximum distance
of cable can be achieved by following
some basic wiring principles. Do not run
the cable near objects that create a lot of
electrical noise. This includes AC motors,
arc welders, AC power lines, and trans-
formers. Use twisted pair cabling when
using the signal and its compliment, and
shielded cabling when running any type of
signal. Use the highest voltage available
for the output voltage. For example, if the
encoder will output 5 to 24 volts, then use
24 volts. Use an open collector or differ-
ential line driver output with a differential
receiver so that the maximum amount of
current can be sink/sourced. If you are
using the encoder as an input to more
than one controller, use a signal amplifier.
This is also a good way to help increase
the distance a signal can travel. Typical
maximum distances for a differential line
driver are around 100ft., or more when
using a differential input, and for an open
collector the distance is around 35 ft.

So it seems the maximum cable length should be around 10 meters.
 
That's weird. Are you getting IR noise from some external source, like an energy saving lamp?
We'll debug this, but now I'm away from home for a week and I can't really look into it.
The Arduino version should not make a difference.
If you add a PRINTLN(duration); line 1224, what does it say during the spurious repeats?

Hi Vincent. Its not lighting I think. I have tried it in 2 different locations and even in the dark.

I am typically getting something like this for a "repeat" code on the console for duration :

0
0
2187

This is from a single button press. In this case the volume direction is "stuck" in either up or down mode.

Occasionally the IR code will be detected correctly (and then I can change volume direction). In this case duration will be about 4400.

This is where I put the duration print statement :

while ((duration = pulseIn(PIN_REMOTE, HIGH, 15000)) < 2000 && duration != 0)
{
// Wait for start pulse
}
PRINTLN(duration);
 
Last edited:
Some USB DACs out there are able to set output volume control according to the volume setting on the computer. It would be super convenient if it was possible to feed the volume setting from an USB audio interface to the Arduino in order to control the LDRs from the voume setting on the audio player of the computer. Is that possible?