I've been working out on and off for the last 8 years but found a groove recently by going to the gym and thinking about the following four things:
1. Music / Podcasts - I actually think I've Pavlov's Dogged myself into associating that blissful feeling of a new song with the endorphins of working out and now I can't get enough. Podcasts are also a highly productive pairing.
2. Mental health - If I'm feeling drained or a little down, it's almost always cured by 30 mins of cardio. Once I figured that out, I starting craving workouts and now have a hard time avoiding them even when on vacation.
3. Social - The gym is another social circle outside of the workplace that's great for meeting people. I've met fellow programmers, metal heads (as in music), and know many a romance that began there.
4. Physical Goal - I like the idea of sculpting my body or at the very least having good posture and minimizing the 'inner tube' on my belly. Seeing the changes manifest over time truly does motivate you to keep going.
Final piece of advice - don't beat yourself up in the beginning! If you only workout once or twice a week, that's a start. Just be consistent and try to let it snowball.