Analog input and Serial Output(See output on serial monitor)


  • Arduino uno has 10 bit ADC(Analog to Digital converter).(Gives 0 to 1023 values as output.)
  • 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). 
  • Resolution can be calculated as maximum 10 bit value divide by input voltage (example. for 5 volts input resolution will be [5volts/1024 units] i.e .0049volts/unit.).
  • NOTE:-The input range and resolution can be changed using analogReference().
  • Syntax:- analogRead(pin);
  • Returns int(0 to 1023)
    
  • Example Code
The code reads the voltage on analog Pin and displays it.
int analogPin = 3;     // potentiometer wiper (middle terminal) connected to analog pin 3
                       // outside leads to ground and +5V
int val = 0;           // variable to store the value read

void setup()
{
  Serial.begin(9600);              //  setup serial
}

void loop()
{
  val = analogRead(analogPin);     // read the input pin
  Serial.println(val);             // debug value
}


Comments

Popular posts from this blog

Analog input Analog output of arduino

Arduino basic:How to get sub string from a string in arduino