R9 is connected to the "hot" lead of the AC power line
and to pin GP4. The ESD protection diodes of the
input structure of the GPIO allows this connection
without damage (see Figure 1). When the voltage on
the AC power line is positive, the protection diode from
the input to VDD is forward biased, and the input buffer
will see approximately VDD+0.7 volts and the software
will read the pin as high. When the voltage on the line
is negative, the protection diode from VSS to the input
pin is forward biased, and the input buffer sees
approximately VSS-0.7 volts and the software will read
the pin as low. By polling GP4 for a change in state,
the software can detect a zero crossing.
Since there is no transformer for power-line