/* 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 center pin of the potentiometer to the analog input 0 one side pin (either one) to ground the other side pin to +3V - LED anode (long leg) attached to digital output 13 through 220 ohm resistor cathode (short leg) attached to ground */ int sensorPin = 27; // select the input pin for the potentiometer int ledPin = 29; // select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor int sensorValue2 = 0; // variable to store the value coming from the sensor void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT pinMode(sensorPin, INPUT); //declare the sensorPin as an INPUT } void loop() { // read the value from the sensor: sensorValue = analogRead(sensorPin); // turn the ledPin on digitalWrite(ledPin, HIGH); // stop the program for milliseconds: delay(sensorValue); // turn the ledPin off: digitalWrite(ledPin, LOW); // stop the program for for milliseconds: delay(sensorValue); Serial.println(sensorValue); if (sensorValue<10){ do{ // turn the ledPin off: digitalWrite(ledPin, LOW); sensorValue2 = analogRead(sensorPin); } while(sensorValue2<10); } else if (sensorValue>999){ do{ // turn the ledPin on: digitalWrite(ledPin, HIGH); sensorValue2 = analogRead(sensorPin); } while(sensorValue2>999); }; }