Вы находитесь на странице: 1из 3

PIC Potentiometer Circuit

In this circuit, we will show how to connect a potentiometer to a PIC microcontroller.


The potentiometer serves as an analog input to the microcontroller.
Being that a potentiometer can have any value from 0 to its rated resistance, it can have any voltage
value from 0V up to the full voltage supplied to it. Therefore, with a potentiometer, we can input any
voltage from 0V to full voltage on the positive rail. So it's very dynamic. A digital input, on the other hand,
can input only 0V or full voltage, with no value in between.
Analog input, then, such as from a potentiometer is more dynamic and can take on many more values.
A potentiometer is a very simple device to connect to a microcontroller.

PIC18F1220 Potentiometer Circuit Schematic


The circuit schematic for the potentiometer circuit we will build with a PIC18F1220 chip is shown below.

The breadboard schematic of the above circuit is shown below.

We establish power to the chip by connecting pin 14 to 5V through a capacitor that connects on the other
end to ground. We connect pin 5 to ground.
The potentiometer has 3 terminals. There are 2 end terminals and a wiper terminal. One side of the end
terminals connects to +5V and the other end connects to ground. The wiper terminal, whose resistance
adjusts, connects to analog pin ANO, which is pin 1 of the microcontroller.
The PIC18F1220 has 6 analog pins, AN0 to AN5. These are pins RA0, RA1, RA2, RA3, RBO, RB1, and
RB4, which are pins 1, 2, 6, 7, 8, 9 and 10, respectively. Technically, we could connect the potentiometer
to any of these pins to allow for analog input from the potentiometer. We would just need to set the pins to
analog input in the code, which we will show how to do below.
In this circuit, we will also set the pin which is the LED is attached to as analog. This way, we make the
LED an analog output. This way, the potentiometer can control the dimness of the LED, just like a dimmer
switch. If the LED pin was a digital pin, it could be only fully on or fully off, with no intermediate states.
However, as an analog pin, it can accept any voltage between 0 and 5V. So it can really be any
brightness. This is one of the dynamic abilities of having analog input.
So the potentiometer connects to AN0 (RA0), while the LED connects to AN6 (RB4).

Вам также может понравиться