Home > Projects > Analog Input using Arduino

Analog Input using Arduino

Summary of Analog Input using Arduino


This article explains how to connect a potentiometer to an Arduino board to control the blinking rate of a built-in LED. The circuit links the potentiometer's outer pins to ground and 5 volts, with the middle pin connected to analog input 0. The provided code reads the analog value (0–1023) via the ADC and adjusts the LED's blink speed based on the knob's position.

Parts used in the Potentiometer Blink Control Project:

  • Arduino Board
  • Potentiometer
  • Built-in LED on pin 13

A potentiometer is a simple knob that provides a variable resistance, which you can read into the Arduino board as an analog value. In this example, you’ll connect a poterntiometer to one of the Arduino’s analog inputs to control the rate at which the built-in LED on pin 13 blinks.

Circuit

Arduino Analog Input

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Connect three wires to the Arduino board. The first goes to ground from one of the outer pins of the potentiometer. The second goes from 5 volts to the other outer pin of the potentiometer. The third goes from analog input 0 to the middle pin of the potentiometer.

For this example, it is possible to use the Arduino board’s built in LED attached to pin 13. To use an additional LED, attach its longer leg (the positive leg, or anode), to digital pin 13, and it’s shorter leg (the negative leg, or cathode) to the ground (gnd) pin next to pin 13. Because of the low amount of current coming from digital pin 13, it is not necessary to use a current limiting resistor in this particular case.

Schematic

Arduino Analog Input schematic

Code

In the beginning of this program, the variable sensorPin is set to to analog pin 0, where your potentiometer is attached, and ledPin is set to digital pin 13. You’ll also create another variable, sensorValue i to store the values read from your sensor.

The analogRead() command converts the input voltage range, 0 to 5 volts, to a digital value between 0 and 1023. This is done by a circuit inside the Arduino called an analog-to-digital converter or ADC.

By turning the shaft of the potentiometer, you change the amount of resistance on either side of the center pin (or wiper) of the potentiometer. This changes the relative resistances between the center pin and the two outside pins, giving you a different voltage at the analog input. When the shaft is turned all the way in one direction, there is no resistance between the center pin and the pin connected to ground.

Major Components in Project

Hardware Required

  • Arduino Board
  • Potentiometer
  • built-in LED on pin 13

For more detail: Analog Input using Arduino

Quick Solutions to Questions related to Potentiometer Blink Control Project:

  • How do you connect the potentiometer to the Arduino?
    Connect one outer pin to ground, the other to 5 volts, and the middle pin to analog input 0.
  • Can you use an additional LED instead of the built-in one?
    Yes, attach the longer leg to digital pin 13 and the shorter leg to the ground pin next to pin 13.
  • What voltage range does the analogRead command convert?
    The analogRead command converts the input voltage range of 0 to 5 volts into a digital value between 0 and 1023.
  • Does this project require a current limiting resistor?
    No, it is not necessary to use a current limiting resistor because of the low amount of current coming from digital pin 13.
  • What component inside the Arduino performs the conversion?
    An analog-to-digital converter or ADC inside the circuit performs the conversion.
  • What happens when the potentiometer shaft is turned all the way in one direction?
    There is no resistance between the center pin and the pin connected to ground.
  • Which variable stores the values read from the sensor?
    The variable sensorValue is created to store the values read from your sensor.
  • How does turning the shaft affect the circuit?
    Turning the shaft changes the relative resistances between the center pin and the two outside pins, resulting in a different voltage at the analog input.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top