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.