Tutorial 03 : Analog Read Serial






This example shows you how to read analog input from the physical world using a potentiometer. A potentiometer is a simple mechanical device that provides a varying amount of resistance when its shaft is turned. By passing voltage through a potentiometer and into an analog input on your Arduino, it is possible to measure the amount of resistance produced by a potentiometer (or pot for short) as an analog value. In this example you will monitor the state of your potentiometer after establishing serial communication between your Arduino and your computer.


https://www.arduino.cc/en/uploads/Tutorial/AnalogReadSerial_BB.png 






/*
  AnalogReadSerial
  Reads an analog input on pin 0, prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
   */


// the setup routine runs once when you press reset:
void setup() {
 
// initialize serial communication at 9600 bits per second:
 
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
 
// read the input on analog pin 0:
 
int sensorValue = analogRead(A0);
 
// print out the value you read:
 
Serial.println(sensorValue);
 
delay(1);        // delay in between reads for stability
}
  }




Download this sketch : 


Enregistrer un commentaire

0 Commentaires