Apart from the story about a turnip, there is another legend - about Jack the drunkard who managed to fool the devil twice, and was punished afterwards. Then, after death, he wasn't allowed to go to Heaven. Neither God, nor Devil needed him.
Restless Jack waiting for the Doomsday was forced to wander on earth, He lightened up his way only with a small piece of coal in his hands. Jack put this light in a pumpkin and set off his journey.
The name of the lantern (lamp) originates from this story - jack-o-lantern, short form from "Jack of the lantern". People think that if you put a pumpkin or a turnip near your house, or just near your house, it will turn away all the evil spirits.