Lesson 4 - Potentiometer

Introduction

In the last experiment, you have learned how to control an LED by PWM programming, which is interesting though sounds slightly abstract. In this lesson, you will learn how to change the luminance of an LED by potentiometer.


Components

- 1 * SunFounder Uno board

- 1 * Breadboard

- Jumper wires

- 1 * Resistor (220Ω)

- 1 * LED

- 1 * Potentiometer

- 1 * USB cable

Principle

Analog V.S. Digital

A linear potentiometer is an analog electronic component. So what’s the difference between an analog value and a digital one? Simply put, digital means on/off, high/low level with just two states, i.e. either 0 or 1. But the data state of analog signals is linear, for example, from 1 to 1000; the signal value changes over time instead of indicating an exact number. Analog signals include those of light intensity, humidity, temperature, and so on.

In this experiment, a potentiometer, or pot, is used to change the current in the circuit so the luminance of the LED will change accordingly. And since the pot is an analog device, the current change is smooth, thus the LED will gradually get brighter or dimmer instead of going through an obvious stepwise process.

What we mean by PWM here is the digitalization of analog signals, which is a process of approaching analog signals. Since the potentiometer inputs analog signals, it should be connected to analog ports, i.e. A0-A5, instead of digital ports.


Experimental Procedures

Step 1: Build the circuit

As you see, the potentiometer is connected to pin A0 of the SunFounder Uno board, which can measure voltages from 0V to 5V. The corresponding returned value is from 0 to 1024. The measurement accuracy for voltage change is relatively high.


Step 2: Program.

Use the code in the document below and copy/paste it into the Arduino Program on your computer:

Arduino Code Lesson 4

Step 3: Compile the code

Step 4: Upload the sketch to the Arduino Uno board


Rotate the shaft of the potentiometer and you should see the luminance of the LED change.