Reading an Analog Input
/*
* AnalogInput.ino * * Created: 5/5/2015 1:30:42 PM * Author: Gideon */
int led=12; int sensor=A2;
int sensorvalue=0;
void setup() {
/* add setup code here, setup code runs once when the processor starts */ pinMode(led,OUTPUT); pinMode(sensor,INPUT);
}
void loop() {
/* add main program code here, this code starts again each time it ends */ sensorvalue=analogRead(sensor); digitalWrite(led,HIGH); delay(sensorvalue); digitalWrite(led,LOW); delay(sensorvalue);
}
This project illustrates how one can read analog values from a variable resistor to control the rate of blinking of an led.