Project tutorial

• 4,232 views
• 1 respect

## Apps and online services

 Arduino IDE

*******

Please visit https://proteshea.com/analog-input-channels-with-arduino-uno/ for a complete list of materials needed for this project.

*******

### Introduction

If you followed along with our previous projects, you should have a good understanding of how to use the digital I/O for control, communication, and reading inputs on the Arduino Uno Rev3 (Uno). In this project, we’re going to show you how to use the analog input channels. The number of channels varies per board, but the Uno has six channels. You will learn how to read each channel and display the value into an organized table on the Serial Monitor, as shown below.

### Potentiometer

The potentiometer is a component that consists of 3 pins and allows you to quickly vary the internal resistance. By varying the resistance, the output voltage is changed between 0V and the maximum voltage that the potentiometer is tied to. For example, if pin 1 is tied to +5Vdc and pin 3 is tied to 0V (GND), the output voltage on pin 2 will vary between 0V and +5V. The potentiometer acts as a voltage divider circuit, as shown below.

On each analog input channel, there is a 10-bit analog-to-digital (ADC) converter. Being that it has a 10-bit resolution, we can acquire samples ranging from 0 to 1023 (2^10 – 1). If your voltage range is from 0-5V, 0V will be mapped to 0 and 5V will be mapped to 1023. To figure out what each voltage between 0V and 5V will get mapped to, we can use the ratio below.

Let’s say we acquire a voltage sample of 1V. We know n, the max input voltage, and the voltage sample, so we can solve for the ADC value, as shown below. Since the solution is not a whole number, the ADC will round down to the nearest whole number which is 204.

### Wiring the Circuit

Place six 10kΩ potentiometers onto the breadboard. Wire pin 3 of each potentiometer to the positive voltage rail and pin 1 to the negative rail of the breadboard. Insert a male jumper into each node that pin 2 of the potentiometers are connected to. Then, wire the other end of each jumper to Analog Inputs 0-5. A circuit schematic is shown below.

### FuelCan Wiring

If you haven’t mounted the Uno onto the prototyping area of the FuelCan, go ahead and do that. I placed the breadboard in the bottom storage compartment to limit the length of the jumper wires. We need to supply +5V and GND to the power and ground rails on the breadboard. Use the provided banana jack to test-lead clip cables to do so. You will need two male header pins to mount the test-lead clips on the breadboard side. Plug the Type A side of the USB cable into USB1 receptacle and the Type B side into the Uno’s receptacle. Power up the FuelCan with the AC-DC power adapter.

### Software

Once the wiring is complete and the FuelCan is powered up, we can now load the sketch onto the Uno. The sketch is below. It sets up the serial terminal between the Uno and the host. The analog values are read from each analog input and the values are sent to the host to display them on the Serial Monitor. Rotate each potentiometer clockwise and counterclockwise to watch the values change from 0 to 1023.

## Code

```//Read the six 10-bit analog values from each potentiometer
//and display them in an organized table on the Serial Monitor

//variable declarations
int A0value = 0;
int A1value = 0;
int A2value = 0;
int A3value = 0;
int A4value = 0;
int A5value = 0;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.print("\n\n");
Serial.print("A0\tA1\tA2\tA3\tA4\tA5\n\n");

}

void loop() {
// put your main code here, to run repeatedly:

Serial.print(A0value);
Serial.print('\t');
Serial.print(A1value);
Serial.print('\t');
Serial.print(A2value);
Serial.print('\t');
Serial.print(A3value);
Serial.print('\t');
Serial.print(A4value);
Serial.print('\t');
Serial.print(A5value);
Serial.print('\n');
delay(3000);

}
```

## Schematics

• 10 projects
• 26 followers

#### Published on

June 1, 2019
See similar projects
you might like

#### Similar projects you might like

• 11,999 views
• 1 comment
• 16 respects

Project tutorial by Giovanni Carrera

• 11,518 views
• 10 respects

by APTINEX

• 2,015 views
• 1 respect

#### Arduino Analog Panel Meter Clock

Project tutorial by Mirko Pavleski

• 13,639 views
• 69 respects

• 11,017 views