“Dark Knight’’ madman James Holmes thought he could make a clean getaway after slaughtering 12 moviegoers at a midnight showing of the new Batman film in Aurora, Colo., but got tripped up by his faulty devices and eagle-eyed police officers.

The killer, 24, had set a timer to turn on his apartment’s stereo at full volume before he left on his deadly mission, hoping neighbors would complain to cops.

Then, when police got to his home, they’d be killed by his booby traps, diverting attention from the theater, where he could go on killing — and still have time to escape dressed as an Aurora police SWAT-team member, law-enforcement sources told The Post yesterday.

“The guy was a mad scientist,” a source said. “There was a magnetic switch [in his apartment so that] when the door opens up, it would trip a chemical container into another chemical container that would ignite the cans of gasoline and light up the whole place and kill the cops.”

But Holmes’ diabolical plot failed because of a series of miscalculations.

First, cops didn’t respond to the noise in the apartment — where trip wires crisscrossed the pad and canisters of explosive liquids and scores of mortars shaped like bullets were strewn about.

Had the trap worked, fireball alone would have blown up and consumed the entire third floor of the apartment building,” a source told the LA Times.

Holmes told cops about the bombs after his arrest, bolstering the theory that he had laid his trap so he could wreak more havoc at the theater before making a getaway.

Not only did that plot fail, but Holmes’ semiautomatic assault rifle — which could fire up to 60 rounds a minute — jammed mid-rampage. It’s unclear how many bullets he emptied from the 100-round drum magazine before the snag, but he was forced to switch to his other legally purchased weapons, a .40-caliber Glock and a Remington shotgun, which had less ammo.

And after wounding 70 people — 12 of whom died — the heavily armed ex-University of Colorado grad student fled through an emergency exit as cops arrived

He was wearing body armor bought from the same outfit that supplies Aurora cops. But if he hoped to blend in with authorities and flee, he was wrong.

“It was one aspect of what he was wearing that did not fit what a SWAT officer might be wearing. There was one particular piece of equipment that he had on him that was out of place,” Aurora Police Chief Daniel Oates said, declining to be specific.

A source told The Post it was the fiend’s throat and groin guards, which cops are issued as standard gear — but never wear because they restrict movement.

“I am so proud of my officers that they spotted that right away and challenged him,’’ Oates said.

Holmes — who’s “totally crazy, he’s walking around talking like a Joker” in prison, a source told The Post — was being held in solitary confinement in the women’s section at the Arapahoe County Jail, another source said.

Tasha Taylor visited a relative who told her “they brought him in a restraint chair and they put all the women on lockdown.’’ The relative quoted a guard saying, “Once they got his armor off, his whole body was painted red’’ and they had to put him in a shower.

Cops said they may now have a lead as to what drove the geeky scientist wannabe over the edge: a relationship that soured.

“I’ve heard one morsel of information about a relationship that may or may not be true, and that’s why we have all our investigators working on this,” Oates told CBS’s “Face the Nation.’’

The suspect — who had dyed his hair red and told cops he was the Joker — also had a “Batman’’ mask, poster and other paraphernalia in his pad, the LA Times said.

His home computer was seized, and “we’re hopeful that will yield some information,” Oates said.

The owner of a local shooting range said Holmes had applied for membership there a few weeks before the bloodbath — but when the owner called back, he heard a disturbing message on the voice mailbox.

“I heard his name, and it was just kind of a bizarre music, stupid stuff,’’ Lead Valley Range owner Glen Rotkovich said.

“I said to myself, ‘What’s with this guy?’ I don’t know if it was the Joker or Batman or who he was trying to be — if anybody. I never saw the movie.”

Holmes may have learned some of his shooting skills as a paintball buff. He had taped to the closet door in his bedroom a poster advertising a 2006 paintball DVD called “Soldiers of Misfortune.”

Der Der Video Productions — based in San Diego, where Holmes grew up — also sells the videos “Bring Out Your Dead” and “Headshot,” and bills the expert shooters in the video Holmes favored as “The Contract Killers.”

Holmes bought his body armor from TacticalGear.com. based in Missouri.

“Obviously, everybody in the office was shocked and disheartened by that fact, ” said company CEO Chad Weinman.

University of Colorado officials are looking into whether Holmes used his position as a grad student there to order chemicals and other materials for the booby traps cops removed from his apartment.

Police said Holmes received deliveries over four months to both his home and at school, but they haven’t said what was in the packages.

Holmes is scheduled to appear with his public defender in court today, and the proceedings will be televised.

His father. Robert Holmes, 61, of San Diego flew to Denver Friday and was expected to attend.

ABC posted a 6-year-old video of Holmes from when he was an 18-year-old at Miramar College in San Diego. In it, he seems to be fascinated by reality versus illusion.

HEART-WRENCHING: Crosses at a makeshift memorial in Aurora, Colo., are a sad reminder yesterday of the 12 victims of a madman’s shooting spree at “The Dark Knight Rises” movie premiere on Friday. (Reuters)

Additional reporting by Josh Saul in New York and Barry Bortnick in Colorado