This is a fun guide to how to say hi to anyone you pass on the sidewalk in your neighborhood.
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
I've found that the most common reason I don't say hi or smile at people I pass on the street in my neighborhood is that I'm staring at the ground or otherwise consumed with my own thoughts, and so I'm not aware of other people. I am mostly likely to get lost in thought or routine to and from the train to work.
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.