DIY Airpiano

Customising, building or repairing your own gear? Need help with acoustic treatment or soundproofing? Ask away…

DIY Airpiano

Post by BJG145 »

Back around 2010, Omer Yosher came up with the Airpiano.

Image

The original website is long gone, though you can still view it on WayBack. It was adopted by a Scottish musician called Jo Hamilton, who made a pretty cool video with it.

Image

https://youtu.be/DTp5MFgzqZk?t=126

Guardian write-up:

https://www.theguardian.com/music/2011/ ... -air-piano

They were sold in small numbers and then discontinued.

It's based on an Arduino and a set of eight IR sensors. There aren't many instruments around that use IR to trigger notes...the Naonext Crystall Ball (sic) can do it, but it only has five of them, which is a bit limiting. There's also a couple of DIY versions like the Flightdeck, which is conceptually quite close, with eight IR modules.

So inspired by those, I've decided to have a go. I ruthlessly reclaimed the Arduino with its Sparkfun MIDI shield from my last project (byebye Eletrunk), picked up a Sharp GP2Y0A21YK0F on eBay, and I've been messing around with that today.

Image

So far so good...after spending a couple of hours trying to remember how to do some basic coding and sorting out bugs like using "=" instead of "==" I was able to get it to trigger a couple of different MIDI notes for different levels...

https://youtu.be/WVkta4_Yaq8

The original Airpiano seems to have been configured to play a scale, with three octaves for different heights.

Encouraged by this, I just ordered another half dozen sensors, and I think I'll need to upgrade to an Arduino Mega to handle the extra inputs.

My enthusiasm for electronics, programming and woodworking vastly outweighs my skills though sadly, so I'll probably be back asking for help for the next stage. (Need to sort out a decent case next.)
User avatar
BJG145
Longtime Poster
Posts: 7665 Joined: Sat Aug 06, 2005 12:00 am Location: UK

Re: DIY Airpiano

Post by Eddy Deegan »

A very impressive first homebrew iteration of the concept! :clap:
User avatar
Eddy Deegan
Moderator
Posts: 9553 Joined: Wed Sep 01, 2004 12:00 am Location: Brighton & Hove, UK
Some of my works | The SOS Forum Album projects | My Jamuary 2025 works

Re: DIY Airpiano

Post by BJG145 »

Thanks Eddy!

Programming has always interested me, but I'm pretty basic, and I know there's some people on the forum who are handy at it, so, I'll just explain what I've got so far in case anyone wants some bedtime reading. ;)

I started by splicing together a couple of demos...one which reads and displays IR values (which seemed to go from about 3 to 30), and another to output MIDI notes, and so far I've got this.

/*
* getDistance
*
* Example of using SharpIR library to calculate the distance beetween the sensor and an obstacle
*
* Created by Giuseppe Masino, 15 June 2016
*
* -----------------------------------------------------------------------------------
*
* Things that you need:
* - Arduino
* - A Sharp IR Sensor
*
*
* The circuit:
* - Arduino 5V -> Sensor's pin 1 (Vcc)
* - Arduino GND -> Sensor's pin 2 (GND)
* - Arduino pin A0 -> Sensor's pin 3 (Output)
*
*
* See the Sharp sensor datasheet for the pin reference, the pin configuration is the same for all models.
*/

//import the library in the sketch
#include <SharpIR.h>
#include <MIDI.h>

//Create a new instance of the library
//Call the sensor "sensor"
//The model of the sensor is "GP2YA41SK0F"
//The sensor output pin is attached to the pin A0
SharpIR sensor( SharpIR::GP2Y0A41SK0F, A0 );

MIDI_CREATE_DEFAULT_INSTANCE();
int noteon = 0;
int olddist = 0;

void setup()
{
MIDI.begin(4); // Launch MIDI and listen to channel 4

}

void loop()
{
int distance = sensor.getDistance(); //Calculate the distance in centimeters and store the value in a variable

if ((distance >= 5) and (distance <= 6) and (noteon == 0))
{
MIDI.sendNoteOn(50, 127, 1); // Send a Note (pitch 50, velo 127 on channel 1)
noteon = 1;
olddist = 1;
}
if ((distance >= 9) and (distance <= 10) and (noteon == 0))
{
MIDI.sendNoteOn(60, 127, 1); // Send a Note (pitch 60, velo 127 on channel 1)
noteon = 1;
olddist = 2;
}
if (((distance < 4) or (distance > 7)) and (noteon == 1) and (olddist == 1))
{
noteon = 0;
olddist = 0;
MIDI.sendNoteOff(50, 127, 1);
}
if (((distance < 8) or (distance > 11)) and (noteon == 1) and (olddist == 2))
{
noteon = 0;
olddist = 0;
MIDI.sendNoteOff(60, 127, 1);
}
delay(10); // Wait
}

