Audio Visual Installation Project: HELP

Anthony Lee's icon

Hi,

I am a Sound Design student looking for some help with my final major project. I want to create a responsive sound installation using Max and Arduino.

I am very new to both of these areas so was hoping to find help here from more experienced users.

My idea is to have 16 LDR's all linked to an arduino mega 2560; sending data when there is a lack of light. From there I would like to feed it through to Max to trigger loops of sound and fx for the loops such as reverb.

I am looking for someone or a group to help guide me through this project!

Would be very grateful to anyone who can help me :)

Source Audio's icon

Sure, could You please precise what all You allready learned about parts that You want to use,
and what is missing ?
I mean do You have an idea how sensitive LDRs are, have You ever tested one, or tried
to figure out how to isolate 16 LDRs from each other, not letting them react to the same light source etc ?
The rest is rather easy, just hook them to analog pins, set the threshold, report
when light goes above or under, and send that info to max via serial.
Then in max one can use 16 values to trigger / control whatever.
How about Arduino ? Tested some simple examples of analog read, serial send etc ?
There are many arduino LDR tutorials available, to get basics going.
I am sure You will get all help You need here to move on, just ask along the way.

Anthony Lee's icon

Yeah, I have an Arduino Mega 2560, some small LDRs and 10k Resistors. So far I have been able to use basic tutorials to hook one LDR up and get it responding using the standard firmata software. I figured if I maybe repeat the process I have done 16 times off the same arduino board then the LDRs will react differently and can be assigned multiple roles...

The main issue I am facing is getting the connection between Max and my Arduino as I have relatively no experience in that area what so ever!

Thanks!

Source Audio's icon

Ok, so You will be measuring voltage level on 16 inputs,
and controling max with the result.
There is one decision to make :
If You know what exactly You want to control in Max, You can
optimise and reduce ammount of data being sent to Max over serial port.
Let's make a simple example : If all You want from LDR-1 is to switch something On/Off
depending on Light conditions, You would set threshold for On/Off change, and
send the Switch State 1 or 0 only when state changes, all in Arduino code.
On the other hand, if You want LDR-2 to act like Volume Control for Sample Playback,
then You would need to send Voltage level, scaled to some range usable in max, and send that
info over serial, with fast enough interval in order to get smooth Volume changes.
---------
I think You can follow me.
So please post Your plan on the matter, so we can figuere out the best way to collect and send the values to max.
Maybe someone else will join in, more people involved, more interesting it is.
If You want to stay flexible, and don't want to mess up with Arduino, You could decide to just read 16 Voltages,
send them to Max, and then apply all the scaling, filtering etc. in Max.
But that would mean much more data being sent over serial

Source Audio's icon

And please, don't try any of this complicated maxuino and similar setups.
You have to do it with own brains.
First thing is just to set serial baud rate properly, and send something to max to get communication going.
Can You do that ?
Do You need a simple example like reading one LDR on A0, sending the values
to max and reading them there ?
Would not need much time to do so.
Just let me know.
Later, when 16 values need to get sent over, one would need some kind of channel info.
Either by sending a string of 16 values all the time, which one can unpack in Max (not really my choice)
or to give each channel some kind of indentifier, like letters A,B,C etc
then using route object in max one could detect which channel is received.

Anthony Lee's icon

Thank you so much! This is all so helpful, I think I'm able to follow most of what you're saying.

I think the best and easiest way for this project would to be consistent with my approach in max so I think a volume fader send would be best when receiving data from an LDR, that way I can transfer that knowledge across to an effect fader etc.

How would I start setting up a blank project in max?

Thanks again for your time, I really appreciate the help!

Source Audio's icon

Don't worry, You will get everyting on time.
On Max side, first You need to get data in.
In case of plain Arduino it will be serial object.
There are some other options, but let's keep it
simple for the time being.
One has to work on both sides, Max and Arduino.
The baud rate has to match on both sides.
Have a look at following simple Arduino code :
-----------------------
void setup(){Serial.begin (57600);}
void loop() { int LDR1 = analogRead(A0);
Serial.println(LDR1);
delay (20);}
-----------------------
Here we set Arduino to start Serial communication at 57600 baud,
read analog pin A0, and send the value to serial object, each value on new line.
Pause for 20 ms and then repeat / loop.
Upload this short sketch to Your Arduino.

Max Patch
Copy patch and select New From Clipboard in Max.

