Arduino analog input-analogread ()

Source: Internet
Author: User
Description

Reads the value from the specified analog pin. the Arduino board contains a 6 channel (8 channels on the mini and nano, 16 on the mega), 10-bit analog to digital converter. this means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. this yields a resolution between readings of: 5 V/1024 units or ,. 0049 Volts (4.9 mV) per unit. the input range and resolution can be changed using analogreference ().

 

It takes about 100 microseconds (0.0001 S) to read an analog input, so the maximum reading rate is about 10,000 times a second.

Read the value from the specified analog pin. The Arduino motherboard has 6 channels (8 mini and nano, 16 mega), and 10-bit AD (Analog-to-analog) converters. This means that the input voltage 0-5 V corresponds to an integer 0. This means that the read precision is 5 V/1024 units, which is about 0.049 V (4.9 mV) for each unit ). The input range and progress can be modified through analogreference.


The read duration of a simulated input is 100 microseconds (0.0001 seconds), so the maximum read speed is 10,000 times per second.

 

Syntax

Analogread (PIN)

 

Parameters

Pin: the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the mini and nano, 0 to 15 on the mega)

Pin: Read analog input pin number (most motherboard numbers are 0-5, Mini and nano are 0-7, mega is 0-15)

 

Returns Return Value

INT (0 to 1023)

Integer int (0 to 1023)

 

Note

If the analog input pin is not connected to anything, the value returned by analogread () will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc .).

If the analog input pin is not connected to any place, the returned value of analogread () also fluctuates due to some factors (for example, other analog input, your hands are too close to the motherboard)

 

Example
 int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3                       // outside leads to ground and +5Vint val = 0;           // variable to store the value readvoid setup(){  Serial.begin(9600);          //  setup serial}void loop(){  val = analogRead(analogPin);    // read the input pin  Serial.println(val);             // debug value}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.