Using an AVR timer to generate a 38 kHz signal
You are not updating PB2, you set it high in the 1st delay and then you set it high again in the second delay, switch from PORTB |= (1 &lt;&lt; PB2); to PORTB &amp;= ~(1 &lt;&lt; PB2); in one of the delays