Dear Mayo Clinic: What is the best way to eliminate insomnia? For almost a year, I've had trouble getting much sleep. I've tried over-the-counter medications, but they aren't very effective.

A: Although sleep medications may be useful when you have occasional trouble sleeping, they aren't meant for long-term use. A better approach is to change your behaviors to cultivate quality sleep. An evaluation with your health care provider to check for underlying issues that could be negatively affecting your sleep also could be valuable.

Insomnia is defined as having problems getting to sleep or staying asleep three nights a week or more for at least three months. When dealing with insomnia, it’s important to rule out medical issues that could be driving it. For example, restless leg syndrome and sleep apnea are two common problems that can lead to insomnia. Some medications also can cause sleep problems.

If an evaluation doesn’t reveal an underlying cause of insomnia, you may benefit from behavioral changes. These changes get your brain to associate your bed and nighttime with sleep.

First, establish a bedtime routine. For example, about 30 to 60 minutes before you go to bed, turn lights low. Turn off the TV and other electronic devices. Brush your teeth and wash your face. Change into pajamas and get into bed. A consistent routine each night gives your brain clear signals that sleep is coming.

Second, reduce the amount of wakeful time you spend in bed. If you get into bed and don't fall asleep within 15 to 20 minutes, get up and go to another room. Keep your surroundings quiet and dimly lit. Don't turn on the TV or other electronic devices. That will wake up your brain, rather than getting it ready for sleep. Instead, do some light reading, listen to quiet music or engage in relaxation techniques. Perform these activities sitting up, rather than lying down.

When your eyes get heavy and your head starts to bob, get back into bed. Don’t go back to bed when you’re just feeling tired. Wait until you’re sleepy. If you can’t sleep once you get into bed, or if you wake up again and cannot fall back to sleep within 15 to 20 minutes, repeat the cycle.

By minimizing the amount of time you spend in bed awake, you’re teaching your brain to associate your bed with sleep. Sometimes, people think it’s a good idea to be in bed at night — even if they are not sleeping — because they are getting some rest. But that conditions your brain to associate being in bed at night with being awake — the opposite of what you want.

Don’t read, watch TV or spend much time in your bedroom during the day. When your alarm goes off, get up, start your morning routine and get out of the bedroom as soon as possible. Dozing in bed between snooze alarms won’t provide quality sleep, and it reinforces poor sleep patterns.

Also, pay attention to other health habits. Sometimes when you are not sleeping well and feel tired the next day, you’ll increase your caffeine intake. While this may help you during the day, it can complicate sleep at night. Work to reduce or eliminate caffeine in your diet. If you continue to use caffeine, consider gradually reducing the amount over time or try switching to half-caffeinated beverages. It is also a good rule of thumb not to consume caffeinated drinks after 3 p.m. or six to eight hours before bedtime.

Finally, don't rely on sleep medication to cure insomnia. Prescription and nonprescription sleep medications are only intended for occasional, short-term use — typically no longer than four to five weeks at the most. Over longer periods of time, these medications can contribute to sleep problems and lower the quality of your sleep.

If you continue to have insomnia after trying behavior modification for several weeks, talk to your health care provider or consider consulting with a health care provider who specializes in sleep disorders.