Mug Music: Turn Water Into an Instrument With Arduino and ChucK

53K32839

Intro: Mug Music: Turn Water Into an Instrument With Arduino and ChucK

What if you could turn any conductive surface into an instrument? Like, say...a mug of water? Best of all, it's cheap; you'll only need $1 worth of extra electrical components (not including the Arduino).

For this project, my friend Harvest and I combined Disney's Touché touch-sensing system with Arduino, and then used ChucK to generate music based on the input. Rain falls gently in the background, and when the user approaches, they can trigger notes on a whole-note scale by touching the mug. Touching the water directly results in some lovely raindrop-inspired, high-pitched notes. Finally, touching the water while also touching a grounded surface will trigger a thunderclap!

Some thank-you's are in order:

  • Disney's original Touché paper
  • madshobye's Touche for Arduino Instructable
  • madlabdk's github project, which implements a more human-readable, less efficient encoding for the data, which we used, because it made it easy to feed the data into ChucK
  • The makers of ChucK, because it's an awesome programming language for synthesizing music (OK, I'm biased, it's from my school)

Prerequisites:

You will find this Instructable much easier to follow if you have a basic understanding of circuits. Additionally, if you want to edit the musical behavior, you'll have to use the ChucK language.

Common problems, things to watch out for, etc:

Make sure your laptop is properly grounded when you do this (e.g. plug it into a wall). Otherwise you'll get some weird readings. Additionally, you may have to alter some of the values in the springshowers.ck file in order for this to work for your personal setup. We used a plain ceramic mug.

Github:

A .zip download of all code is available at the next step, but here's the github repo if you want to download the code from there as well.

More projects:
 Check out my blog at bonnie-eisenman.tumblr.com to see what I'm up to.

STEP 1: Materials and Setup

HARDWARE

You will need one each of the following:

Resistors: 10k, 1M, 3,3k

Capacitors: 100pf, 10nf

Diode: 1N4148

Coil / inductor: 10mH

We purchased these from Mouser. This sample shopping cart contains enough materials for 3 such projects. It comes out to  about $1.11 per project for all of these components, not including shipping!

Additionally, you will need an Arduino, breadboard, jumper wires, and an alligator clip -- all of which should be pretty standard. 

SOFTWARE

Install ChucK and the Arduino IDE. Then download the mug-music-master.zip file from this step, which contains all necessary code.

CIRCUIT

See attached image for the circuit image, taken from this Instructable, which includes instructions on how to setup the circuit.

You'll want to set up the circuit on a breadboard, and connect an alligator clip to the end where the "object" should be. We then dunked the free end of the alligator clip into a mug filled with water, and plugged the Arduino into our USB port.

STEP 2: Upload the Arduino Sketch

The attached Arduino sketch is taken from madlabdk's github repository. The only difference is that we added a delay() line to slow the rate of new data.

Upload it without modifications to your Arduino. (This file is attached here, or go back a step to download all relevant code.)

If you want to change the frequency of notes later, you can change the delay duration, but for now this will work.

STEP 3: Run the ChucK Code

Take a look at the full directory of code; you should see two ChucK files.

simplest.ck is a demonstration of the bare minimum necessary to interact with the Touche output from ChucK. It contains a simple sin wave oscillator and interprets input as MIDI notes.

springshowers.ck is what you see in the YouTube video, and is more complicated. For fun, I suggest running springshowers.ck first. :)

You can experiment with ChucK and simplest.ck to do some cool things on your own, afterwards!

Run either as a normal ChucK program. You have two options:

  1. Using MiniAudicle: open the file with MiniAudicle, start the Virtual Machine, add the correct serial port number as an argument, and click "add shred." If you don't know the serial port number, skip that step -- it will output your options when you run it. Pick whichever corresponds to your USB port.
  2. Command line: run "chuck springshowers.ck:[port number]"

Both should have the same effect.

That's it! You're done. Have fun playing around with your new instrument!

)

37 Comments

I realize I'm a little late to the party, but I've been having some problems with sound. Everything works perfectly and I can hear the rain sounds, as well as changing them, but there is a really distorted loud noise that happens every few seconds. Any ideas of how to stop this?

Hi,I don't know what I do wrong but when I run springshowers.ck, chunk's console write this:

[chuck]:(2:SYSTEM): running virtual machine...

[chuck](VM): sporking incoming shred: 1 (springshowers.ck)...

0: COM3

serial device #3 not available.

maybe I don't know well how can I enter in port number.

Please can some body help me, thanks

great project. i try to combine it with my mp3shield - and therefore only have the pin 10 free instead of pin 9 - that should work, shouldn't it? I just changed the pin 9 to 10 in the code. It seems to work ( i can see my arduino picks up the different touches - ) but it does not change the sound of the mug depending on where I touch the mug... any idea?

