> For the complete documentation index, see [llms.txt](https://learn.breadstick.ca/breadstick/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learn.breadstick.ca/breadstick/breadsticks/raspberry-breadstick/code-examples/adc.md).

# ADC

{% tabs %}
{% tab title="1" %}

<figure><img src="/files/bnw6m8Quu13mXFQW7ScR" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="2" %}

<figure><img src="/files/4uNxUFBqNzeCbW2iFI6f" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="3" %}

<figure><img src="/files/GdDyNlJ64uARGvYYl48K" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="4" %}

<figure><img src="/files/PHqGWjTwyVP9OdUZXr6f" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="5" %}

<figure><img src="/files/zb7ZVZepXb7yv40BRl55" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="6" %}

<figure><img src="/files/giUyLQWFguL5Db8OLnsL" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="7" %}

<figure><img src="/files/1uAHFGCioG29M47kYfN5" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

## ADC Pins - A1, A2, A18, A17

While all ADC pins are digital pins, not all digital pins are ADC pins.&#x20;

## Code

```python
"""
ADC Demo Code
Breadstick Innovations
April 26, 2024
https://learn.breadstick.ca/breadstick/breadsticks/raspberry-breadstick/code-examples/adc

ADC converts 0-3.3V to 16-bit integer
RP2040 has a 12-bit ADC but CircuitPython converts it to a 16-bit result.
2^16 = 65536 values
0 is one of those values,
so the range is 0-65535.
3.3V/65535 steps = 50uV/step
You won't actually measure at 50uV accuracy, closer to 1mV accuracy.
"""

from board import *
from pwmio import PWMOut
from analogio import AnalogIn
from time import sleep
from adafruit_dotstar import DotStar


def convert_voltage(ADC_value):
    return 3.3 / 65535 * ADC_value


def convert_range(ADC_value, from_max, to_max):
    return int(ADC_value / from_max * to_max)
    

pot_1 = AnalogIn(A1)
pot_18 = AnalogIn(A18)

led_5 = PWMOut(D5, frequency=500, duty_cycle=0)

leds = DotStar(DOTSTAR_CLOCK, DOTSTAR_DATA, 24, brightness=0.02, auto_write=False)

RED = (255, 0, 0)
ORANGE = (255, 75, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
OFF = (0, 0, 0)

leds.fill(OFF)
leds.show()

while True:
    ADC_1 = pot_1.value
    ADC_18 = pot_18.value

    led_5.duty_cycle = ADC_1

    voltage_1 = convert_voltage(ADC_1)
    voltage_18 = convert_voltage(ADC_18)
    print((voltage_1, voltage_18))

    bar_graph = convert_range(ADC_18, 65535, 25)
    leds.fill(OFF)
    for i in range(bar_graph):
        leds[i] = ORANGE
    leds.show()

    sleep(0.04)

```
