I was up working on SEO until 5 am last night, and now it's 4:30 and I'm coding away. Does anyone have any good tips to help with insomnia?

I tend to work late into the evenings, and I get such an adrenaline rush from coding (I'm a nerd, I know) that I have a hard time winding down. Then, when I finally do, my mind tends to wander while I'm trying to fall asleep, and I keep thinking of things I can implement and, well, there's no time like the present! I try to put them off until morning but that just makes me more anxious and then I end up getting out of bed a half hour later instead of right away.

Help?

Yeah. I have those nights when my mind just won't turn off. The trick (for me) is to concentrate on something totally unrelated. I listen to a piece of music in my head, concentrating on every note. By doing that I force my mind out of the rut it is in. Works most times. For me the piece is (believe it or not) Classical Gas by Mason Williams. You would think I would pick a slow piece but I also visualize the finger picking so two senses are being focused.

Keep in mind also that a lack of vitamin B favors insomnia. As thyroid issues like hyperthyroidism.

This is something that doesn't have one solution for all answer. https://en.wikipedia.org/wiki/Insomnia and the Prevention paragraph works for me.

I used to be an all hours on call person and it took its toll. About a decade ago I recognized the signs and found that setting limits along with getting to an established schedule did wonders.

It's rough to do for some folk but for me, that was all it took.

Thanks for the replies everyone! I ended up not getting to sleep until nearly 6 am and woke up at like 2:30 pm. The day today really got away from me and I've pretty been in a daze all day. :-/ I'm afraid of repeating the cycle now. I need to figure out how to tire myself out.

Do you have other hobbies besides coding?
Practise one of those before going to sleep.
As you said, you being a nerd the chances you have any other hobbies are perhaps low.
Try to get one. The obvious one is reading.
Don't start reading an IT related book though!
Read something entitled like "The secret life of the butterfly", perhaps you fall asleep reading it. :)
Hope this helps.

I used to be the same, then I decided something had to change as my body is lot older than yours and was suffering as a result. So I don't do any work after 6pm, and don't touch the smartphone after 10pm. I am always in bed for 10.30pm regular as clockwork now, and always asleep by 11pm. Yes, my old man bladder wakes me in the night at around 4.30am but I get straight back to sleep and feel refreshed enough to get straight out of bed without snoozing my 6am alarm.

It took a good couple of months to reset my body clock from getting up at 10am and working until 3am (or later) but eventually it got there. Best thing I ever did, truth be told. I used to kid myself that I worked better of a night, but that's all it was: an illusion. Switching off mentally requires switching off tech...

If you are on the computer in the evening you might want to installing f.lux. I've been using it for months. It automatically adjusts the level of blue light coming from your screen after sunset. I know that Windows 10 bow has its own version of this but I suspect (like most MS extras) that f.lux is much simpler to use. It's free, BTW.

My Samsung S8+ has a blue light feature for night usage, but to be honest I think it's more the act of working/browsing/checking that keeps me too stimulated to sleep than the light issue.

Member Avatar for diafol

Keep fit. Being energised after a workout is a different energised from coding. I sleep like the dead after a good gym session or long run. Not even my old man bladder wakes me up :)

commented: Seriously. Cycling is my new passion. Can't sleep? Ride 10 miles! +0

I used to exercise immediately before bed, but not anymore. At my home in NY, I have an exercise bike in my bedroom. I'll exercise for an hour and then crash. Here in California, I'm in a complex with a small gym, but it's not as convenient, nor do I feel comfortable going there in my PJs late at night, and exercise being less convenient means I don't really do it.

The only thing that sometimes works for me is to watch an action tv show before bed, like the Walking Dead or something like that. Pretty much any type of show that requires my full attention. While my brain is busy thinking about zombies and what character is going to die next, it's not thinking about ad sales and SEO and website traffic and Dazah and APIs and all the things that keep me up at night. I usually have an easier time falling asleep after spending the full hour "winding down" thinking about fictional characters that have my full attention as opposed to anything important.

Ok, lucky for you I happen to know a certain me who suffered from insomnia, as well as a certain girlfriend who still does. Unfourtunately there is no one magical cure, as little is known about the condition, and even less is known about the causes. But there are some things you can do that might help. Keep in mind, you should try and pace with the latest nuroscience research as some of these tips may be outdated in a few years as we learn more.

To start none of this is going to probably happen over night. Your case may range from very mild, where it will only take a few days to a few weeks to correct-to extremely severe where months and more often years are taken to correct. If you're concerned about something, always talk to a professional, I'm not a medical doc.

1) Two hours before bed, all screens go off. ALL of them. Phone, TV, computer...everything. You need to train your brain that now is the time for bed, and depriving it of stimulus is exactly one way to do that. Also screens have ways of constantly distracting you from your own bordom, I.E. the internet. Many people don't realize how important it is to be bored. We evolved that way, staring at the stars and letting our imagination wander.

2) Keep a notpad and paper next to your bed. You wanting to suddenly write code and having a rush of ideas, is the bordom coming in I just mentioned. Being able to jot your ideas down to the most intracate detail you desire will help with the anxiety, and keep you away from your enemy, the screen. You may even just nod off writing.

3) alcohol is a bit of a tricky one. It's long been known to settle nerves, and that might help. But all that sugar is doing really nothing to help you nod off. My advice is stay away. The same goes for exercise. Exercise may make you feel tired, but it actually shoots off adrenaline endorphans. So it's awesome in the morning, but not so awesome when trying to deprive your brain of all stimulus. Do exercise when you get up, though. That will really help.

