This can be equated with repetition and flow. Does it have shape, develop thematically, and is it dynamic? The bottom line is does it create an emotional response? Does it tell a story and invite listeners on a journey? And most importantly, can you hum or whistle your melody when away from the piano?
Nothing replaces the ‘inspired’ melody, but that is between you, your soul, and your imagination. While you are waiting for inspiration to strike, sometimes a simple chord progression will give you a clue to help start your melody, other times, it may just be more intuitive. Improvising over a chord progression, or just humming or playing along until an interesting phrase catches your ear can also be a good way to start. Be aware that melodies don’t always start at the piano. They may pop into your head at anytime or, anywhere! Although we want some repetition, it’s a fine line between catchy, and annoying so we need to give it SOME variety as well. Changing dynamics within the melody, loud and soft accents, using harmonic and key changes, speeding up, slowing down, pauses, playing some sections in a different rhythm while keeping the same notes etc. and adding harmony to some of the notes to create texture are things to keep in mind.
Rhythm is a very key element of your melody!
Try tapping out the melody as if it is being played on a drum. Does is flow and have a groove, or does it seem a little jumpy? If the song is an instrumental, and your melody seems a little awkward, you might try making up words just to see how it sings. If you are writing lyrics, try removing any words that are not absolutely essential. You might need to even out your melody. Often times just changing the rhythm by removing (or adding notes) can smooth it out, but less is usually more.
I have spent years listening to the melodies of many great songwriters, analyzing those, and then writing my own. Keep listening to uncover the patterns and shapes great melodies have in common and in the process discover what you like and don’t like about certain melodies and of course keep writing your own!
A little analysis.
In the song 'Cristofori's Dream' the melody is based on the scale tones of the key it is written, D-minor. The verse uses the harmonic minor scale (D-E-F-G-A-Bb-C#), notice the melody follows these scale tones with a certain amount of repetition. For a melody to really work, it has to have some degree of repetition. Here the first 3 notes are repeated 3 times and then it continues up the scale adding a little variety and theme development. Once the melody is stated, it repeats itself. Then the melody gets repeated again in the key of A-minor, and then the D-minor and the A-minor melodies are repeated AGAIN in a lower octave...repetition! The melody of the chorus brings in chord tones (i.e. D-F#-A) which blend and flow nicely with the scale tones. Writing large interval jumps in the melody usually is not a good idea. The melody should be singable, and too many large jumps will make it awkward generally speaking. That being said, in the song ‘Return to the Heart’, the melody begins with an octave jump from E up an octave to E ( Key of A Major). This resolves to the 3rd of the key (C#) and is repeated 3 times. The sound is pleasant and still melodic, so there are exceptions to every rule.