Wednesday, December 26, 2012

Virtual Guitar String with Arduino and Max/MSP

Hello Guys,
It's been a long time since i am writing this blog. I was having a dream to generate music with hand gesture. I was looking for it. But finally i got an idea. Using Light Dependent Resistor (LDR) as a sensor, Arduino UNO as a PC interface and MAX/MSP as a Music Generator, finally i build a very basic hand movement music controller. And it sounds great....
The name behind Virtual Guitar String is that there is no string though we can change the tone of music...

Let's build it...


If you don't have an arduino, buy new arduino UNO R3 or any other product from
https://amzn.to/2QRr2IW
If you are new to Arduino, first download the Arduino environment from following link.
http://arduino.cc/en/Main/Software
For the first time users, install the driver as shown on this link,
http://arduino.cc/en/Guide/Windows#toc4


Software:
(1) Arduino Environment - http://arduino.cc/en/Main/Software
(2) Max/MSP - http://cycling74.com/products/max/ (Trial verson can work perfect)


Hardware :
(1) 100k ohm register (one)

(2) LDR (one)
(3) Bread board (one)
(4) wires (4 to 5)
Connect the componets as shown in the schematic.


Diagram 1:




Diagram 2:




Diagram 3:





Arduino Environment:

For sketch, open Arduino Environment, and go to
File->Examples->Firmata->StandardFirmata
So, standard Firmata sketch will open. Now Upload the sketch by pressing Ctrl+U or File->Upload option. So sketch will upload on Arduino UNO board.
Now, close the Arduino Environment.

Maxuino:
Now go to following link and download Maxuino 007. you can download latest version Maxuino014, but i prefere to download Maxuino007, because in my case latest version was not working properly. So, download Maxuino007.zip
http://www.maxuino.org/archives/category/updates
or directly go to
http://maxuino.org/media/maxuino-007.zip


Max/MSP:
Download the Max/MSP from this link (Trial verson works perfect) and install it...
http://cycling74.com/products/max/

Now, extract the file maxuino-007.zip and open the folder maxuino-007.
Open the file Arduino_test in Max.
So it will look as shown in following figure.


Now, go to FILE->SAVE AS. Save the file as arduino_test_guitar in the same folder.
Follow the steps shown in figure. Make sure you have connected Arduino Board with PC.
Step 1: Select Appropriate port. In my case it is COM5.
Step 2: In analog pins On/Off block there is first trigger button. Check that button to check it as shown in following figure.



Step 3: In this step you don't need to do anything. You can see the value in analog Pins Input block, first value will take place the same value as the analog pin 0 will havem the value will be in between 0 to 1. As shown in figure 3.
Step 4: Make new object by pressing 'n' or by double clicking in free space. Give the name "s trig". And connect it as shown in following figure. The output of analog pin 0 to input of created object "s trig". Save the patch by just pressing Ctrl+S.


Now onward all the processing is done in new patch. This patch must remain open. Go to FILE->New Patcher or pressing Ctrl+N, new patch will open. 
Make new patch as shown in follwing figure.


If you don't know how to generate this block, don't worry. just copy following code, and paste in New Patcher window of Max.

CODE:

