Analog inputs as switches & Midi

:)Just a quick question! Can I use 4 seperate piezos with 4 separate analog inputs to act as switches that when activated will send 4 separate midi notes from my Arduino and is it possible to be constantly outputting a midi note value of “0” when none of the switches are activated? Thanks! :slight_smile:

Umm, yes :smiley:

Cheers mowcius! :slight_smile: Now to experiment with a bit of code! I’ll be back of course :)Ha

Um…you need to do a bit of somewhat more elaborate (voltage) buffering and (software) debouncing to use piezos properly.

For the first, piezo elements can spike in the hundreds of volts, and you need to protect your Arduino from that.

For the latter, the output voltage curve of the piezo is more like a spike, followed by a drop, and a series of lesser spikes as the crystal “bounces back.”

I don’t have the time to search at the moment, but look around for articles/posts about using Arduino as a drum machine; at least one user has solved both these issues already.

I should also add – you probably know this already – a continuous send of a note value of zero is non-standard for MIDI. You might be thinking of an off message: but that needs to be note-specific.

My own silly little Arduino MIDI code has a variable called sounding(), which flags when a noteOn has been sent, and tracks when the corresponding button has been released so as to send the appropriate noteOff event. It’s probably been more elegantly done in the various libraries that are coming together for MIDI on the Arduino.

This will help as a start:


Thanks mowcius & nomuse!!! :slight_smile: yes nomuse I basically need a midi note value of “0” outputting just the once after each piezo has been touched because the zero is to reset my movies in Quartz Composer before the next one can be played by the next piezo. :slight_smile:

Aha. Yah, I use MIDI to control Qlab, so I also designed the Arduino routines I wrote to work well with it.