Staff found James Rooney in the toilet of the Sea Breeze Cafe in Leith at 3pm on Wednesday. They immediately summoned the police and an ambulance.
Medics disposed of the syringe and, after rousing Rooney, 29, who was uninjured, they left. Police officers then searched him and found heroin in his trouser pocket. He was arrested and spent a night in a police cell. Appearing from custody at Edinburgh Sheriff Court today, he pleaded guilty to possessing the drug.
Defence agent Ewen Roy said that Rooney, of Niddrie Mains House, Edinburgh, had overcome a drug problem through a rehabilitation programme but had relapsed on Wednesday.
"He was given a small amount of the drug by a friend and succumbed to temptation by taking it," Mr Roy said.
Because his body was no longer used to heroin it was a shock to his system and he fell unconscious.
Sheriff Noel McPartlin fined him 200.