Start to wind down physically and mentally at least an hour and a half before going to bed.
I just read a factoid on writers' problems (https://knoji.com/9-common-problems-and-conditions-that-could-affect-writers-and-their-writing-careers/) and noticed that a couple of people commented that the author left one out: getting a good night's sleep with ideas swirling around in their heads. Sleep problems are certainly not limited to writers. Everyone of us has ideas, hopes, worries, resentments, anticipations, irrelevancies--good things, bad things, and neutral things--going on in our minds constantly.
If that's still going on when we get into bed at night, it's not hard to get to sleep; it's impossible. I consider myself an expert on the topic. I have had trouble sleeping as long as I can remember. Time was when it was not unusual for me to lie awake, or read, or sit in the dark waiting to get drowsy again, or in short, anything but sleep for as much as five hours after I went to bed. But now I'm sleeping better than ever before.
While part of my improved sleep can be attributed to finally getting a prescription to something that works for me, I don't need it all the time. More importantly, I have found ways of quieting my mind. Most of them work not only at night, but also when I need some peace and quiet in my inner being at any time.
For a writer, the best way to clear one's mind for sleep is to turn off the computer at least an hour and a half before going to bed. I would like to get to bed around 10:00 at night, although I seldom make it that soon, so I stop writing, researching, thinking of topics, etc. by 8:30. If I read something, I make sure it is unrelated to anything I might be interested in writing about. I do not watch television. Among other things, it is likely to give me not only more things to fire up the conversations in my mind, but also provide moving images to go along with it.
So I listen to my favorite music, or I play Sudoku, or I play with my dogs. Weather permitting, I love to go outside in my back yard and feel the breeze, watch the stars, listen to nature sounds (I especially love the sound of crickets and other insects, as long as they stay outside!), smell whatever is blooming in the garden, etc. Because I am a classical music lover, all of these activities are either wordless or (in the case of the beautiful sacred music of the Renaissance) in something other than English. Concentrating attention on these things crowds inner conversations and mental notes about research and writing out of my mind.
I have learned that I have control over what I choose to think about. If I'm writing, I need to think about what I'm writing. If I am having a conversation, or even an argument, with someone, I need to think about it. If I am in some kind of trouble and want to know what to, I need to think about it. But if I'm trying to get to sleep, not only do I not need to think about any of those things, I mustn't . So I need to choose something else to think about, not just run with the daytime stuff that comes up in my mind.
As a Christian, I find that verses of Scripture or meditation on the greatness of God's love and mercy are just the thing. I have more thoughts about that on my blog (http://allpurposeguru.blogspot.com/2009/09/trusting-god.html). People of other faith traditions undoubtedly have equivalent things to think about. In any case, even if you are going to bed after a truly rotten day where lots of stuff went wrong or you were hit with a major crisis, something good happened. It's good to think back to identify the good things and spend some energy on being glad for them.The idea is to choose something short, uncomplicated, peaceful, and positive, and train your mind to pay attention to it.
A third lesson I have learned, mindfulness of breathing (https://knoji.com/deep-breathing-technique-how-to-breathe-deeply-for-better-health-and-stress-reduction/">), is especially powerful when combined with meditation. Breathe slowly and deeply, concentrating on all the physical sensations. That in itself may help quiet the mind so you can fall asleep. Or think a short phrase in the rhythm of your breathing: inhale /Lord, Jesus Christ, exhale / have mercy on me; or inhale / God is good, exhale / all the time.
Those things work for me, and I'm confident anyone can adapt them and improve their sleep. They work better with some other standard advice: Avoid caffeine after mid-afternoon. Pseudoephedrine also interferes with sleep, so choose a decongestant nasal spray for stuffiness or sinus headaches instead. Do not do strenuous exercise or work within two hours of bed time. Do not use your bed for anything but sleeping and sex. Keep your bedroom dark, to the point of making sure you can't directly see your lighted clock face. Do not lay awake in bed for more than half an hour; get up and sit in a chair or something. If that's necessary, or if you wake up in the middle of the night, do not turn on a light.