This is a tale of how hunger and lust can lead to doom. It's not a moral tale for humans, though: it's about beetles. The story begins a few months hence. Later this summer, farmers up and down the country will gather this year's grain harvest - all 20 million tonnes of it - and put it into storage ready to be sold.

This is the moment that one group of insidious pests will have been waiting for. Hiding in cracks and crevices in grain stores throughout the land are tiny beetles capable of causing significant damage to stored cereals.

Until recently the methods used for detecting infestation by such insects were relatively crude and inaccurate. They involved simply inspecting the crop by eye, or else taking samples from within the bulk of the grain by using a long, hollow rod. Failure to detect early signs of infestation can be disastrous.

A farmer or trader who discovers insect infestation has to take remedial action - usually by spraying the crop with an organophosphate pesticide. Many farmers spray the grain anyway, just in case. Around 1.4 million tonnes of grain is treated with such contact pesticides each year. This means that some five tonnes of organophosphate is being used, some of it needlessly.

If farmers had a better way of detecting the presence of beetles, it would enable them to do two things. First, they could find out much sooner if there was an infestation, and treat the grain before the damage was too great. Second, they could confidently confirm that there was no infestation, so there would be no need to spray the crops "just in case".

Now a group of researchers at the Government's Central Science Laboratory (which has just relocated to York) believes it has a solution.

After 10 years' intensive research, funded by the Ministry of Agriculture, Dr John Chambers and his team have developed a cunning way of using the whiff of sexual promise to lure unsuspecting beetles into strategically placed traps hidden within the grain store.

Tests have shown that the traps are around one hundred times more efficient at indicating the presence of the insects than traditional techniques relying on visual inspection alone.

"Trying to find these beetles - which are only five or six millimetres long - in a huge grain store is slightly more difficult than looking for a needle in a haystack," said Dr Chambers.

A few years ago the team developed a cone-shaped trap with a perforated dome lid and an internal surface coated with Teflon so that trapped insects could not escape by climbing out. While this in itself was a big improvement on traditional methods, it still relied on the beetle finding the trap, rather than the trap finding the beetle.

Dr Chambers's team turned its attention to the saw-toothed grain beetle, Oryzaephilus surinamensis, an important pest worldwide.

The team wanted to see if it was possible to entice the beetles to follow their noses into traps that had been laced with pheromones, the volatile substances produced by animals to attract mates.

The first problem was to isolate and identify the appropriate pheromones from the beetle.

"We passed a stream of air over a culture of around ten thousand beetles and collected the aroma given off by the culture. This mixture contained around 200 chemicals, and we had to find out which ones of these were the attractants," said Dr Chambers.

To do this, the team used an incredibly intricate technique called electroantennography. A tiny wire made from tungsten was sharpened electrochemically to create a microscopic drill bit. This was used to bore a hole into the antenna of a beetle, through which an electrode was inserted. The electrode was sensitive enough to detect tiny electrical disturbances in the antenna, which occur when the antenna is "excited" by something in the air.

Next, the mixture of 200 chemicals was passed through a gas chromatograph. This does two things: it separates the chemicals from each other and it characterises them by their molecular "signature".

The mixture was fed into the gas chromatograph at one end and the now- separated compounds passed over the beetle at the other. As the beetle encountered each chemical in turn, the electrical signals coming from its antennae were monitored. In this way, two chemicals which excited the beetle were identified.

However, the problem was far from solved. One male beetle produces only 80 million millionths of a gram of these pheromones in an hour. Hardly sufficient to generate industrial-scale quantities needed by the world's agricultural community.

"These pheromones are a class of compound called macrocyclic lactones, which are relatively easy for the beetle to produce. But they're difficult to synthesise in the laboratory," says Dr Chambers. Nevertheless, in collaboration with Southampton University, a new synthetic route to a series of lactones was developed that could produce useful quantities of the chemicals.

This was followed by a detailed programme testing beetles' behaviour in response to the synthetic pheromones. Mixtures of the chemicals in different proportions were passed into enclosures containing beetles, and their reactions monitored.

The researchers eventually formulated a cocktail - including a volatile compound from a fungus, besides the two pheromones - that actually proved more attractive to the beetles than their own natural pheromone mixture.

Unusually, the pheromones attract both male and female beetles. The hypothesis for this is that it encourages large numbers of beetles to congregate in one mass, causing the local temperature to rise and so providing a favourable "micro-environment" for reproduction and growth.

The final part of the jigsaw was to devise a means of packaging the pheromone mixture. The answer was to seal a solution of the mixture in a plastic capsule that gradually leaks its contents, in a slow and controlled release.

The team has now produced a trap in which the pheromone mixture can be released over a six-week period. As soon as grain is put into storage, the traps can be placed at strategic points in the surface and within the body of the grain, and examined periodically for signs of infestation.

Licensing agreements have been reached with commercial distributors and Dr Chambers expects that the pheromone lures will be available to farmers in time for this year's harvest, at a cost of between pounds 2 and pounds 3 each.

It might seem expensive - though it's worth reflecting that the beetles led astray by an artificial scent will pay an even higher pricen