In general, the techniques of this disclosure are directed to communication between an implantable medical device (IMD) and an external device. In some examples, the external device transmits a signal that includes a communication key. One or more sensors of the IMD sense the signal that includes the communication key, and the IMD uses the communication key for coding the communication between the IMD and the external device. The one or more sensors that sensed the signal may also sense one or more patient characteristics.