Thanks for your help!

do you have more photos of the circuit?

TY!

Hi bonnie, as of now, we are trying your experiment but we dont have the 10mH.could we just alter or modify the circuit without using the inductor?how?we need your help.also for the chuck software,there were so many serial port displayed in the console and we dont know how to display the functional one.thank you

That's an awesome project. I'm a beginner in electronic, also i can't find all those compounds at low price (or without shipping costs too high).

Do you think i can replace the coil and the 100pF by something else ? What will happen if i take a 10MF capacitor instead of a 100pF one for example ?

Please excuse me for thoses stupid questions, thank's for your answers !

Hi,

is it possible to get a more detailed picture of the circuit?

I have tried to build this but keep getting an arpeggio playing over and over regardless of whether I am touching the mug or not? Any ideas?

Thanks

Update. there is actually a provision for that in the chuck file. just search for

// Loitering reading

if (val < 28)

and replace it with a value that suits your setup. i am using 35 and no more screeching. thanks again to the author for a very configurable code. Cant thank you enough :)

Rohan, you're welcome! Glad you managed to debug it and got it working :)

i think the sound is due to the change from the maxPos from 1 in air to 30~35 in the water mug. I fixed it by putting a threshold depending on the stable maxPos Value in water. I think it might vary at times, so be sure to see the difference on the serial monitor. The if condition helped me solve it. hope it works for you too.

///Code for threshold

if (maxPos > 35){

Serial.print(maxPos, DEC);

Serial.print(" ");

Serial.println(maxVal, DEC);

} else { Serial.println( "UnderThreshold");}

delay(200);

}

I'll try to post a more detailed picture soon (it's unassembled at the moment).

In general, you can debug by viewing the Arduino serial output directly in the Arduino IDE. It should spit out a stream of lines with two numbers per line; the first number is the one that's usually interesting and it's what this sketch uses. It should remain constant when you're not touching the mug.

If it isn't remaining constant: something's wrong with your circuit and/or setup. Is your laptop plugged in to a grounded outlet? Is the mug on a non-conductive surface? Did you double-check to make sure that nothing's touching that shouldn't be in your circuit, like an alligator clip that's touching a wire? (I've made all these mistakes, haha.)

If the number IS remaining constant: congrats, it's working! You probably just need to mess with the numbers in the sketch. Try loading up simplest.ck and experimenting from there.

firstly thanks for this awesome project... i seem to have the same problem and i have checked everything multiple times. the arpeggio just won't go! :(

Hi,

Great project !

I'm using a Human Body Touch Sensor Module bought on DX for 2.53$ as a shortcut, just to test the idea and then decide about the circuit.

Anyway, it works but in addition to the very nice Chuck sounds I'm getting bad noise from time to time.

Can you tell what is the expected range of values for curVal (and later for maxVal, maxPos) ?

Thanks !

Avi

This is what we got (can hear the bad sound interrupting....):
https://www.dropbox.com/s/1ukw4xajnqgcyqi/2014-12-14%2018.50.52.3gp?dl=0

can someone (who has made the circuit) post the different arduino serial output in different cases so that i can stimulate it without the circuit or maybe some other sircuit

Hello there, I loved the final result you get, I have built the circuit and connected to the arduino, just to confirm it was built right, I looked into the SerialMonitor and can see the data being sent over the serial port.

The problem I'm having is with the Chuck program, I have tried both methods you describe in the last step of the instructable, but can't get it to work... my COM port is 12, so I enter it as '12' and as 'COM12' but neither seem to work... both in CMD screen and miniAudicle I do get the list of ports available but don't know how to select my port. At the CMD screen I get COM1, COM2 and COM12 as options 0, 1 and 2, so I press 2 and there's no response, same goes for miniAudicle, I can see the same option in the Console monitor, can't write in the console screen, and don't seem to send as argument either... what am I missing? I have made sure the port is not reserved by arduino IDE or any other program, hope you can help...

Hi nick, you have to **launch** it with the right arguments. So run it once to figure out which port number you need, then remove the shred and run it again with the right arguments. (I think.) So in miniAudicle, try launching it with 2 as the argument to begin with.

Make sure you do NOT have the Serial Monitor in Arduino IDE open when you're doing this!

Hope that helps. :)

Thanks for your reply, for some reason when I attempt to remove the shred it prompts me an error (see pic), I hit 'Abort' and the VirtualMachine remains open with the shred loaded and can't add any shred after that...

I then close miniAudicle and try again as you suggest above, entering now #3 (as I added another device (phone in diag mode) just to make sure #2 as not being confused with COM2); I get the conditions in the pic shown below (please let me know if this is how it should look like) but the Arduino doesn't seem to communicate as the TX LED is not blinking (it should blink right?), I'm running in XP by the way...

More Comments