Max for Live: Light Dependent Resistor

No additional objects or packages are required for getting the Arduino's data to Max or Max for Live via USB serial. The first Arduino-Sensor-Circuit needs no adjustments for this example. It will drive a subtractive synth, with the light intensity controlling the cutoff frequency of a lowpass filter.


Breadboard Circuit

The breadboard circuit for this example is the same used in the first Arduino-Sensor-Circuit:

/images/basics/ldr_input_fritzing.png

Arduino Code

The same Arduino code can be used to send data to Max or Max for Live:

      int analogInput = 0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{

  float value = analogRead(analogInput);

  Serial.println(value);

  delay(5);
}

Max 4 Live Patch

Receiving the data sent from the above Arduino code is managed with the serial object in Max. It needs the same baud rate as the sender (9600) as second argument and the Arduino's serial port ID as first argument. Clicking print gives the list of serial devices in the max console. Enter the result into the serial object (in this case 'd' for 'usbmodem').

Once the proper id is set, the metro object can be started using the toggle switch. Every ten milliseconds, data is read from the serial port. The following objects unpack and format the stream and turn it into an integer.

The resulting values are just scaled and used for the cutoff frequency of two parallel low pass filters.

/images/basics/arduino/max4live_ldr.png

LDR controlled subtractive synth in the Max device editor.


Additional Resources

This example works with the same approach.