I am trying to show that for $n \geq 3$, $Z(D_{2n}) = 1$ for odd $n$ and $Z(D_{2n}) = \{1, r^{\frac{n}{2}}\}$ for even $n$. This is my attempt.
Let $g \in Z(D_{2n})$ and write $g = s^x r^y$ for $x \in \{0,1\}$, $y \in \{0, \ldots, n-1\}$. If $g$ is in the center, it commutes with $s$: \begin{align*} s(s^x r^y) & = (s^x r^y)s \\ s^x (s r^y) & = s^x r^ys \\ s^x (r^{-y} s) & = s^x r^y s \end{align*} Cancelling gives: \begin{align*} r^{-y} & = r^y \\ (r^y)^{-1} & = r^y \end{align*} So $r^y r^y = r^{2y} = 1$. $r$ has order $n$, so $n \mid 2y$.
At this point I should be able to conclude that if $n$ is odd, $2y = 0$, so $y = 0$, but if $n$ is even, $y = \frac{n}{2}$. I cannot figure out how to prove this step, which would complete the proof.
The dihedral group has presentation $\langle a,b \mid a^n=b^2=1, bab=a^{-1}\rangle.$ It has $n$ involutions $b,ba,\dots , ba^{n-1}$ conjugated by powers of $a$ and $n$ powers of $a$. None of the involutions above is in the center because they do not commute with $a$.
A power $a^i$ of $a$, $0\le i \le n-1$, is in the center iff it commutes with $b$, so iff $ba^ib=a^i$ or $a^i=a^{-i}$ or $i\equiv -i \mod n.$
If $n$ is even then this implies $i\in\{0,n/2\}$ and if $n$ is odd $i=0$. Thus if $n$ is even the center consists of two elements and if $n$ is odd the center is trivial.