I never really learned the habit of doing this until very recently and found that it actually took some thought and experimentation to do it well. My fiancee and I reenacted a typical scenario you might get on the street. Saying hi to a person of the sex to which you're inclined can be especially fraught, so we took the liberty of adding a few extra steps on what not to do.
Step 1: Be aware of your surroundings
So the first step is simply remembering to look up and around. Stop staring at the sidewalk. When you do that, you'll become aware of the people you'll soon be passing. The other part of this step is to generally direct your field of vision in the direction of people passing.
Step 2: Make eye contact and smile
We don't recommend that you wave unless the person is sitting on their porch or gardening or something else far away. You'll look awkward and dorky.
Step 3: Walk away and don't turn back
Step 4: Remember not to do any of the following...
Glare at someone to make sure that they make eye contact.
Say hi before you're in comfortable eye contact range.
Get in someone's face.
Turn back and profess undying love.