5. Given the function
$$
f(x)=4 \sin 2 x+3 \cos 2 x+2 a \sin x+4 a \cos x
$$

has a minimum value of -6. Then the value of the real number $a$ is $\qquad$.
5. $\pm \sqrt{2}$.

Let $\sin x+2 \cos x=t$. Then
$$
t \in[-\sqrt{5}, \sqrt{5}],
$$

and $2 t^{2}=4 \sin 2 x+3 \cos 2 x+5$.
Thus, $f(x)=g(t)$
$$
=2 t^{2}+2 a t-5(t \in[-\sqrt{5}, \sqrt{5}]) \text {. }
$$

Since the minimum value of the function $f(x)$ is -6, we have
$$
2 t^{2}+2 a t-5 \geqslant-6 \text {. }
$$

Taking $t=\frac{1}{2}$, we get $a \geqslant-\frac{3}{2}$;
Taking $t=-\frac{1}{2}$, we get $a \leqslant \frac{3}{2}$.
Thus, $-\frac{a}{2} \in[-\sqrt{5}, \sqrt{5}]$.
Hence, $g(t)_{\min }=g\left(-\frac{a}{2}\right)=-\frac{a^{2}}{2}-5=-6$
$$
\Rightarrow a= \pm \sqrt{2} \text {. }
$$