Lie down on your right side first. Put the right arm under your head and use the left arm for support in front of the belly. Fold both the legs at the knee and raise the left knee in the air. Circle it in one direction 7-10 times and then circle it in the opposite direction. Make the circles as wide as possible.
Next comes the leg raises. Bring your left leg down. Straighten it and then raise it as high as you can. Remember not to overstretch as it is easy to do so in pregnancy. Raise the leg up and down. Repeat this action for about 3-4 minutes. Then cross your left leg over so it is sitting in front of your belly. Hold the ankle with your left arm. Now straighten the right leg and start raising the right leg a few inches above the ground. You will feel a stretch in your inner thigh muscle. Bring the right leg up slowly and then bring it back down. Repeat for a minute or so. Then, raise the right leg faster a few times, 5-10 times, depending on your stamina. At the last raise, hold the right leg in the air and count to five.
Now turn over to lie on your left side. Bring the left arm under your head, the right arm in front of your belly to support yourself from rolling over, fold the legs and raise your right knee in the air. Circle the knee, first in one direction and then the other direction. Once finished, straighten your right leg and raise it up and down. Next cross it over to bring it in front of your belly and hold it with your right arm at the ankle, raise your left leg up and down, first slowly and then faster. Finally hold it still in the air for a count of five.
I started doing these in the night whenever I woke up due to painful hips and legs. I would keep lying in bed, do these exercises and would feel so much better that I had no problems falling back to sleep right away. Of course, when in doubt, you should always consult your OBGYN or midwife to make sure that it is safe for you to do.