/* Analog Input Demonstrates analog input by reading an analog sensor on analog pin 0 and turning on and off a light emitting diode(LED) connected to digital pin 13. The amount of time the LED will be on and off depends on the value obtained by analogRead(). The circuit: * Potentiometer attached to analog input 0 * center pin of the potentiometer to the analog pin * one side pin (either one) to ground * the other side pin to +5V * LED anode (long leg) attached to digital output 13 * LED cathode (short leg) attached to ground Created by David Cuartielles modified 30 Aug 2011 by Tom Igoe modified 13 Dec 2016 by JStolfi This example code is in the public domain. http://arduino.cc/en/Tutorial/AnalogInput */ int sensorPin = A0; // select the input pin for the potentiometer int ledPin = 13; // select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor int prevValue = -1; // sensor value read on previous pass of the loop void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); // declare the ledPin as an OUTPUT: pinMode(ledPin, OUTPUT); } void loop() { // read the value from the sensor: sensorValue = analogRead(sensorPin); if (sensorValue != prevValue) { // print out the value you read: Serial.println(sensorValue); // save the value for the next pass: prevValue = sensorValue; } digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level) delay(sensorValue); // wait for milliseconds: digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW delay(sensorValue); // wait for for milliseconds: }