How to stay motivated when working on projects by yourself?
In my experience doing an independent research project, one of the most helpful things has been to remind myself why I thought my project was worth doing. If you can periodically re-excite your interest in the project, you may find yourself wanting to spend time on it. Those have been my most productive times.

Also, meet up with your advisor on a regular basis, even if it's only once every quarter or something (more is preferable). If it will help light a fire under you, set a meeting a few weeks in advance, decide on something you'll show them/discuss with them at the meeting, and use the meeting as a mini-deadline.

It's all about carrots and sticks. Remind yourself why you're doing it; remind yourself that it won't be so nice if you don't do it. Reward yourself for meeting milestones. Make yourself keep milestones.

Also, if you're experiencing any health issues (mental or otherwise) related to this, don't be afraid to seek help. There are often resources nearby, and you're better placed to do good research if you look after yourself.