A man caught trying to have sex with his bicycle has been sentenced to three years on probation.
Robert Stewart, 51, admitted a sexually aggravated breach of the peace by conducting himself in a disorderly manner and simulating sex.
Sheriff Colin Miller also placed Stewart on the Sex Offenders Register for three years.
Mr Stewart was caught in the act with his bicycle by cleaners in his bedroom at the Aberley House Hostel in Ayr.
Gail Davidson, prosecuting, told Ayr Sheriff Court: "They knocked on the door several times and there was no reply.
"They used a master key to unlock the door and they then observed the accused wearing only a white t-shirt, naked from the waist down.
"The accused was holding the bike and moving his hips back and forth as if to simulate sex."
Both cleaners, who were "extremely shocked", told the hostel manager who called police.
Sheriff Colin Miller told Stewart: "In almost four decades in the law I thought I had come across every perversion known to mankind, but this is a new one on me. I have never heard of a 'cycle-sexualist'."
Stewart had denied the offence, claiming it was caused by a misunderstanding after he had too much to drink.
The bachelor had been living in the hostel since October 2006 after moving from his council house in Girvan.
He now lives in Ayr.
Bike sex case sparks legal debate
The case of a man convicted of simulating sex with his bicycle has sparked a debate about human rights and the privacy of an individual.
Internet message boards have been buzzing with comment about the case of Robert Stewart, 51, from Ayr.
He was reported by cleaners at a hostel who unlocked his door and found him engaged in a sex act with his bike.
Stewart was put on the Sex Offenders' Register, which some posters said was an over-reaction by the sheriff.
Stewart admitted a sexually aggravated breach of the peace by conducting himself in a disorderly manner and simulating sex. As well as being put on register for three years, he was put on probation for the same length of time.
More than a million people have read the story on the BBC news website and it has been hotly debated on forums elsewhere.
One contributor asked: "Would they have done the same to a woman with a sex toy?
"Apart from the fact that the sex toy was manufactured for the purpose, and a bicycle wasn't, I really don't see that the two acts are all that different."
Another blogger said: "I am more disturbed by the sheriff's ruling than the act of having sex with a bike."
Those discussing the case online were also worried about the future implications.
One person wrote: "It's bad news for privacy in the UK because of how a ruling like this could be used to support similar cases in future."
Legal experts said he would have been placed on the Sex Offenders' Register under Section 80 of the Sexual Offences Act 2003.
This states that a person should be put on the register "if the court determines that there was a significant sexual aspect to the offender's behaviour in committing the offence".
This is not the first legal case involving someone simulating sex with an inanimate object.
In 1997 Robert Watt, 38, was fined £100 for trying to have sex with a shoe in an Edinburgh street
In 2002 the same man was arrested for simulating sex with a traffic cone in front of a crowd of people
Earlier this month, sentence was deferred on teenager Steven Marshall, from Galashiels, who admitted simulating sex on a pavement while drunk.
Human rights lawyer John Scott told the BBC Scotland news website that the case raised important privacy issues.
He said: "It certainly prompts questions about what people can and can't do behind closed doors with inanimate objects.
"However, the difficulty is that the man involved in this case pleaded guilty to a breach of the peace so these issues of privacy weren't considered by the court."
He added: "The sheriff had to act on the guilty plea and make a decision about whether or not there was a sexual nature to the offence. Clearly there was and that's why the man has ended up on the register."
However, Mr Scott said it should not be seen as a test case or one that would set a precedent in the future.
"This case should not prevent people who want to engage in this sort of activity doing so.
"What I would say to a client of mine that wanted to do this kind of thing is as long as it's behind a bolted door, with an inanimate object, then each to their own."