arduino                
            Entradas analógicas
        
        
            
    Buscar..
Sintaxis
-  
analogRead(pin)// Leer desde el pin dado. 
Observaciones
Serial.println(val)
 Para obtener ayuda con la comunicación en serie, consulte: Comunicación en serie
Imprima un valor analógico
int val = 0;    // variable used to store the value
                // coming from the sensor
void setup() {
  Serial.begin(9600); //Begin serializer to print out value
  // Note: Analogue pins are
  // automatically set as inputs
}
void loop() {
  val = analogRead(0); // read the value from
                       // the sensor connected to A0.
  Serial.println(val); //Prints the value coming in from the analog sensor
 
  delay(10); // stop the program for
             // some time
}
        Obtener voltaje de pin analógico
Las clavijas analógicas se pueden usar para leer voltajes, lo que es útil para monitorear la batería o interactuar con dispositivos analógicos. Por defecto, el pin AREF será el mismo que el voltaje de operación del arduino, pero puede establecerse en otros valores externamente. Si el voltaje a leer es mayor que el voltaje de entrada, se necesitará un desviador potencial para disminuir el voltaje analógico.
#define analogPin 14    //A0 (uno)
#define AREFValue 5        //Standard for 5V Arduinos
#define ADCResolution 1023    //Standard for a 10bit ADC
int ADCValue = 0;
float voltage = 0;
void setup()
{
    Serial.begin(9600);
}
void loop() 
{
    readADC();
    Serial.print(voltage); Serial.println("V");
}
void readADC()
{
    ADCValue = analogRead(analogPin);
    float = ( ( (float)ADCValue/ADCRange ) * AREFValue );    //Convert the ADC value to a float, devide by the ADC resolution and multiply by the AREF voltage
}
    
    
    
    
    Modified text is an extract of the original Stack Overflow Documentation
        Licenciado bajo CC BY-SA 3.0
        No afiliado a Stack Overflow