{
 "boxes" : [   {
   "box" :    {
    "maxclass" : "ezdac~",
    "id" : "obj-3",
    "numinlets" : 2,
    "numoutlets" : 0,
    "patching_rect" : [ 86.154442, 202.691116, 45.0, 45.0 ]
   }

  }
,   {
   "box" :    {
    "maxclass" : "newobj",
    "text" : "* 1000.",
    "id" : "obj-241",
    "numinlets" : 2,
    "fontsize" : 12.0,
    "numoutlets" : 1,
    "patching_rect" : [ 86.102966, 110.455551, 49.0, 20.0 ],
    "outlettype" : [ "float" ],
    "fontname" : "Arial"
   }

  }
,   {
   "box" :    {
    "maxclass" : "newobj",
    "text" : "saw~",
    "id" : "obj-252",
    "numinlets" : 2,
    "fontsize" : 12.0,
    "numoutlets" : 1,
    "patching_rect" : [ 86.154442, 147.918884, 39.0, 20.0 ],
    "outlettype" : [ "signal" ],
    "fontname" : "Arial"
   }

  }
,   {
   "box" :    {
    "maxclass" : "newobj",
    "text" : "r trig",
    "id" : "obj-185",
    "numinlets" : 0,
    "fontsize" : 12.0,
    "numoutlets" : 1,
    "patching_rect" : [ 86.102966, 69.837769, 34.0, 20.0 ],
    "outlettype" : [ "" ],
    "fontname" : "Arial"
   }

  }
 ],
 "lines" : [   {
   "patchline" :    {
    "source" : [ "obj-252", 0 ],
    "destination" : [ "obj-3", 1 ],
    "hidden" : 0,
    "midpoints" : [ 95.654442, 187.959442, 121.654442, 187.959442 ]
   }

  }
,   {
   "patchline" :    {
    "source" : [ "obj-252", 0 ],
    "destination" : [ "obj-3", 0 ],
    "hidden" : 0,
    "midpoints" : [  ]
   }

  }
,   {
   "patchline" :    {
    "source" : [ "obj-241", 0 ],
    "destination" : [ "obj-252", 0 ],
    "hidden" : 0,
    "midpoints" : [  ]
   }

  }
,   {
   "patchline" :    {
    "source" : [ "obj-185", 0 ],
    "destination" : [ "obj-241", 0 ],
    "hidden" : 0,
    "midpoints" : [  ]
   }

  }
 ]
}



Now, save this patch. And check out the circuit in progress. I am sure, this will work. This is done,
Check out my video of Virtual Guitar String by Arduino and LDR...



For Song controlled using Hand Gesture make New Patcher as shown below...

If you don't want to build this, just copy and paste the following code...

