The sentence that uses the literary technique onomatopoeia is:
He hit the nail with the hammer—whack, whack, whack.
Onomatopoeia refers to words that imitate the natural sound associated with the objects or actions they refer to, and "whack" represents the sound of the hammer hitting the nail.