<p>I actually did this, on my Malyan M150. </p>

<p>After not that much experimentation at all it turned out that the frequency of the produced tone scales linearly with the speed of the motors. Due to the nature of the way humans perceive music, the actual frequencies do not matter at all, just the relative difference in frequency between the tones. This means that it is actually really easy to let a 3D printer play a tune, you just have to make sure that when the next tone needs to have a frequency that is for example 20% higher than the last one, the motor needs to move 20% faster, no need to actually measure at which speeds the printer produces which tones. </p>

<p>One of the main issues turned out to be the maximum speed of the motors, which wasn't high enough for some of the higher notes, but this issue could be solved by multiplying all the speeds by a number lower than 1, thereby lowering the required speeds while still maintaining the original melody. Playing two tones at the same time proved to be a bit too difficult for my not that great programming skills, while not being worth the effort because somehow there was quite a large difference in volume between the motors. </p>

<p>In the end, I made a MATLAB script that converts MIDI files to G-code with the following result: <a href="https://www.youtube.com/watch?v=jPV-TolORK4" rel="nofollow noreferrer">3D-printer playing popcorn song</a></p>

CC BY-SA 4.0
2020-10-05T12:19:52.153Z
You could have had 3 instruments at the same time or 3 different volume levels by using the 3 motors
FarO
CC BY-SA 4.0
2018-04-30T13:16:33.957Z
2019-05-08T13:18:08.763Z
2019-05-08T13:18:08.763Z
Ezra
<p>Yes, it has been done before, see <a href="https://github.com/forflo/gCodeMusic" rel="noreferrer">here</a> and <a href="https://github.com/yeokm1/midi-to-simple-metal-gcode" rel="noreferrer">here.</a></p>

<p>The README file of the first repository linked above contains a detailed explanation of the basic idea/calculations involved.  A short excerpt:</p>

<blockquote>
  <p>As you can set the parameters of G1 in such a way as to precisely control the velocity and the distance of a movement along a certain axis, you can control the operation frequency of the stepper motors as well as the actual time to complete a movement.</p>
</blockquote>

<p>On another note (pun intended), you can also play music by using the code <a href="http://reprap.org/wiki/G-code#M300:_Play_beep_sound" rel="noreferrer"><code>M300</code></a>.</p>

CC BY-SA 3.0
2018-03-21T16:34:21.787Z
2018-03-21T16:34:21.787Z
mac
<p>Harking back to the days of "singing disk drives," I am wondering if anyone's written music to be performed on a 3D printer. Most of us have noticed in passing that the servo motors for X and Y drive generate a different pitch depending on motion speed. With some care and experimentation, one could write g-code to produce not only a tone but even a 2-tone chord.  So -- has this been done? Does anyone want to do so? (Note that there's no need to simultaneously produce a print, but that would be even classier).</p>

CC BY-SA 4.0
2019-05-13T06:43:07.803Z
Followup: an actual object that is musical while it's printing?
Jeroen3
<g-code>
Music from the printer?
Carl Witthoft
# Music from the printer?

(Asked by: username_0 on 2018-03-21)

Harking back to the days of "singing disk drives," I am wondering if anyone's written music to be performed on a 3D printer. Most of us have noticed in passing that the servo motors for X and Y drive generate a different pitch depending on motion speed. With some care and experimentation, one could write g-code to produce not only a tone but even a 2-tone chord. So -- has this been done? Does anyone want to do so? (Note that there's no need to simultaneously produce a print, but that would be even classier).

**Tags:** g-code
> **Comments:**
> **username_1**: Followup: an actual object that is musical while it's printing?  

---

## 2 answers

### Answer by username_4 on 2018-03-21. Score: 11 | Accepted answer

Yes, it has been done before, see [here](https://github.com/forflo/gCodeMusic) and [here.](https://github.com/yeokm1/midi-to-simple-metal-gcode)

The README file of the first repository linked above contains a detailed explanation of the basic idea/calculations involved. A short excerpt:

> As you can set the parameters of G1 in such a way as to precisely control the velocity and the distance of a movement along a certain axis, you can control the operation frequency of the stepper motors as well as the actual time to complete a movement.

On another note (pun intended), you can also play music by using the code [`M300`](http://reprap.org/wiki/G-code#M300:_Play_beep_sound).


---

### Answer by username_2 on 2018-04-30. Score: 7

I actually did this, on my Malyan M150.

After not that much experimentation at all it turned out that the frequency of the produced tone scales linearly with the speed of the motors. Due to the nature of the way humans perceive music, the actual frequencies do not matter at all, just the relative difference in frequency between the tones. This means that it is actually really easy to let a 3D printer play a tune, you just have to make sure that when the next tone needs to have a frequency that is for example 20% higher than the last one, the motor needs to move 20% faster, no need to actually measure at which speeds the printer produces which tones.

One of the main issues turned out to be the maximum speed of the motors, which wasn't high enough for some of the higher notes, but this issue could be solved by multiplying all the speeds by a number lower than 1, thereby lowering the required speeds while still maintaining the original melody. Playing two tones at the same time proved to be a bit too difficult for my not that great programming skills, while not being worth the effort because somehow there was quite a large difference in volume between the motors.

In the end, I made a MATLAB script that converts MIDI files to G-code with the following result: [3D-printer playing popcorn song](https://www.youtube.com/watch?v=jPV-TolORK4)

> **Comments:**
> **username_3**: You could have had 3 instruments at the same time or 3 different volume levels by using the 3 motors  

---

