How to Read in Arduino Analog Input on Processing

Originally published by Mar 31, 2020

This article was translated to English, and was originally published for deviceplus.jp.

Table of Contents

  1. Introduction
  2. Convert analog values to digital values
  3. Analog input with Arduino
  4. Adapt voltage with Volume
  5. Analog input with Volume
  6. Conclusion
  7. Related manufactures

Introduction

With digital input, 5V tin exist read as HIGH and 0V as LOW. You can determine whether a switch is on based on which state it is in. Yet, electricity is not only 5V and 0V, merely various voltages. For instance, one AA battery is 1.5V, and a household outlet is 100V.

Arduino supports analog inputs to read these diverse voltages. Analog inputs enable you to read the state of electronic components that alter gradually. For example, you tin utilise volume to adjust brightness or loudness or a temperature sensor to get the current temperature.

voltage can be read from analog input

This commodity is the last in the series. We will explain analog input using volume.

Convert analog values to digital values

Actual voltage is non an verbal value such as 1V or 5V, merely an irrational number, in which numerical values continue forever after the decimal bespeak, such every bit 5.01342…Five. These values cannot be direct handled by a computer. In electronic circuits, therefore, analog values are converted to digital values using a mechanism chosen Ad converter and then that the value can exist handled by a computer. Arduino also has an Advertizement converter by default, which can read analog voltages and convert them into digital values.

The AD converter divides the target voltage into several equal parts. For Arduino Uno, voltages can exist read in the range of 0-5V. These 0-5V values are divided into 1023 equal parts. The Advert converter converts the analog voltage reading to the nearest equal value. If the voltage is 3V, for example, "614" is the closest value. This value can be sent to Arduino for use.

how the analog value is converted to digital value

Integer values upward to 1023 are used to process the program. All the same, the input value is not a voltage value. If you want to know the voltage value, you lot tin can summate it as follows:
how to calculate the voltage

For instance, if the value from the AD converter is "614", you lot can obtain about 3V by dividing past 1023 and so multiplying by 5.

Analog input with Arduino

With Arduino Uno, y'all tin can use vi pins for digital input, A0 to A5. By connecting electronic components here for the input, you tin can read how much voltage is applied. Withal, pins A4 and A5 are also used for digital advice chosen I2C. Note that these pins cannot be used for analog input when connecting electronic components such equally sensors or displays that utilise I2C digital communication.

pins that support analog input

Adjust voltage with Volume

"Volume" is an electronic part that can be used to adjust the audio volume or lighting brightness. The volume contains terminals moving on the resistive element. The resistance tin can be changed by moving these terminals.

The volume generally has three terminals. The left and right terminals are fastened to both ends of the resistor. The center terminal is designed to move on the resistive element. If you lot move the middle terminal to the right, the resistance between the left and middle terminals increases. Conversely, if y'all move it to the left, the resistance decreases.

how the volume works

In the effigy in a higher place, the resistance element is linear, but in the rotary volume, the internal resistance element is circular. Although the shapes are dissimilar, they basically operate the same way.

The Arduino analog input uses the voltage modify for the input. Since the resistance changes in the book, however, information technology is not possible to read the book modify past connecting it directly to Arduino. Therefore, the resistance change should be converted to a voltage change. Connect the power supply and GND to the left and right terminals of the resistor. The voltage at the center terminal changes depending on the concluding position. Assume that the left terminal is connected to GND, and the right concluding is connected to a ability supply (5V). The voltage increases every bit the center terminal moves to the correct, and it decreases as the terminal moves to the left. The left end is 0V and the right end is 5V, so the value tin be changed within the range of 0 to 5V.

If this center final is continued to the Arduino analog input last, the input can exist changed by moving the book.

how the volume works

Analog input with Book

Now let's try analog input using the book. Gear up the post-obit electronic components.
Volume pod
volume pod

The volume pod contains the resistance value of the range that can be changed. It is good to employ a 10kΩ book for the Arduino input. The volume will be easier to move, if a knob is attached to the rotation axis of the book.

Alligator-clip jumper line
alligator clip jumper line

Useful for attaching a book pod. Pinch the book terminals with the prune-shaped connectors. The linked product is available as a set of two crimson lines and two black lines.

When you have prepared the components, connect them as shown in the figure beneath. Since the volume pod cannot exist plugged into the breadboard, use an alligator-clip jumper line to connect it directly to Arduino. Make sure that the metallic part of the alligator prune does not bear upon the adjacent clip part.

connecting volume pod to arduino

Write the following program:

To cheque the land where the analog input pivot is connected, specify the target pin in "analogRead()" (line xi). Then, input the voltage of the pin with the value of 0 to 1023. If you want to know the voltage, it is calculated and converted to voltage equally in line 13.

Write the plan to Arduino and brandish the serial monitor.
The value digitized by the AD converter is displayed later "Value:", and the value calculated and converted into voltage is displayed later "Volt:". Y'all can meet that the value changes as the book is rotated.

converted value and volt

Conclusion

In this serial, we introduced the usage underlying Arduino. Try operating a variety of electronic components and creating programs based on the content explained in this series. Thank you very much for post-obit this half-year series to the terminate!

Explore the rest of this serial to get to know about the basics of Arduino:

  • The Basics of Arduino: Adjusting LED Brightness
  • The Nuts of Arduino: Controlling the Motor
  • The Basics of Arduino: Reading Switch States
  • The Nuts of Arduino: Control LED Lighting with Digital Output
  • The Basics of Arduino: Prepping the Arduino

Bank check us out on Social Media

How to Read in Arduino Analog Input on Processing

Source: https://www.deviceplus.com/arduino/the-basics-of-arduino-reading-voltage/

0 Response to "How to Read in Arduino Analog Input on Processing"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel