Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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 0.
- Whether the LED if on for readings below 2.5.V.
- The circuit:
- Potentiometer attached to analog input A1
- 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 0
- LED cathode (short leg) attached to ground
- Created by David Cuartielles
- modified 12 Feb 2016
- By Ernst Pluess
- This example code is in the public domain.
- */
- int sensorPin = A1; // select the input pin for the potentiometer
- int ledPin = 0; // select the pin for the LED
- int sensorValue = 0; // variable to store the value coming from the sensor
- void setup() {
- // declare the ledPin as an OUTPUT:
- pinMode(ledPin, OUTPUT);
- }
- void loop() {
- // read the value from the sensor:
- sensorValue = analogRead(sensorPin);
- if (sensorValue < 512) {
- // turn the ledPin on
- digitalWrite(ledPin, HIGH);
- }
- else {
- // turn the ledPin off:
- digitalWrite(ledPin, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement