1.. zephyr:code-sample:: thermometer 2 :name: Thermometer 3 :relevant-api: sensor_interface 4 5 Get ambient temperature data from a temperature sensor and get alerts when temperature drifts 6 above a threshold. (polling & trigger mode). 7 8Overview 9******** 10 11This sample application periodically measures the ambient temperature 12at 1Hz. The result is written to the console. 13 14Wiring 15******* 16 17VDD pin should be connected to 2.3V to 5.5V 18GND pin connected to 0V 19VOUT pin connected to the ADC input pin. 20 21.. _`MCP970X Sensor`: http://ww1.microchip.com/downloads/en/devicedoc/20001942g.pdf 22 23An overlay is provided for the nrf52840dk/nrf52840 board with the 24sensor connected to pin AIN7. 25 26Building and Running 27******************** 28 29To build for the nrf52840dk/nrf52840 board use: 30 31.. zephyr-app-commands:: 32 :zephyr-app: samples/sensor/thermometer 33 :board: nrf52840dk/nrf52840 34 :goals: build flash 35 :compact: 36 37 38To build for other boards and ambient temperature sensors, enable the sensor 39node that supports ``SENSOR_CHAN_AMBIENT_TEMP`` and use an overlay to create an 40alias named ``ambient-temp0`` to link to the node. See the overlay used for the 41``nrf52840dk/nrf52840`` board within this sample: 42``boards/nrf52840dk_nrf52840.overlay`` 43 44 45Temperature Alert 46================= 47 48If the attached sensor supports alerts when the temperature drifts above or 49below a threshold, the sample will enable the sensor's trigger functionality. 50This will require the sensor's TRIGGER KConfig setting to be enabled. An 51example of this setup is provided for the ``frdm_k22f`` board, using 52``boards/frdm_k22f.conf``. 53 54Sample Output 55============= 56 57.. code-block:: console 58 59 *** Booting Zephyr OS build zephyr-v3.3.0-2354-gb4f4bd1f1c22 *** 60 Thermometer Example (arm) 61 Temperature device is 0x525c, name is tcn75a@48 62 Set temperature lower limit to 25.5°C 63 Set temperature upper limit to 26.5°C 64 Enabled sensor threshold triggers 65 Temperature is 25.0°C 66 Temperature is 25.0°C 67 Temperature is 25.0°C 68 Temperature is 25.0°C 69 Temperature is 25.5°C 70 Temperature above threshold: 26.5°C 71 Temperature is 26.5°C 72