I had this idea of a variable "noteon" which remembers whether there's currently a note playing or not, and a variable "olddist" which is like a range; 1 for the low note, 2 for the high note, 0 for neither.

(To reproduce what I think is one of the modes of an Airpiano, I imagine multiplying the whole thing by 8 for an octave of sensors, and have a distance range divided into three height areas for three octaves. I picked that up from the demo here.)

With these DIY Arduino/MIDI instruments, there's always some "debounce" to get jittery sensors turning out a clean range, a clean note-on note-off. (Some commercial instruments are still quite bad at this.) So in the above, I trigger the lower note within a certain limited range of sensor values (5 or 6) but kill it with a wider range (below 4 or above 7). The idea was to stop fluctuations on the margin.

I'm aware it's pretty bad, and this is just a quick 1st draft, so I'm happy to hear any ideas about a better logic! I haven't thought about polyphony yet.
User avatar
BJG145
Longtime Poster
Posts: 7665 Joined: Sat Aug 06, 2005 12:00 am Location: UK

Re: DIY Airpiano

Post by Folderol »

I like it. I think the humble Arduino is grossly underestimated.
I can see you're using you're using an analog input (A0) and guess your just dividing the received value down for the octave steps. The mega would indeed readily give you an entire 12 notes (it actually has 16 analog inputs, so you could use some for volume, pitchbend etc.

Edit. I see I'm late :lol:

P.S
I always use a time based debounce. Accept the first change on a channel immediately, but then don't accept any changes within 50mS. Rinse and repeat.
User avatar
Folderol
Jedi Poster
Posts: 19728 Joined: Sat Nov 15, 2008 12:00 am Location: The Mudway Towns, UK
Yes. I am that Linux nut {apparently now an 'elderly'}
Onwards and... err... sideways!

Re: DIY Airpiano

Post by BJG145 »

Folderol wrote:I always use a time based debounce. Accept the first change on a channel immediately, but then don't accept any changes within 50mS. Rinse and repeat.

Right, yes. Time-based debounce sounds like a good idea...
User avatar
BJG145
Longtime Poster
Posts: 7665 Joined: Sat Aug 06, 2005 12:00 am Location: UK

Re: DIY Airpiano

Post by Eddy Deegan »

I've never done Arduino programming, but a quick search indicates that the language does support switch statements and array indexing.

At the moment you have the checks for distance ranges combined with the actions:

Code: Select all

if ((distance >= 5) and (distance <= 6) and (noteon == 0))
{
MIDI.sendNoteOn(50, 127, 1); // Send a Note (pitch 50, velo 127 on channel 1)
noteon = 1;
olddist = 1;
}
if ((distance >= 9) and (distance <= 10) and (noteon == 0))
{
MIDI.sendNoteOn(60, 127, 1); // Send a Note (pitch 60, velo 127 on channel 1)
noteon = 1;
olddist = 2;
}
if (((distance < 4) or (distance > 7)) and (noteon == 1) and (olddist == 1))
{
noteon = 0;
olddist = 0;
MIDI.sendNoteOff(50, 127, 1);
}
I would be inclined to do the range checking separately, put the result into an enumerated result value and then evaluate it in a switch statement. The specific ranges in your example code look slightly non-intuitive to me but I expect they are there for a reason.

In C (and I suspect the Arduino language) I would handle the distance like this:

Code: Select all


void loop()
{
   // Stuff ...

   int distance_range = normalise_distance(sensor.getDistance());

   switch  (distance_range) {

   case 1:
        // Insert logic here for when the actual distance is 0-2
        break;

   case 2:
        // Insert logic here for when the actual distance is 3-5
        break;

    case 3:
        // ... and so on
        break;

   // ... and so on
   }
}

// Example only: Translate actual distances into a range identifier
// In the below example, distances from 0-2 map to range 1,
// distances from 3-5 map to range 2,
// distances from 6-9 map to range 3,
// distances from 10-14 map to range 4,
// distances from 15-17 map to range 5,
// everything greater defaults to range 6
int normalise_distance(int actual_distance)
{
    int distance_map[] = 1,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,6,6,6;
    int max_mapped_distance = sizeof(distance_map) - 1;

    if (actual_distance > max_mapped_distance) {
        return 7;  // Or whatever...
    } else {
        return distance_map[actual_distance];
    }
}
There's nothing majorly spectacular I'm adding there but it might help you start to organise the logic in a slightly more manageable way. One advantage is that if you want to process a distance value differently then you can simply change the values in the distance_map array and not have to edit a bunch of 'if' statements with the new range checks.

If that makes sense?

You could also go further and extend normalise_distance() to return different values for the same range depending on if noteon is 0 or 1 which would save a bunch more 'if' statements in the calling code.
User avatar
Eddy Deegan
Moderator
Posts: 9553 Joined: Wed Sep 01, 2004 12:00 am Location: Brighton & Hove, UK
Some of my works | The SOS Forum Album projects | My Jamuary 2025 works

Re: DIY Airpiano

Post by Martin Walker »

Fascinating stuff BJG145!

And well done for getting octave switching on your very first session.

However, I gained an extra thrill out of discovering Jo Hamilton whose video demonstrating the prototype was truly haunting, so thanks for that too.

Martin
User avatar
Martin Walker
Moderator
Posts: 21477 Joined: Wed Jan 13, 2010 8:44 am Location: Cornwall, UK

Re: DIY Airpiano

Post by BJG145 »

Martin Walker wrote:I gained an extra thrill out of discovering Jo Hamilton

...yeah, she's quite cool...

Thanks for the programming tips Eddy, I'll study that. I wasn't fishing honest... ;)
User avatar
BJG145
Longtime Poster
Posts: 7665 Joined: Sat Aug 06, 2005 12:00 am Location: UK

