  We provide a new method to derive heavy element abundances based on the
unique suite of nebular lines in the mid- to far-infrared (IR) range. Using
grids of photo-ionisation models that cover a wide range in O/H and N/O
abundances, and ionisation parameter, our code HII-Chi-mistry-IR (HCm-IR)
provides model-based abundances based on extinction free and temperature
insensitive tracers, two significant advantages over optical diagnostics. The
code is probed using a sample of 56 galaxies observed with $Spitzer$ and
$Herschel$ covering a wide range in metallicity, $7.2 \lesssim 12+\log(O/H)
\lesssim 8.9$. The IR model-based metallicities obtained are robust within a
scatter of 0.03 dex when the hydrogen recombination lines, which are typically
faint transitions in the IR range, are not available. When compared to the
optical abundances obtained with the direct method, model-based methods, and
strong-line calibrations, HCm-IR estimates show a typical dispersion of ~0.2
dex, in line with previous studies comparing IR and optical abundances, a do
not introduce a noticeable systematic above $12+\log(O/H) \gtrsim 7.6$. This
accuracy can be achieved using the lines [SIV]$_{10.5 \mu m}$,
[SIII]$_{18.7,33.5 \mu m}$, [NeIII]$_{15.6 \mu m}$ and [NeII]$_{12.8 \mu m}$.
Additionally, HCm-IR provides an independent N/O measurement when the
[OIII]$_{52,88 \mu m}$ and [NIII]$_{57 \mu m}$ transitions are measured, and
therefore the derived abundances in this case do not rely on particular
assumptions in the N/O ratio. Large uncertainties (~0.4 dex) may affect the
abundance determinations of galaxies at sub- or over-solar metallicities when a
solar-like N/O ratio is adopted. Finally, the code has been applied to 8
galaxies located at $1.8 < z < 7.5$ with ground-based detections of far-IR
lines redshifted in the submm range, revealing solar-like N/O and O/H
abundances in agreement with recent studies.
