Here are some pictures:
Here's a description of how it works:
Music Machine 2 consists of two elements.
The first is a repeated C major triad which provides the pulse for the machine. This pulse is played as quavers at 120 bpm.
The second element is the melody (also played as quavers) that is generated using the following rules:
1. The melody can only use notes from the C major scale.
2. Whilst it is possible to generate notes from any octave, the extreme high and low octaves can only play notes from the triad
(C, E or G). Any note from the scale can be played in the middle octaves.
3. The process is weighted in favour of making a middle octave selection.
4. There is a 50/50 chance that the note will be sustained rather than stopped when the next note sounds.
The machine will run indefinitely until stopped by the user.
This version uses an ultrasonic distance sensor and an Arduino.
And here's some video of it in action: