From Slate's The Vault (history blog), information about deterring grave-robbers:
The gun, which the museum dates to 1710, is mounted on a mechanism that allows it to spin freely. Cemetery keepers set up the flintlock weapon at the foot of a grave, with three tripwires strung in an arc around its position. A prospective grave-robber, stumbling over the tripwire in the dark, would trigger the weapon—much to his own misfortune.Via The Oddment Emporium.
Grave-robbers evolved to meet this challenge. Some would send women posing as widows, carrying children and dressed in black, to case the gravesites during the day and report the locations of cemetery guns and other defenses. Cemetery keepers, in turn, learned to wait to set the guns up after dark, thereby preserving the element of surprise.