A firearm which went off in the hand of a 12-year-old trespasser was installed as an alarm, a court heard.
All three men deny firearms charges
Skip hire firm owner Jack Clarkson, 63, said he set up the device after a number of break-ins and vandalism at his mill in Burnley, Lancashire.
Jack John Ashley, known as JJ, bypassed the trap as he took the device off the premises when it accidentally went off, Burnley Crown Court was told.
Mr Clarkson, of Worsthorne, Burnley, denies possessing a prohibited firearm.
The home-made device could be triggered by walking into a trip wire which would fire a shotgun cartridge from the barrelled contraption into the ground.
Mr Clarkson said a build-up of thefts, vandalism and fire damage led him to setting up the alarm gun for the first time on 6 April 6 2006, the day of the accident.
The gun fired a blank cartridge less than a hour after Clarkson installed it when youths entered the mill in Gordon Street.
Mr Clarkson redeployed the device but said he did not have time to empty the shotgun pellets from the cartridge and left in live rounds.
The injured boy needed surgery on his damaged hand following the incident.
Under cross-examination Clarkson denied suggestions that he wanted to give the impression of a shotgun being fired at an intruder.
He was supplied the device by his friend, Derek Kokocinski, 56, of Cliviger, Burnley, who is accused of manufacturing a prohibited firearm.
Kokocinski, a fish farmer, said he made the device to help alert him to poachers on his land.
"My intention was to make a noise to alert me. It was purely for signalling, to be pushed firmly into the ground," he said.
He added he was "devastated" that a boy had been injured.
A third defendant, Peter Smith, 51, of Gordon Street, Worsthorne, who was supplied a similar alarm gun by Kokocinski, is also charged with possessing a prohibited firearm on his allotment.
All three deny the charges and the case continues.