Before anyone can truely come up with an original melody, you must first have a rudimentary understanding of basic music theory...
You must be able to resite at least 4 basic scales in what ever key you find most comfortable the scales are major, minor, harmonic minor, pentatonic. Once you learn each scale, then comes phrasing and timing exercises of those scales. For example instead of playing the scale in simple quarter notes, playit in 8th notes... Mix the quarter notes and 8th notes together and you have a amatuer melody, but nevertheless a melody.
If you find yourself stuck with that same similar melody over and over again, for me, it's my chord progression that is the problem... Change up the chord progression and it usually will inspire a new melody.
Never force you self to write music (unless there is a deadline of some sort). I have physically and mentally collapsed due to working on a peice too hard, if you can't come up with something, go relax and eat and apple or something... Then later on, come back to the old' piano (or whatever instrument you are playing).
Honeing your improvisational skills will greatly help your writing abilities. Take the easiest scale (pentatonic), go to you tube and slap on a simple blues rock backing track and jam for a half hour. It's super fun!!!
I could go on for a long time about all the different tips and trick to making a master peice, but feel free to PM me with any questions. I would be more then happy to help :)
This post is not ment to be a lesson but just some basic insight.