Suche…


Syntax

  • analogRead(pin) // Vom angegebenen Pin lesen.

Bemerkungen

Serial.println(val)

Hilfe zur seriellen Kommunikation finden Sie unter: Serielle Kommunikation

Drucken Sie einen analogen Wert aus

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
}

Spannung vom analogen Pin abrufen

Analoge Pins können zum Lesen von Spannungen verwendet werden, was für die Batterieüberwachung oder das Anschließen von analogen Geräten nützlich ist. Der AREF-Pin entspricht standardmäßig der Betriebsspannung des Arduino, kann aber extern auf andere Werte eingestellt werden. Wenn die zu lesende Spannung größer als die Eingangsspannung ist, ist ein Potentialteiler erforderlich, um die Analogspannung zu senken.

#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
Lizenziert unter CC BY-SA 3.0
Nicht angeschlossen an Stack Overflow