MIDI input to PWM output

Hi. I'm finally giving in the towel and looking to hire someone who can write a sketch that takes a basic MIDI input from the rx pin in an arduino uno and put outs the correlating frequency out of one of the pwm pins. (it is eventually going to a motor) all the hardware is done and working well. I've been running a basic midi in sketch that turns the motor on when any key is down and stops when the key is up, so progress has been made. I just don't know how to get tones out of this thing (outside of the basic tone() sketch which worked fine. I can send wiring diagram, photos, whatever you'd need. If you're in the NYC area I'm also happy to meet up and work it out. thanks so much for reading and i'm looking forward to hearing from you!

this sounds a little confusing...

MIDI to PWM ..

OK PWM is Pulse WIDTH modulation not Frequency modulation. The frequency of the square wave remains the same it is only the mark/space ratio that changes. where does "tone/frequency" come into this.

When you say drive a motor , what kind ? if it is a standard RC Servo that takes PWM 1-2 ms with a 20ms duty cycle then you are adjusting the mark/space ratio and not the frequency. If you are intending that it should approximate an analogue output to drive a motor a different speeds (also PWM not Frequency) then you really should be looking at an external motor driver or ESC like those found on RC gear.

Cheers Pete.

Hi Bainesbrunch
Thanks so much for your reply.
The motor is a standard 3v dc motor.
It is preceded by this in the circuit:

you can read a bit about it here:
Otherwise, its a pretty standard MIDI in circuit with an optoisolator going into rx pin on the arduino (with an added switch to be able to load new sketches), pin 13 out going into the ‘hack off’ and then out via 1/4" audio connector to the motor. I’ve been running this sketch as a basic test:

#include <MIDI.h> // Add Midi Library

#define LED 13 // Arduino Board LED is on Pin 13

// Below is my function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
digitalWrite(LED,HIGH); //Turn LED on
if (velocity == 0) {//A NOTE ON message with a velocity = Zero is actualy a NOTE OFF
digitalWrite(LED,LOW);//Turn LED off

void setup() {
pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
MIDI.begin(MIDI_CHANNEL_OMNI); // Initialize the Midi Library.
// OMNI sets it to listen to all channels… MIDI.begin(2) would set it
// to respond to channel 2 notes only.
MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
// tells the Midi Library which function I want called when a Note ON command
// is received. in this case it’s “MyHandleNoteOn”.

void loop() { // Main loop
MIDI.read(); // Continually check what Midi Commands have been received.

Ah and to answer your first question, I am probably really confused about how this works but I'm looking for what would essentially be the tone() function controlled by the midi messages from my midi controller (standard m-audio oxygen 8 v2)
When I uploaded the tone() sketch it worked fine with the motor so now if I could only combine the MIDI input sketch and assign a tone to each MIDI key (standard, nothing fancy) then I'd be so happy I'd do a dance.

OK ... there is some confusion on your part going on here.

A motor cannot be used to play tones, at least not the way you are planning to using a variable frequency drive. You could get it to spin at different speeds and that would create a series of tones.

Why a motor for the OP device (unless you really are hacking a vibrator in which case i understand and require no further information)

Also what is you end goal on this. I am not sure i understand what the application is (again unless it really is a vibrator)

Cheers Pete.

Thanks for your help. I just got it up and running. You can see what I mean from the video. It basically works by getting picked up from the bass pickup:


Ha Ha .. excellent, but I still dont know what it is for ???

Nice Base BTW .. I Play (Base) too mainly rock blues with a bit of swing jazz for fun..

Cheers Pete.

Hey Pete.
thanks! its for performance/sound art.

cool my Sons are both musicians too.
One produces music in London, the other is studying for a degree in music in South Wales