Same baud rate should be set in Max serial object.
You can place single serial object in empty patcher and
give it arguments a 57600.
So that would be {serial a 57600} "a" for port and "57600" for baud rate.
Port "a" would not necessary match the port Your Arduino would be, but that does not matter,
one can set that later.
Instead of posting here as text, have a look at the max patch,
that would let You select Your Arduino, poll the data coming in etc.
I will place comments in the patch, to help You easily get what is going on.
And only 1 piece of software should be communicating with arduino at same time,
so if You want to get data in Max, close Arduino Serial Monitor.

Source Audio's icon

And I still think that writing Arduino Sketch and Max Patch will soon become easy for You.
BUT getting this 16 LDRs to function independently, which means each of them having own
light "situation" will be quite a challenge.
There are several kinds of LDRs, they also have different Resistance Curves and Range,
and also differ in sensitivity to small changes of light intensity.
Getting 16 usable and independent control values from 16 of them in a same room
will be difficult.
But, one thing after another

Anthony Lee's icon

Hey,

Sorry for the delay. I've been very busy at work!

So I've successfully managed to get a signal through to max following your instructions! Thank you so much, this is a huge step in the right direction. I'm not entirely sure of everything that's going on but for now I'm happy it's working!

I now need it to automate volume of a sample, what next steps would you recommend?

In terms of the 16 LDR's working independently, would it be easier to say have 4 initial samples (with volume automation attached) and then 4 effects for each loop? Would this make things any easier?

Source Audio's icon

Hi Anthony, don't worry , it is Your project, Your tempo...
We are still at the basics here, so I think I might tell You a bit about things
that one wants to achieve, in technical terms.
As first it is important to control amount of data sent and processed in Max.
On Arduino side, we want to send values only if something changed,
and not every 10 miliseconds.
On Max side the same, volume control needs to move only if
there is a value change, otherwise it will allways be busy, stealing CPU cycles.
Now that computers are so damn fast, that might not seem an issue,
but it is allways better to have things set right, because too much strain on the scheduler in
Max might disturb timing of other important events.
Now enough of theory.
Let's forget all above for the moment, as we deal with just 1 LDR.
Here is a max patch with 1 Audio Player, and it's Volume control
is controled with LDR value.
I have used objects which I prefer to use, it could have been done in different
way, with different objects as well.
If You get interested by one or the other object just click on it and open it's help,
to get more info about it.

Max Patch
Copy patch and select New From Clipboard in Max.

And here is the patch :

Source Audio's icon

As next You will for sure want to test several LDRs connected, not only because of
Arduino sketch, but in first place to see how indenpendent of each other they react to light.
That will be the most important part of the whole project.
Do You have any plans about the room where all this is going to be installed and running ?
And what will happen there in terms of light ?
LDRs are not only sensitive to light coming from the front, but also from the back and sides.
It might be helpfull to place them in some tubes, well darkened and isolated from the back.
Like that they will be more focused. Tube can be made out of ballpen or something similar.
On software side, one can do what one wants, You are right that it is less critical to have
effect control get a bit influenced by volume control due to "crosstalk",
then Playback Start/Stop, which would be so obvious.
I think 16 LDRs are going to be difficult to tame.
Would You maybe consider using also other sorts of sensors in combination with LDRs?
There are sooo many, from temperature, pressure, humidity, movement just to name a few.
------------
Now back to software, what would You prefer as next step ?
On one side one has to make arduino sketch for more LDRs, and maybe put some
data smoothing inside.
I would really prefer going step by step, as it makes no sense that I make everything,
but rather help You do so.

Anthony Lee's icon

Okay, so I've been reading up on the help section of everything I'm not sure about and I think I can definitely understand a lot more than I did! What I would like however, is to reverse the signal from the LDR? I've tried adding an object with 'jit.reverse' in several places however can't seem to make it happen.

Basically what I am aiming to achieve is a lack of light increasing the particular effect. I will be building an installation with a central light pointed at a wall of LDRs, when a person or group cover the LDRs the sounds playing will start/develop etc.

I think you've given me a great basic model to work from and experiment with and I am really looking forward to learning more about Max, any tips from now to help reverse the signal?

Also if you have a moment, I'm thinking about trying to run this as an independent loop/system (without my computer) what would you recommend for this type of thing? Is a computer completely necessary?

Source Audio's icon

