# Do lone pairs contribute towards the pi electron count of heterocycles?

I'm not able to understand how the following compounds are aromatic.

When should the lone pairs on heteroatoms be taken into consideration when counting the number of π electrons?

One lone pair (brown) is in a p-orbital, and hence participates in conjugation with the two π-bonds. The other lone pair (blue) is pointing outwards from the ring in an $\mathrm{sp^2}$ orbital. This lone pair is orthogonal, or perpendicular, to the π-system and hence cannot take part in conjugation. In total there are six π electrons, and the compound is therefore aromatic.