Re: DIY Airpiano

Post by James Perrett »

Rather than upgrading the processor to gain more inputs, it may be worth just adding an analogue input shield like the one at

https://www.vellemanformakers.com/produ ... uino-ka12/
User avatar
James Perrett
Moderator
Posts: 15673 Joined: Mon Sep 10, 2001 12:00 am Location: The wilds of Hampshire
JRP Music - Audio Mastering and Restoration. JRP Music Facebook Page

Re: DIY Airpiano

Post by BJG145 »

James Perrett wrote:Rather than upgrading the processor to gain more inputs, it may be worth just adding an analogue input shield

Thanks James, interesting...I'd been wondering about going for one of these, which is cheaper (16 analogue inputs on the Mega compared to 6 on the Uno, which should be plenty); not sure how these "compatible" boards compare to originals, or how likely it is to work with the same Sparkfun MIDI shield and code, but can't go too far wrong for a tenner...(?)
User avatar
BJG145
Longtime Poster
Posts: 7665 Joined: Sat Aug 06, 2005 12:00 am Location: UK

Re: DIY Airpiano

Post by Folderol »

BJG145 wrote:
James Perrett wrote:Rather than upgrading the processor to gain more inputs, it may be worth just adding an analogue input shield

Thanks James, interesting...I'd been wondering about going for one of these, which is cheaper (16 analogue inputs on the Mega compared to 6 on the Uno, which should be plenty); not sure how these "compatible" boards compare to originals, or how likely it is to work with the same Sparkfun MIDI shield and code, but can't go too far wrong for a tenner...(?)

Most Arduino clones are quite reliable (they use the same chips and board layout).
The Mega should behave identically with the Sparkfun board.
However... the mega also has 3 additional serial ports, all of which are trivially easy to set up as MIDI out ports (and not quite so easily as MIDI in ones).
The only thing you have to watch out for is that you don't try to send MIDI messages too fast, or they are liable to overfill the buffer and get corrupted. Simply put a 1mS delay after each complete command.
User avatar
Folderol
Jedi Poster
Posts: 19728 Joined: Sat Nov 15, 2008 12:00 am Location: The Mudway Towns, UK
Yes. I am that Linux nut {apparently now an 'elderly'}
Onwards and... err... sideways!

Re: DIY Airpiano

Post by BJG145 »

Cheers Folderol, think I'll give that one a try then.

Second attempt...

https://youtu.be/fDRFHEF2UK4

...not much different here, just added a third zone and tried to make it more musical. The readings become increasingly jittery with distance, so I'll definitely have to work on the debounce. Anyways I'll wait for the rest of my flock of sensors to turn up now...
User avatar
BJG145
Longtime Poster
Posts: 7665 Joined: Sat Aug 06, 2005 12:00 am Location: UK

Re: DIY Airpiano

Post by Arpangel »

My god, this could be what I’m looking for in my Spice Up A Laptop Performance thread.
User avatar
Arpangel
Jedi Poster
Posts: 19426 Joined: Sat Jul 12, 2003 12:00 am

Re: DIY Airpiano

Post by BJG145 »

OK well I wasn't really accepting pre-orders but if you like you can put down a £500 deposit. It's a lot cheaper than this one. ;)
User avatar
BJG145
Longtime Poster
Posts: 7665 Joined: Sat Aug 06, 2005 12:00 am Location: UK

Re: DIY Airpiano

Post by Arpangel »

BJG145 wrote:OK well I wasn't really accepting pre-orders but if you like you can put down a £500 deposit. It's a lot cheaper than this one. ;)

So what’s the spec?

:think:
User avatar
Arpangel
Jedi Poster
Posts: 19426 Joined: Sat Jul 12, 2003 12:00 am

