When can I make opportunity attacks?
Generally, only willingly moving out of an enemy's reach provokes opportunity attacks
From the Basic Rules, p74:
You can make an opportunity attack when a hostile creature that you can see moves out of your reach. To make the opportunity attack, you use your reaction to make one melee attack against the provoking creature. The attack interrupts the provoking creature’s movement, occurring right before the creature leaves your reach.
No other situations are listed. Note that unlike previous editions, only leaving an enemy's reach provokes; moving from one position in their reach to another does not provoke. Being forced out of a creature's reach also doesn't provoke, as when pushed or falling.
Ranged attacks do not provoke; from the Basic Rules, p73:
Aiming a ranged attack is more difficult when a foe is next to you. When you make a ranged attack with a weapon, a spell, or some other means, you have disadvantage on the attack roll if you are within 5 feet of a hostile creature who can see you and who isn’t incapacitated.
Ranged attacks have disadvantage when in melee, but do not provoke.
Spells do not provoke or suffer any other penalties for being cast in melee (other than those that require a ranged attack, which suffer disadvantage as mentioned above).
Some feats may expand how and when an opportunity attack is triggered. In these cases, the specific wording of the feat will override the general rule.
I'd suggest a brief disclaimer at the end; only Polearm Master and War Caster currently modify opportunity attacks. Polearm Master lets you make one as an enemy enters your reach with certain weapons, while War Caster lets you cast a spell instead of making one. All other Feats technically let you make similar attacks that *aren't* opportunity attacks using your reaction.
This answer would be better if you pointed out that you have to have not already used your reaction during that round/turn. (It is otherwise quite well presented). If you have already used a reaction then you can't make an opportunity attack until the next round/turn.
I'm not so sure about only *willingly* moving. It looks like how the target moves determines whether or not the OA takes place, not willingness. PHB Ch. 9, page 195, Opportunity Attacks: You also don’t provoke an opportunity attack when you teleport or when someone or something *moves you **without** using your movement, action, or reaction*. For example, you don’t provoke an opportunity attack if an explosion hurls you out of a foe’s reach or if gravity causes you to fall past an enemy.
I'd like it if the part about the major change from 3.5/4 to 5 (IE, moving within threat) was changed, since that greatly changes Reach.
I don't want to create a new question and get tagged as a dupe, so I ask for clarity here: given this answer, does any PC at melee range can take opportunity attack when an enemy leave their reach? Or do they need a feat or something like it?
@Zoma Any creature can use the rule from my first quote to make an opportunity attack; they do not need any particular feat, class, or special ability. Some feats and abilities allow creatures to make attacks of opportunity in *other* situations, but they will explicitly describe those situations.