Example 7 Let $S=\left\{A=\left(a_{1}, a_{2}, \cdots, a_{8}\right) \mid a_{i}=0\right.$ or $\left.1, i=1,2, \cdots, 8\right\}$, for any two elements $A=\left(a_{1}, a_{2}, \cdots, a_{8}\right)$ and $B=\left(b_{1}, b_{2}, \cdots, b_{8}\right)$ in $S$, denote $d(A, B)=\sum_{i=1}^{8}\left|a_{i}-b_{i}\right|$, and call it the distance between $A$ and $B$. How many elements can be selected from $S$ at most, such that the distance between any two of them is $\geqslant$ 5?
(1995 Chinese National Team Selection Test)