Ideally you'll be able to avoid all medications (including herbal remedies) during pregnancy. Most drugs haven't been tested on pregnant women, and it can be hard to know what effect they'll have on your baby.
If you have a severe sleep problem or disorder, though, your doctor or midwife may recommend a prescription or over-the-counter drug to use during your second or third trimester. It's important never to take any medication during pregnancy without first consulting your healthcare provider.
Over-the-counter remedies
Ask your doctor or midwife which over-the-counter medicines would be safe for you to try. The antihistamines diphenhydramine hydrochloride and doxyalamine are sometimes used as sleep aids because drowsiness is a side effect. (These ingredients are found in Benadryl, Sominex, and Unisom, for example.)
Other possible side effects include impaired alertness and dizziness, so don't drive or operate machinery after taking either of these medications. And again, check with your healthcare provider before taking any medication while you're pregnant.
Prescription medicine
If you're suffering from severe insomnia or anxiety, your healthcare provider may recommend that you take a prescription sleep medication. Never drive or operate machinery after taking a drug to help you sleep.