4) Set a time for bed and a time to wake, and stick to it. Even if you only get a few hours of sleep, it doesn't matter. Your brain must learn X time is sleep, and Y time is get up. The best time is between 10PM and 9AM. When the bodys natural melatonine levels start to kick in. Speaking of which pick up some melatonin if you want. Stuff is legitimate, and completely safe.

5) I keep saying your brain, as if you are not your brain. But it turns it's not just you, but many you's back there. Speaking of which, do not spend all day in the same room, and even try to work away from that room. The brain craves diversity, and staying in one place all day is the exact opposite. Studying in a coffee house may seem dumb, but the change in environment is not only stimulating but also satiating.

6) If you're on any adderall or speed, talk to your doctor about getting off. Nothing spells party all night like that drug.

If these problems persist after a few weeks, you need to see a specialist. Hope this helps.

Well I am going to run against the tide.
I would like to know if this is a regular occurance or just when you get caught up in a project. If the former then i agree with most of the input, but if the latter I would say don't make a mountain out of a molehill, it sounds to be as if your enthusiasm for a project may consume you from time to time, and in my opinion that is excellent for you and your clientelle, and when the project is done you can time out relax and be "normal" whatever that is.

Well I've been having a bit of a bout. A few years ago I wrote an app to help me solve Sudoku puzzles. It doesn't have any smarts (what would be the fun in that). It just eliminates all the filling in and erasing.

Anyway, It was done in 1980s type style and I wanted to rewrite it using my own OOP custom controls. It took some cussing and swearing and some brain stretching but I finally got it working (many happy sleepless hours of debugging). I have now learned something new. So now, instead of going to sleep I am documenting and prettifying and I will eventually turn it into a daniweb tutorial on building compoiund controls if you think it would be of use and/or interest.

I sometimes wind up with insomnia myself. I'm not one for taking supplements or anything, but for those times I really can't get to sleep, 5-10mg of melatonin can definitely help.

Also, you don't have to exercise right before bed, but getting in any exercise during the day can make a big impact. I try and ride my bike anywhere from 30 minutes to 2 hours a day, depending on what my workload looks like. I can definitely say that even on the days I ride for 30 minutes, I usually go to sleep way earlier than I otherwise would.

Some tips my doctors gave me when dealing with chronic (and I mean I at times didn't get more than half an hour of sleep out of every 24 for weeks on end) insomnia:

  • Stop using emissive screens at least an hour before going to bed (so TV, computer, tablet, cellphone, etc.)
  • Don't eat or drink during that period
  • Take a short walk outside. Relaxes the mind, refreshes the body
  • Some light reading helps
  • Get rid of the CFL energy saver light bulbs as their flicker overstimulates the brain even if you can't consciously see it.

I just got through three nights where I was wide awake from 1-4am. One of them was a beautiful, war[m], clear night with a full moon so I went down to the lake and sat on a rock for 1/2 hour. Much better than lying in bed, tossing and turning.

<embarrassing typo corrected>

12:30 am here. I spent 40 minutes on the treadmill at 11. Plopped myself down on the couch for a little bit, washed up, and now I'm here on my computer, not feeling like I'm capable of falling asleep anytime soon, although I would love to be fast asleep within the hour. What do I do?

P.S. My body requires 9.5 hours of sleep. It simply does. If I get less than 8, I physically feel like I haven't slept in days and am unable to function. On Tuesday night, I only got 7 hours of sleep. I woke up and simply was unable to fall back asleep. I was a zombie who was aching from head to toe until 7 pm, when I finally crashed. I slept straight through from 7 pm last night (Wednesday night) until 8 am this morning. (You know, because 13 hours of sleep is obviously required to recover after only getting a measly 7 the night before.) So I've been up since 8, it's currently 12:30, and I want to get to sleep ... Suggestions?

Have you tried listening to something like Delta Waves?

Wow Jim, if that music can put Dani to sleep, then I can only suggest a half bottle of some strong drink. But I guess Dani better tries out your sound waves first! Think I'll have a nap now...

I have tried your delta waves before! It worked for a month or so, a long time ago. Now I have a Brookstone sleep sounds machine and it only works half the time as well.

I don't really suffer from insomnia but on occasions when I can't get to sleep listening to an audiobook for a few minutes usually makes me drop off. I think it's because it takes my mind off whatever it was on and, depending on the book, can be quite relaxing.

12:30 am here. I spent 40 minutes on the treadmill at 11. Plopped myself down on the couch for a little bit, washed up, and now I'm here on my computer

And there's the problem. You go straight from strenuous physical (or mental, just as bad) activity to laying in bed trying hard to sleep.
The body and mind don't work like that, they need time to unwind.

Sit on the couch with some light reading, preferably with some soft music and muted light, for half an hour or so.
No food or drinks in that period, allow your body and mind to slow down.

THEN go to bed, maybe read a few pages more, and turn off the light.
Don't squeeze those eyes shut and think so hard about why the heck you're not falling asleep, as that's probably the very reason you're not falling asleep. Allow your mind to wander and slow down as well as your body, and you'll eventually drift off to sleep.

First period it will take a while, but after some time it'll go a lot quicker.

Turning your alarm clock around so you're not constantly reminded of the time can help as well. The darn thing will go off in the morning to tell you it's time to get out of bed, that's the only time you really need it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.