Re: DIY Airpiano

Post by ManFromGlass »

Will they be available in blue?
8-)
User avatar
ManFromGlass
Longtime Poster
Posts: 7381 Joined: Sun Jul 24, 2011 12:00 am Location: O Canada

Re: DIY Airpiano

Post by Arpangel »

ManFromGlass wrote:Will they be available in blue?
8-)

Something eye catching I hope, with lots of lights, and bits that glow according to how you play.
User avatar
Arpangel
Jedi Poster
Posts: 19426 Joined: Sat Jul 12, 2003 12:00 am

Re: DIY Airpiano

Post by Folderol »

Arpangel wrote:
ManFromGlass wrote:Will they be available in blue?
8-)

Something eye catching I hope, with lots of lights, and bits that glow according to how you play.

This is obviously where I went wrong with the YP. It just gets on with the job without any fuss :tongue:
User avatar
Folderol
Jedi Poster
Posts: 19728 Joined: Sat Nov 15, 2008 12:00 am Location: The Mudway Towns, UK
Yes. I am that Linux nut {apparently now an 'elderly'}
Onwards and... err... sideways!

Re: DIY Airpiano

Post by Arpangel »

Folderol wrote:
Arpangel wrote:
ManFromGlass wrote:Will they be available in blue?
8-)

Something eye catching I hope, with lots of lights, and bits that glow according to how you play.

This is obviously where I went wrong with the YP. It just gets on with the job without any fuss :tongue:

YP is obviously a great synthesiser, but it’s not for me, you know me Folderol, I’m old, lazy, my eyes are going, and so is my dexterity, I need big, lots of knobs that do obvious things, colours too, and lights, small screens and computers are a thing of the past for me
User avatar
Arpangel
Jedi Poster
Posts: 19426 Joined: Sat Jul 12, 2003 12:00 am

Re: DIY Airpiano

Post by BJG145 »

I'm going to post up some more pics of the original creation because I'm expecting the Mega and sensors to arrive any day now, and that's pretty much all there is to it, but my woodwork skills are nowhere. I'd be more confident knocking up a 3D model and emailing it to Shapeways to print in ABS or something, but...anyway...

Image

Image

Image

Image

What's the best plan...? It looks like a hollowed-out wooden box with a sheet of "acrylic glass", someone called it...is that even a thing...? Do they mean plexiglass...? Anyway, any thoughts on how to approach this welcome.
User avatar
BJG145
Longtime Poster
Posts: 7665 Joined: Sat Aug 06, 2005 12:00 am Location: UK

Re: DIY Airpiano

Post by Sam Spoons »

Perspex is a trade name for acrylic plastic sheet. Building a simple box from a piece of 9mm plywood, an identically sized piece of Perspex and some timber 'strip wood' should be not beyond someone with basic woodworking ability? Prove the concept then either make some nice looking side cheeks or get a nicely made box built?
User avatar
Sam Spoons
Forum Aficionado
Posts: 21546 Joined: Thu Jan 23, 2003 12:00 am Location: Manchester UK
People often mistake me for a grown-up because of my age.

Re: DIY Airpiano

Post by BJG145 »

Sam Spoons wrote:Building a simple box from a piece of 9mm plywood, an identically sized piece of Perspex and some timber 'strip wood' should be not beyond someone with basic woodworking ability?

Umm...OK. I'll have a go.... :thumbup:
User avatar
BJG145
Longtime Poster
Posts: 7665 Joined: Sat Aug 06, 2005 12:00 am Location: UK

Re: DIY Airpiano

Post by Folderol »

Stripwood for the edges is definitely the way to go. It is much easier to manage, and you actually fit it after everything else, so you can make it a nice snug fit.
You might also need some packing pieces underneath the plexiglass/polycarb - whatever you use, to allow for the thickness of the sensors if they have heads that need to be proud.

Paint on the underside of this in reverse order and you'll get a nice glossy finish that'll never rub off :)
User avatar
Folderol
Jedi Poster
Posts: 19728 Joined: Sat Nov 15, 2008 12:00 am Location: The Mudway Towns, UK
Yes. I am that Linux nut {apparently now an 'elderly'}
Onwards and... err... sideways!

Re: DIY Airpiano

Post by Sam Spoons »

I'm pretty sure there'll be a DIY shop near you that will cut sheet materials and timber to size, I was going to suggest B&Q if you were in the UK but you'd be looking at around £50 for materials and I'm sure there are much cheaper options.

Otherwise go and see a decent joiners workshop with those pics and I reckon they could make you something for not a silly amount.
User avatar
Sam Spoons
Forum Aficionado
Posts: 21546 Joined: Thu Jan 23, 2003 12:00 am Location: Manchester UK
People often mistake me for a grown-up because of my age.
Post Reply