An apprentice mechanic turned to dealing drugs after racking up bills for his car which he could not pay.
Byron Thomas, 22, was caught after a local resident saw him smoking some of the cannabis with two friends behind some garages in Royal Wootton Bassett.
Although the three had nothing on them when they were searched, the police went on to search Thomas's car.
In it they found almost £2,000 worth of the drug, some in wraps ready for sale, along with scales, a pipe and a cannabis grinder.
Colin Meeke, prosecuting, told Swindon Crown Court that Thomas was caught in the parking area behind Fairfield on Thursday, October 4.
He said a member of the public approached a police community support officer to say some young men were smoking drugs behind the garages.
After calling in a policeman to help him, they found nothing apart from £195 in Thomas' pocket.
"This arose the police's suspicion and they investigated further and Thomas indicated a car nearby was his," Mr Meeke said.
In the vehicle the found the paraphernalia along with a tobacco tin containing three small bags of herbal matter along with a larger bag of drugs.
Mr Meeke said the small bags were in total worth about £70 and the larger amount, weighing 163 grams, had a street value of around £1,800.
When he was questioned he said he had been smoking drugs with his friends and acknowledged he had been selling drugs for about five weeks.
"Asked in terms what he was going to do with the money he said it was 'either going to be saved or spent to better myself'," he said.
Thomas, of Tanners Close, Royal Wootton Bassett, pleaded guilty to possession of cannabis with intent to supply and supply.
Rob Ross, defending, said his client was plainly not an experienced dealer but thought he would try and make some extra by selling to friends. He said he had bought about six ounces of cannabis for £1,500 and looked likely to make a profit of about £150.
"He is a young man of 22 years of age who has never been in trouble with the police before," he said.
"He's two years into a three year apprenticeship as a mechanic with a good company with prospects for the future.
"He had some bills to pay on his car, was strapped for cash, smoked a bit of dope himself and decided to us this money he had saved over a long period of time to buy some cannabis and sell it.
"Someone calls the police because three young men are smoking drugs behind a garage and he is utterly honest with them."
Judge Douglas Field said: "I think you will have learned your lesson if I pass a suspended sentence."
He jailed him for six months suspended for a years and ordered him to do 250 hours community service and forfeit the drugs, cash and paraphernalia.