CODE:
{
 "boxes" : [   {
   "box" :    {
    "maxclass" : "newobj",
    "text" : "- 200.",
    "outlettype" : [ "float" ],
    "patching_rect" : [ 134.879517, 72.621559, 41.0, 20.0 ],
    "fontname" : "Arial",
    "id" : "obj-16",
    "numinlets" : 2,
    "fontsize" : 12.0,
    "numoutlets" : 1
   }

  }
,   {
   "box" :    {
    "maxclass" : "newobj",
    "text" : "freqshift~",
    "outlettype" : [ "signal", "signal" ],
    "patching_rect" : [ 59.093952, 111.469749, 60.0, 20.0 ],
    "fontname" : "Arial",
    "id" : "obj-15",
    "numinlets" : 2,
    "fontsize" : 12.0,
    "numoutlets" : 2
   }

  }
,   {
   "box" :    {
    "maxclass" : "ezdac~",
    "patching_rect" : [ 65.633759, 153.987793, 45.0, 45.0 ],
    "id" : "obj-14",
    "numinlets" : 2,
    "numoutlets" : 0
   }

  }
,   {
   "box" :    {
    "maxclass" : "newobj",
    "text" : "* 800.",
    "outlettype" : [ "float" ],
    "patching_rect" : [ 134.727707, 40.554146, 42.0, 20.0 ],
    "fontname" : "Arial",
    "id" : "obj-241",
    "numinlets" : 2,
    "fontsize" : 12.0,
    "numoutlets" : 1
   }

  }
,   {
   "box" :    {
    "maxclass" : "newobj",
    "text" : "r trig",
    "outlettype" : [ "" ],
    "patching_rect" : [ 135.0, 9.0, 34.0, 20.0 ],
    "fontname" : "Arial",
    "id" : "obj-185",
    "numinlets" : 0,
    "fontsize" : 12.0,
    "numoutlets" : 1
   }

  }
,   {
   "box" :    {
    "maxclass" : "newobj",
    "text" : "sfplay~ 1",
    "outlettype" : [ "signal", "bang" ],
    "patching_rect" : [ 11.0, 60.0, 59.0, 20.0 ],
    "fontname" : "Arial",
    "id" : "obj-11",
    "numinlets" : 2,
    "fontsize" : 12.0,
    "numoutlets" : 2,
    "save" : [ "#N", "sfplay~", "", 1, 120960, 0, "", ";" ]
   }

  }
,   {
   "box" :    {
    "maxclass" : "message",
    "text" : "open",
    "outlettype" : [ "" ],
    "patching_rect" : [ 69.0, 9.0, 37.0, 18.0 ],
    "fontname" : "Arial",
    "id" : "obj-10",
    "numinlets" : 2,
    "fontsize" : 12.0,
    "numoutlets" : 1
   }

  }
,   {
   "box" :    {
    "maxclass" : "toggle",
    "outlettype" : [ "int" ],
    "patching_rect" : [ 11.0, 8.0, 35.0, 35.0 ],
    "id" : "obj-8",
    "numinlets" : 1,
    "numoutlets" : 1
   }

  }
 ],
 "lines" : [   {
   "patchline" :    {
    "source" : [ "obj-241", 0 ],
    "destination" : [ "obj-16", 0 ],
    "hidden" : 0,
    "midpoints" : [  ]
   }

  }
,   {
   "patchline" :    {
    "source" : [ "obj-185", 0 ],
    "destination" : [ "obj-241", 0 ],
    "hidden" : 0,
    "midpoints" : [  ]
   }

  }
,   {
   "patchline" :    {
    "source" : [ "obj-8", 0 ],
    "destination" : [ "obj-11", 0 ],
    "hidden" : 0,
    "midpoints" : [  ]
   }

  }
,   {
   "patchline" :    {
    "source" : [ "obj-10", 0 ],
    "destination" : [ "obj-11", 0 ],
    "hidden" : 0,
    "midpoints" : [ 78.5, 53.5, 20.5, 53.5 ]
   }

  }
,   {
   "patchline" :    {
    "source" : [ "obj-11", 0 ],
    "destination" : [ "obj-15", 0 ],
    "hidden" : 0,
    "midpoints" : [ 20.5, 90.357758, 68.593948, 90.357758 ]
   }

  }
,   {
   "patchline" :    {
    "source" : [ "obj-15", 0 ],
    "destination" : [ "obj-14", 0 ],
    "hidden" : 0,
    "midpoints" : [  ]
   }

  }
,   {
   "patchline" :    {
    "source" : [ "obj-15", 0 ],
    "destination" : [ "obj-14", 1 ],
    "hidden" : 0,
    "midpoints" : [  ]
   }

  }
,   {
   "patchline" :    {
    "source" : [ "obj-16", 0 ],
    "destination" : [ "obj-15", 1 ],
    "hidden" : 0,
    "midpoints" : [ 144.379517, 103.666145, 109.593948, 103.666145 ]
   }

  }
 ]
}


Check out my video of Hand Gesture Music Control Demo 1 and Demo 2...

Demo 1.




Demo 2.



Thank you for visiting my blog....
I hope you understood the process very well...
I am sure you will make your own Hand Gesture Control Music System... 
See you later...

5 comments:

  1. This was very helpful for what I needed to do. Thank you so much for posting this.

    ReplyDelete
  2. Hi, thank you very much for this blog! I am new to Max Msp and I would like to know what i need to do on the patch to make the song input into a direct sound input??

    ReplyDelete
    Replies
    1. You can give output of sfplay object to ezdac.
      If you don't have an idea about thia, download my patch and connect sfplay to audio out (ezdac).

      Hope you get it worked. For.more details feel free to contact me.

      Delete
    2. You can give output of sfplay object to ezdac.
      If you don't have an idea about thia, download my patch and connect sfplay to audio out (ezdac).

      Hope you get it worked. For.more details feel free to contact me.

      Delete