Count the lightning and thunder. If the thunder comes immediately after the lightning, the lightning is too close. If there's are a few seconds... even five or ten, the lightning is farther off and you're probably safe.
BUT, why not just wait for the storm to pass? It's usually just a few...