How do I convert 9 V DC to 5 V?

I would use a 7805 to get 5 volts simple circuit. Here is a image: 7805

idea: please make sure that caps are ceramic/polymer caps. The ceramic caps only have low ESR value. specially the right hand one.


Since you want to power from a 9V battery we have to look out for possible current losses. While a three-legger like LM7805 may be an obvious choice, this regulator has a ground current of 8mA maximum. An LDO (low drop-out) regulator typically needs far less, e.g. the ground current of an LP2981 is only 800\$\mu\$A maximum. That's only 10%!
LDOs are as easy to use as an LM7805. The output capacitor is a bit larger, though, important for stability.

edit
Johan wanted an example:
alt text

If not used, the ON/OFF input must be tied to \$V_{IN}\$. The output capacitor value of 3.3\$\mu\$F is the minimum required for stability. "More capacitance provides superior dynamic performance and additional stability margin" (dixit NS)

edit 2
You can even save more power, but it's probably not worthwhile; your motors may consume a lot more than the LDO's 800\$\mu\$A.
Anyway, there are LDOs with < 1\$\mu\$A ground current, like the Seiko S-812C50. Input voltage up to 16V, output voltage is selectable from 2V to 6V in 100mV increments. Output current is limited, however, to 50-75mA.


I might consider just providing the ATmega328 unregulated power unless you have something that actually requires it on the board. 2-3 AA cells should remain within 1.8 to 5.5 V over their life.

A schottky might be prudent if you insert the batteries the wrong way (probably will need 3 cells then), and you could add a TVS if you want to be even safer.