How can I design a low pass filter using Z transform in Microcontroller?
The usual method to design an IIR filter is to start with a frequency response we want, for example.

$$A(s)= \dfrac{1}{1+\dfrac{s}{\omega_p}}$$

Where \$ \omega_p \$ is the pole frequency in \$ \text{rad}\cdot \text{s}^{-1}\$.  We can convert this to time domain by using the Tustin or bi-linear transformation.

$$s = \dfrac{2}{T} \cdot \dfrac{1-z^{-1}}{1+z^{-1}}$$ 

Where \$T\$ is the time between samples.  This gives us a new function in \$z\$

$$ H[z] = \dfrac{y}{x} = \dfrac{1}{1+\dfrac{2}{\omega_p\cdot T} \cdot \dfrac{1-z^{-1}}{1+z^{-1}}}$$

With a bit or arithmetic we can get this of the form:

$$ H[z] = \dfrac{y}{x} = \dfrac{B_0+B_1 \cdot z^{-1} + B_2 \cdot z^{-2} + ... }{1-A_1 \cdot z^{-1} - A_2 \cdot z^{-2} - ...}$$

Now we note that \$ z^{-1} \$ represents one step back in time, \$ z^{-2} \$ represents two steps back in time and so on.

In this particular example we only need to worry about the the current a previous one values.

let \$y_0\$ be the current output, \$y_1\$ be the previous output, \$x_0\$ be the current input, \$x_1\$ be the previous input.

At each stage we can calculate a new \$y_0\$

$$y_0 = A_1 \cdot y_1 + B_0\cdot x_0 + B_1\cdot x_1$$



You can also design this as an FIR filter but because these do not look at previous outputs you would have significantly more terms.

$$y_0 = B_0 \cdot x_0 + B_1 \cdot x_1 + B_2 \cdot x_2 +  ...$$