How does flagella work?

Flagella plays the dual role of locomotion and sense organ, being sensitive to chemicals and temperatures outside the cell.