What does D2 do in this schematic?
D2 protects Q1 from reverse bias on its B-E junction.

A typical small-signal transistor can only withstand a few volts of reverse bias before it breaks down, and an antiparallel diode limits it to about 0.7&nbsp;V.

R31 limits the current into the transistor when the input is positive, and it also limits the current through the diode when the input is negative.