Is It Legal: Can you booby trap your home?

Let's say your home is burglarized more than once and you get fed up with the crime. So you set up a trap to stop any criminal in their tracks if they try to break in.