Here's a method I use that works. First, sit down at your piano or keyboard and just improvise.
I suggest improvising first because music that is created in this way is at its freshest. It's not adulterated or thought up. It is pure inspiration.
Now, there will come times during improvisation where you may say to yourself, "this is nice and I'd like to develop it." You see, now you have an original melody to develop.
The trick is you don't need a lot of material to begin with. JUST TWO BARS IS ENOUGH to start you on your way. I usually work within 8-bar phrases so I know that the melody will usually end or repeat itself after 8-bars. I say usually because sometimes, the melody does not want to fit nice and neat into a predefined 8-bar phrase. But more times than not, the 8-bar phrase will serve you well
Now, to be able to grow the initial 2-bars of inspired melody into 8, you can either harmonize the melody with a few chords or just write out the rest of the melody as it comes. Once I have the first 2-bars, I usually have already identified what Key the piece will be in.
It then becomes a matter of choosing a few chords from the Key and the rest of the material is easily flushed out into 8-bars. In the piece "Rainforest," I use 2 chords for an entire 8-bar phrase ( 4-bars for G Maj. and 4 for E-minor) and improvise the melody on top