| 1 |
/* |
| 2 |
AnalogReadSerial |
| 3 |
|
| 4 |
Reads an analog input on pin 0, prints the result to the Serial Monitor. |
| 5 |
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu). |
| 6 |
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. |
| 7 |
|
| 8 |
This example code is in the public domain. |
| 9 |
|
| 10 |
https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogReadSerial |
| 11 |
*/ |
| 12 |
|
| 13 |
// the setup routine runs once when you press reset: |
| 14 |
void setup() { |
| 15 |
// initialize serial communication at 9600 bits per second: |
| 16 |
Serial.begin(9600); |
| 17 |
} |
| 18 |
|
| 19 |
// the loop routine runs over and over again forever: |
| 20 |
void loop() { |
| 21 |
// read the input on analog pin 0: |
| 22 |
int sensorValue = analogRead(A0); |
| 23 |
// print out the value you read: |
| 24 |
Serial.println(sensorValue); |
| 25 |
delay(1); // delay in between reads for stability |
| 26 |
} |