this is how i learned it. if you have a heterocyclic compound (for example with an oxygen atom) and an atom has two lone pairs, then the first lone pair can donate into the system and the second loan pair cannot. this would make the oxygen atom sp2. a general rule of thumb (i was told) is that if you have a lone pair of electrons on an atom in a ring and the atom is not already involved in a pi bond (as loveoforganic said) then the lone pair can delocalize into the system