Set the pan on a medium flame and add just enough unroasted beans to cover the bottom. Cover fully with a lid—ideally a clear one, so you can see color changes without removing the cover and lowering temperature at a crucial moment. Vigilance is critical: don't just set it and forget it. To ensure even roasting, keep the coffee moving by gently, continuously shaking the pan.
When you start to hear crackling, open the lid and let the coffee's outer silvery skin escape [Corby's note—here's where the chaff blowback starts]; blow on the coffee to help it along. First, be sure to raise the flame to high to maintain temperature. Replace the lid and return the flame to medium once the skin dissipates.
Maintain a close watch on your beans' changing color, tilting the clear lid occasionally to let smoke escape. Keep the heat on until an almond-like hue paints the bean for light roast, milk chocolate for medium roast, and dark chocolate for dark roast.
Finally, the critical last step: cooling. Forget this step, and your medium roast can go dark in just minutes. The moment beans turn the color you want, turn off the flame and immediately transfer them to an uncovered metal container, or one that is covered but not airtight, so gas can escape. If it's not summertime, place the container outside or in front of an open window to properly cool. In warmer conditions, place in the fridge for a few minutes and then let stand at room temperature. Wait a couple of days (I'll explain why in just a moment), grind and enjoy.
I've never tried it myself, but people tell me about using their hot air popcorn poppers as impromptu coffee roasters. As with the pan method, keep a close eye on color, be sure to remove the skins and cool promptly. Side benefit: your next batch of popcorn might just carry notes from your favorite morning cup. (Hold the butter.) [Corby's note: I DID use a popcorn popper, on many occasions, and finally gave up, because the flaky dried chaff, something of the texture of dried bonito flakes, blows and settles everywhere, and you tend to find it months later in crevices you didn't know existed. But at least they don't go rancid, and they can remind you of the home roasting technique you worked to get right.]
If your pan-based experiments produce encouraging results, and if you have the room and a few dollars to spare, you might think seriously about investing in a home roasting machine. You'll appreciate the consistent results and greater control. Machine types and costs vary widely, but generally speaking, quality machines can be had starting at a couple of hundred dollars.
You can find quality unroasted (commonly called "green") coffee online, but I like to see and smell before buying. Avoid beans with a woody aroma—they're too old—or ones with fruity aromas, signaling the presence of fermented beans that will ruin what pours in your cup.