I'm trying to run the MIDI example from Arduino.CC in Arduino Studio.

I am using an Arduino Leonardo, which has USB HID capabilities. I have installed the library as mentioned:

MIDI Library installed

When I press the compile or upload button, it says:

'D3' was not declared in this scope

What's wrong? How do I fix this?

  • the error happens when the source code is being compiled .... the upload is not attempted ... upload only happens when the code compiles without errors
    – jsotola
    Commented Apr 26, 2020 at 18:07

1 Answer 1


The pitches for the notes are taken from pitchToNote.h. In there you can see definitions for the notes like:

#define pitchC3  48

It seems that the names were changed from C3 to pitchC3.

I am not 100% sure, but my guess is that this was done to avoid conflicts between the note A3 and the analog input A3 (and silimar).

So, in line 25 of the example code, add pitch for all notes:

const byte notePitches[NUM_BUTTONS] = {pitchC3, pitchD3, pitchE3, pitchF3, pitchG3, pitchA3, pitchB3};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.