*******
Please visit https://proteshea.com/analog-input-channels-with-arduino-uno/ for a complete list of materials needed for this project.
*******
IntroductionIf 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.
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.
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.
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.
SoftwareOnce 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.
Comments