Good answer, as far as it goes.
Each ATM is connected to the bank, either directly (say this is an ATM at your bank) or indirectly through an intermediary called as “switch” (say this is an ATM at somebody else’s bank or a supermarket).
Only information flows through this connection, not the bills!
The information transmitted typically includes your account number, the amount, and your PIN. The PIN is encrypted before sending it, so that even somebody with a wiretap would not be able to determine what your PIN is.