Skip to content

Instantly share code, notes, and snippets.

@kuasha
Created January 7, 2017 06:18
Show Gist options
  • Save kuasha/30f12d6de5f652b0ec5d004b5cc751f1 to your computer and use it in GitHub Desktop.
Save kuasha/30f12d6de5f652b0ec5d004b5cc751f1 to your computer and use it in GitHub Desktop.
/*
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
* Note: because most Arduinos have a built-in LED attached
to pin 13 on the board, the LED is optional.
Created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe
modified 6 Jan 2017
By Maruf Maniruzzaman
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int newSensorValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
// read the value from the sensor:
newSensorValue = analogRead(sensorPin);
if(abs(newSensorValue - sensorValue) > 5){
sensorValue = newSensorValue;
Serial.println(sensorValue);
}
delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment