How to set up equation for buffer reaction?
There is a general way to do these sorts of problems. The idea is to consider equilibria of both acid/base and of the water.

When there is solution of a weak acid and it salt, or just the weak acid or just the salt, i.e. pure HA, NaA + HA or pure NaA, then there is no distinction between these types of solution because of the equilibria involved. ( NaA just represents any salt ). The following calculations apply for each or any of these solutions.

Start by defining the equilibrium constants for the reactions. A molecule dissociates as $\mathrm{HA \leftrightharpoons H^+ + A^-}$, but to be general we let the base be [B] instead of $\mathrm{[A^-]}$ and so write $\mathrm{HA \leftrightharpoons H^+ + B}$

$$K_a=\mathrm{[H^+]_e[B]_e/[HA]_e} \tag{1}$$

where the concentrations are those at equilibrium.

There is also the equilibrium $\mathrm{H_2O \leftrightharpoons H^+ + OH^-}$ to consider and

$$K_w=\mathrm{[H^+]_e[OH^-]_e}$$

We know the amounts of acid $c_a$ and base $c_b$ added at the start of the reaction. To obtain the pH at equilibrium the amount $\mathrm{[H^+]}$ has to be calculated. To do this work out the concentration of acid and base in terms of the initial amount and the ionised species.

The total concentration of HA is 

$$c_a=\mathrm{[HA]_e+[H^+]_e - [OH^-]_e}\tag{1a}$$

and for the base 

$$c_b=\mathrm{[B]_e -[H^+]_e + [OH^-]_e\tag{1b}}$$

The e subscripts are now dropped for clarity. [Note that some authors use mass and charge balance instead to work out the concentrations.]

These values can be substituted into the equilibrium constant equation (1) and using $K_w=\mathrm{[H^+][OH^-]} $. Substitution leads to the general equation

$$K_A=\mathrm{[H^+]}\frac{c_b + \mathrm{[H^+]} - K_w/\mathrm{[H^+]} }{c_a - \mathrm{[H^+]} + K_w/\mathrm{[H^+]}  }\tag{2}$$ 

which is a cubic equation in $\mathrm{[H^+]}$ that is best solved numerically in the most general case. This equation can be simplified under different conditions as the examples below demonstrate.

Note that when $c_b=0$ equation (2) describes the case of pure HA, when $c_a=0$ it describes the hydrolysis of pure NaA solution.

The figure shows how the pH changes for a weak acid/conjugate base with the p$K_A$ shown and $c_a$ = 0.01 M over a range of $c_b$ concentrations. The curve was calculated by numerically solving eqn 2.  The straight line (coloured grey) is the Henserson-Hasselbalch equation described below in (A). It is clear where this approximate equation fails.



Figure 1. pH vs concentration of base $c_b$. Red line full calculation, straight line (grey) the approximate Henderson-Hasselbalch eqn. The dashed lines show the p$K_A$ and the acid concentration $c_a$ used. The region where the Henderson-Hasselbalch eq. is a good approximation is clear; $c_b$ should be no less than $\approx 0.1c_a$. The plot uses the values in example (B).



Example (A) The Henderson-Hasselbalch eqn is an approximation but limits should be tested.

When the concentrations $c_a$ and $c_b$ are far larger than $(\mathrm{[H^+]} + K_w/\mathrm{[H^+]})$ or $(\mathrm{[H^+]} - K_w/\mathrm{[H^+]})$ these terms  can be ignored without error. This produces 

$$\mathrm{[H^+]} = K_Ac_a/c_b,  \qquad \mathrm{pH}=\mathrm{p}K_A - \log_{10}(c_a/c_b)  $$

which is the formula often used. The log form is called the Henderson-Hasselbalch eqn.  It is often the case that $c_a/c_b=1$ then $\mathrm{pH}=\mathrm{p}K_A$.

Example B. What is the pH of a buffer solution consisting of 0.01 M of a weak acid with $K_A$ = 1.5$\cdot$ 10-4, and 0.01 M of its conjugate base?

We could use eqn. 2 but this means solving a cubic which is not necessary. Realising that in acid solution $\mathrm{[H^+] \gg [OH^-]}$ then

$$K_A=\mathrm{[H^+]}\frac{c_b + \mathrm{[H^+]} - K_w/\mathrm{[H^+]} }{c_a - \mathrm{[H^+]} + K_w/\mathrm{[H^+]}  } \to \mathrm{[H^+]}\frac{ (c_b + \mathrm{[H^+]}) }{ (c_a - \mathrm{[H^+]} )}   $$ 

This equation has to be solved and not approximated to the Henderson-Hasselbalch eqn. since $\mathrm{[H^+]}$ may not be very different to $c_b$. 

Letting $x =\mathrm{[H^+]}$ then $x^2+(c_b+K_A)x-K_Ac_a=0$ or 

$$x=\frac{-(c_b+K_A)+\sqrt{(c_b+K_a)^2+4c_aK_A}}{2} $$

which gives $\mathrm{[H^+]}=1.45\cdot 10^{-4}$ or a pH = 3.84. This answer is close to that of the HH equation which gives $\mathrm{pH = p}K_A =  3.82$, so as it turns out the HH equation was good enough.