Yes, if you are struggling with some programming problem and then decide to go to bed you are not likely to fall asleep quickly. I suggest you do something relaxing - take a bath, go for a 15 min walk, read a book.
There are many more
tips on how to wake up early and why, hope you'll find those that will help you become an early riser.