Almost nine out of ten Australians take some form of medication, according to a recent poll. Much of that will be in tablet form, either prescribed or bought over the counter.

But in the rush of daily life it can be easy to confuse or mix up pills, especially if you or someone you care for is taking several medications. So how can you be sure the pill you’re about to take is the correct one?

We’ve designed some technology that could help with this issue. Also, the tool might one day be suitable for pill testing at music festivals and other events where other pill drugs are available.

Read more: Your period tracking app could tell Facebook when you're pregnant – an 'algorithmic guardian' could stop it

In our experiments we have demonstrated how off-the-shelf mobile hardware can be used to identify pills. Soon we expect this hardware may be built into most smartphones.

How does it work?

The enabling technology, known as near-infrared spectroscopy, is not new. What is new is that it has been miniaturised.

The technology works by shining infrared light onto the pill. The pill absorbs and reflects some of the light depending on its chemical composition.

By measuring the spectrum of the reflected light, we can obtain a unique signature for this pill. By cross-referencing this signature against a database on known pills or chemicals we can identify the pill.

Smart Hospital Living Lab , Author provided

The technology does not damage the pill, since it simply shines infrared light for a couple of seconds.

It does not rely on the visual appearance of the pill at all. In our tests we could accurately differentiate between pills that look virtually identical.

Further accuracy improvements are expected soon. But at this stage we can say this technology allows for pill-testing to be done on the spot, using a mobile device. It’s no longer necessary to ship samples to a dedicated testing facility.

At the moment the technology has been tried on only about 60 pills that can be bought over the counter, such as painkillers, vitamins and other supplements. It could easily be extended to prescription medications.

We actually developed our prototype to be used on prescription and over-the-counter pills, as a way to make sure people are taking the correct medication. This work is being carried out as part of a broader Smart Hospital project to make hospitals safer and more efficient.

For example, medication errors occur when nurses give the incorrect pill to patients in a hospital, or when patients take the wrong pill at home. Our technology has been designed to reduce such errors due to mislabelling or lack of labels.

Which brings us to the debate on pill testing.

Checking ‘other’ pills

It’s become clear that our technology also has the potential to check other types of pills and could be used in scenarios such as people attending music festivals, on-the-spot police checks, or any other situation.

But there are some potential problems here. Our work has shown that environmental factors – such as ambient light – may affect the accuracy of the system, so it’s unlikely to be as accurate as in controlled lab settings.

Also, because our prototype works by cross-referencing to a database of known pills, it can be challenging for the system to identify home-made pills that may not exactly match the chemical composition in our database.

Still, there are a couple of ways to deal with this situation.

First, the system can provide a confidence rating, effectively saying that it has not seen a particular pill before, but it can report which pill it is most similar to.

Second, if we are interested in certain active chemical components in the pill, it can report which of those components are present in the pill, but not necessarily in what amounts.

The tech’s coming, ready or not

The technology for pill testing is changing quickly. Soon these changes will have an impact on the arguments used by the different sides of the pill-testing debate that has gripped Australia.

Our technology demonstrates the potential for making pill-testing a private matter, with no need for any taxpayer-funded testing at events. It is entirely conceivable that soon it will be possible to buy a pill-testing device that you can carry in your pocket and use where and when you choose.

Pill-testing proponents argue that it has the potential in its current form at festivals to be one last safeguard and source of advice before pills are consumed (or not).

Read more: Here's why doctors are backing pill testing at music festivals across Australia

With the pill-testing technology maturing and being miniaturised even further, we expect within a few years to see widespread prototypes being used. While the hardware is quickly improving, the main challenge remains the analysis that we have developed to differentiate between pills.

We want to raise awareness about this technology and advise all camps in the pill-testing debate that they need to consider how to respond to this technology.

Pill-testing critics might need to consider ways to stop pill-testing given the availability of cheap testing devices – should such devices be banned?

Pill-testing supporters need to consider that pill-testing may soon be possible outside well-staffed festival tents. Therefore, there is a need for new interventions, as well as a consideration of who maintains the pill database: government, industry, NGOs, or perhaps some crowdsourced approach?