> For the complete documentation index, see [llms.txt](https://monasheng.gitbook.io/zerotohero/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://monasheng.gitbook.io/zerotohero/arduino-zero-to-hero/module-capstone-project/sensor-tasks.md).

# Sensor Tasks

Having wired and powered up the Arduino, you will now work to integrate the sensors present on the *Zero-to-Hero Demo Board* (a push button and a Potentiometer/Voltage Divider) with your MCU. Complete these steps in order before attempting the [External LED Tasks](/zerotohero/arduino-zero-to-hero/module-capstone-project/external-led-tasks.md).

<figure><img src="/files/cJEWsKolC6eIQ8ULD2C0" alt=""><figcaption><p>Left: the Normally-Open push-button provided on the demo board. Right: the Potentiometer provided on the demo board. In both cases, the contacts of these sensors are broken out to pin-headers as shown by the silk screen printed on the board.</p></figcaption></figure>

## Task 5 - Wire-up the Push Button

* [x] Using jumper wires, connect the push button on the demo board to suitable pins on your Arduino, assuming:

1. You will measure the button state, and,
2. that you will utilise a *built-in pull-up resistor* to provide an input voltage to the button.

{% hint style="info" %}
:man\_mage: **Hint:**  Revisit [Floating Voltages and Pull-Up/Pull-Down Resistors](/zerotohero/arduino-zero-to-hero/core-skills/input-output-pins/floating-voltages-and-pull-up-pull-down-resistors.md) if you are unsure how to wire a button to use a built-in pull-up.
{% endhint %}

{% hint style="danger" %}
:zap: **Warning:** DO NOT connect one side of the button to constant $$5;\text{V}$$ and the other to`GND`, or you will create a short circuit when it is pressed, **potentially killing the demo board, your Arduino, and your computer!**
{% endhint %}

## Task 6 - Measure the Push Button

* [x] Open a new Arduino Sketch.
* [x] Write a simple program to configure your selected pin and enable the built-in pull-up.
  * [x] Verify and Flash this code using the IDE.
* [x] Validate that your connections are correct by measuring the pin voltage with a multimeter, *using the supplied measurement pads* on the demo board.

{% hint style="info" %}
:man\_mage: **Hint:**  If you have wired the circuit and configured your pin correctly, you should observe a clear change in voltage when the button is pressed.
{% endhint %}

## Task 7 - Sense and Report the Push Button

* [x] Modify your sketch to read the state of the push button using your Arduino.
* [x] Report the button state via the Serial Monitor at a regular interval - e.g. $$5;\text{Hz}$$.
  * [x] Do not use the `delay()` function.&#x20;

{% hint style="info" %}
:man\_mage: **Hint:**  If you do not remember how to take actions on an interval on your Arduino, revisit the [Timers](/zerotohero/arduino-zero-to-hero/core-skills/timers.md).
{% endhint %}

## Task 8 - Wire-up the Potentiometer

* [x] Using jumper wires, connect the potentiometer on the demo board to suitable pins on your Arduino. You should make this connection assuming you are going to measure the (analog) potentiometer output voltage.

{% hint style="info" %}
:man\_mage: **Hint:** the potentiometer works the same way [Voltage Dividers](/zerotohero/arduino-zero-to-hero/core-skills/input-output-pins/voltage-dividers.md) do - scaling the input voltage to the output depending on the position of the knob.

&#x20;Revisit [analogRead()](/zerotohero/arduino-zero-to-hero/core-skills/input-output-pins/analog-pins/analogread.md) if you are unsure how to wire a potentiometer.
{% endhint %}

## Task 9 - Measure the Potentiometer

* [x] Validate that your connections are correct by measuring the potentiometer output voltage with a multimeter, *using the supplied measurement pads on the demo board*.

{% hint style="info" %}
:man\_mage: **Hint:**  If you have wired the circuit correctly, you should observe a clear variation in output voltage as the potentiometer knob is turned.
{% endhint %}

## Task 10 - Sense and Report the Potentiometer

* [x] Modify your code to also initialise a suitable pin for, and read the output voltage of the potentiometer.
* [x] Report the knob turn percentage via the Serial monitor at a regular interval - e.g. $$5;\text{Hz}$$.
  * [x] Do not use the `delay()` function.&#x20;
  * [x] Your reading should report `0%` on the monitor when the knob is turned fully-anticlockwise, and `100%` when it is turned fully-clockwise.
* [x] `File -> Save As...` your sketch for later use.
