I'd love to say there's a hard and fast way to stay motivated but if I did I'd be completely lying! Truth is there are a few things you can do and hope that some or all of them work.
1. The first thing is to be realistic with yourself. If what you want to stay motivated to do is lose weight for example, you're not suddenly one day going to be able to run 5k, you have to gradually build it up, set yourself small, achievable goals. For me the thing I needed to stay motivated to do was write blog posts, I knew I wasn't going to be able to post every day so I set myself a realistic goal which was to post twice a week, which for the past month I have been able to do!
2. Along the same lines is don't do things for so long that you get bored. I knew I wasn't going to be able to write blog posts for 5 hours in a row so I spend maximum about 1 hour at a time over a few days to write a post. Again if you're trying to get fit or lose weight set aside say an hour however many days a week, commit to working out for that whole hour but don't do longer than that and change it up from day to day so you don't get bored.
3. Be patient! This is my worst thing, I start something and then want to get it done straight away. It doesn't work! If you rush something you'll sacrifice quality for speed. Writing a long blog post (my beauty haul for example) takes me ages, you have to take the pictures, crop, edit and upload them, write the post (which takes me forever as it is), insert the pictures and check it for spelling mistakes of which there are plenty! But when I get the finished post it's so much better than it would have been if I'd taken quick, crappy pictures and not checked for spelling mistakes or checking I've said all I've wanted to. What I'm trying to say is taking the time will be worth it!! Nothing is going to happen overnight!
4. Finally is be disciplined with yourself. This is the hardest to do as it requires motivation to do, however if you're not disciplined with yourself when you're for example working out if you miss a day then the next day you'll be even less motivated to do it and it will end up that you do nothing. So even if you're tired or really busy etc. you don't need to do all you planned to but do something to keep on top of whatever it is you're trying to do.
Thanks for reading :)
Hope this helps!