Loop certain number of times then do action

Pullup resistors are included for free with the purchase of an Arduino:

https://docs.arduino.cc/built-in-examples/digital/InputPullupSerial/