The basic idea of a set gun or a spring gun is really simple. First, a thin thread or wire is stretched across the zone that is meant to be protected. Then, one end of the thread is tied to the trigger of a firearm, which is then tied to a tree or a support pole. The firearm is then loaded and prepared to be ready to fire. Any person or animal that walks into the zone will then set off the firearm. In some cases, the firearm is simply meant to fire a warning shot and scare the intruder into leaving the area (as well as warn the defenders of the presence of an intruder). In other cases, the firearm is aimed at the zone it is meant to protect, so it may end up killing or injuring the intruder. These have been used historically for various reasons, such as guarding a campsite from wild animals, setting a trap for an animal, maintaining a defensive perimeter around military stores, guarding against poachers etc.
Typically, the firearm in question is usually some kind of shotgun because it sprays a wide area.
A 19th century alarm gun designed to deter poachers by firing a blank in the air.
Image released into the public domain by Simon Speed. Click on image to enlarge.
A Spring gun currently on display in the Pitt Rivers Museum in Oxford England. Click on image to enlarge.
Image released under GNU Free Documentation License 1.2 or later, by user Throwawayhack at Wikipedia
Such traps were very popular in England during the 1700s, but became illegal to use after 1825. In the United States, such traps have made it to the 20th century, though they are not used as much now. The firearms are also generally loaded with non-lethal shot to avoid lawsuits and the areas are generally marked with warning signs and high fences to reduce legal risks as well. One famous legal case to study in this regard is Katko vs. Briney, which took place in Iowa in 1971 and the defendant (Briney) was held liable for injuries caused to the intruder (Katko). Briney had an old unoccupied farmhouse on his property, which was in a state of disrepair and had "No Trespassing" signs all over it, but was often broken into and burgled constantly. Hence, he rigged a shotgun to fire at any intruders that opened one of its doors. The shotgun was aimed to fire at an intruder's legs, so as not to cause mortal injuries. A few days later, Katko broke in to collect some old bottles and was injured by this trap. The Iowa Supreme Court ruled that the defendant's use of deadly force on unoccupied property was not reasonable or justified and Briney would have been justified in the use of a shotgun, had he been in the farmhouse during the intrusion. After the lawsuit, some news papers incorrectly reported that the Briney residence had been broken into (not the unoccupied farmhouse). Therefore, several other states introduced "Briney bills" for laws concerning self-defense of property and family.
Instances of set gun traps were also seen during the Vietnam war, as well as other guerilla conflicts around the world.
One more famous incident where a set gun was involved, was the Gunpowder Incident, which happened shortly before the American Revolution. In Williamsburg, Virginia, the British governor, Lord Dunsmore had begun to move supplies of gunpowder to Royal Navy ships against the wishes of the locals, who believed that the gunpowder belonged to the colony and not the Crown. On the night of June 3rd 1775, two local youths were injured by a spring gun set up to protect the warehouse where the supplies were stored. The local population were outraged and the governor was forced to flee with his family, on to the British vessel Fowey, which was anchored off-shore. Governor Dunsmore then declared Virginia to be in a state of rebellion. Incidentally, the local force that opposed governor Dunsmore was led by Patrick Henry of "Give me liberty, or give me death" fame.