Hi Anthony,
reversing LDR values can be done either in Arduino or in max.
in max You could insert {scale 0 1023 1023 0} to do so.
in Arduino one could use map with same settings.
Now to computerless option...
Maybe there are some toys arround which can play samples and insert
effects and automate them as well ?
I don't know really, I dont use such gear.
Something could be done with Teensy 3 and Audio schield,
https://www.pjrc.com/store/teensy3_audio.html
but maybe one might need a few of them to have 4 channel automated Audio and effects.
Would that not be a bit too much ?
I mean learning all that stuff...
What You want to do can be easily done with secondhand MacBook,
2 GHz dual core, would be just fine.
One buys that for 100 $ theese days.
-----------------------
Back to the code, here are 2 different approaches to scanning 16 analog inputs,
and applying some hystheresis in order to reduce jitter.
Version "a" is selfexplaining, having all 16 in plain text,
the other one is much more effective, it iterates over 16 inputs
and sends Input number and value pairs to serial out.
Both have corresponding Max patch.

Archive.zip
zip
Anthony Lee's icon

Hey,
Could you explain the {scale 0 1023 1023 0} bit? I'm unsure what exactly the placement of the zeros mean with regards to the scale etc of the data.
Thanks so much for the two files, I will be giving them a big look over today. I don't have the necessary equipment yet to fully set up 16 LDRs but once I get some more wire I should be able to!
I think buying a secondhand mac like you said would probably be the easiest route to go computerless or just to not have mine sat in the building for 3 days, I'll have a quick search later today!

Source Audio's icon

Anthony, the scale object, (or map as well) takes incoming stream of ints or floats and scales them
according to arguments set.
Have a look in scale help file.
You have data coming from LDRs, ranging from min 0 to max 1023.
If You want to invert that, than You scale it like I mentioned.
You could also use scale to do any other range scaling,
like {scale 0 1023 127 0}, which would produce 127 .. 0, out of incoming 0 ..1023.

Source Audio's icon

Here's me again ...
I suggested using second hand macbook or similar, but
forgot to mention that older Macs running OSX 10.6
will not really be suited for Max7.
One could install OSX 10.7 and get it running, but if You
need a lot of CPU power, depending on effects used,
Max 4.6 would be the ideal version to do so.
Or maybe Max6xx ?
Anyway, when You get so far to finalise the project,
I'll be glad to help You convert the project to older Max version if necessary.

Anthony Lee's icon

Hey,
Sorry again for the late reply! I've got a hand in at the moment so I'm focussing all my studies on completing that for now.

If I could quickly back track to just one LDR responding, how would I go about trying to make the response more dynamic?
For example, when the LDR is in the light the track can still be heard at a relatively normal volume, and when the light is blocked then the volume just rises slightly, what if I wanted to make it so that when the LDR is in the light, the volume is at 0 and when the light covered then the volume is 100? Do you kind of understand what I mean?

Thanks!

Source Audio's icon

Hi Antony,
It is clear that LDR will not report full light 1023 or 0 totally dark values.
I told You that from the beginning.
You have to watch what range You get in Max when light changes,
and adjust the scaling factor.
Let's do It :
If under full light Your LDR sends value 800, and under " no light "
it sends 100, then You could set scale parameters to :
{scale 100 800 1. 0.} , that means when LDR sees "dark" (value 100) volume wold be at full 1.
and when LDR sees full light (value 800) volume will be at 0 = silent.
---------------
Unfortunately, this scaling will depend on Room conditions, and the way LDR's
are built, exposed to light etc.
So be prepared to tune the scaling factor, depending on circumstances.

Anthony Lee's icon

During testing I've also realised another problem, My LDRs are not sensitive enough to pick up the change in light over around 30cm, I can view the numbers changing in the serial data however the volume does not reflect it unless the light source is extremely close, how would you recommend I get more versatility out of it? Larger LDRs or is there a way in max to do this?

Source Audio's icon

The first part is getting most out of LDR's.
I told You there are different kinds, having different sensitivity, and
resistance.
Also that resistor sitting between +v and LDR has to be taken into account.
--------------
That is physical task to solve.
So You need to look where You can buy LDRs, see their specification, and buy
ones that fit best for Your needs.
Don't ask me here to tell You which...
If the ammount of Light that will change in that Room, does not produce
enough of resistance in LDR's and in that sense enough numbers
that could be used for Volume or similar controls in Max, then You have to change something.
Produce more Light change, or give up light and LDR's and go with distance sensors or something else.