  We present an optimized scheme for nanoscale measurements of temperature in a
complex environment using the nitrogen-vacancy center in nanodiamonds. To this
end we combine a Ramsey measurement utilized to temperature determination with
advanced optimal control theory. We test our new design on single
nitrogen-vacancy centers in bulk diamond and fixed nanodiamonds, achieving
better readout signal than with common soft or hard microwave control pulses.
We demonstrate temperature readout using rotating nanodiamonds in an agarose
matrix. Our method opens the way to measure temperature fluctuations in complex
biological environment. The used principle however, is universal and not
restricted to temperature sensing.
