Blinking LED With Analog Input Using Arduino

This program will allow adjust the speed of a blinking LED with analog input. Follow this patch to connect a potentiometer to your Arduino board. Then put an the long lead of an LED in pin 13 of your digital in/out, and the short lead in Ground.

/*

* AnalogInput

* by DojoDave <http://www.0j0.org>

* Turns 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(). In the easiest case we connect

* a potentiometer to analog pin 2.

*/

int potPin = 2;    // select the input pin for the potentiometer

int ledPin = 13;   // select the pin for the LED

int val = 0;       // variable to store the value coming from the sensor

void setup() {

pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT}

void loop() {

val = analogRead(potPin);    // read the value from the sensor

digitalWrite(ledPin, HIGH);  // turn the ledPin on

delay(val);                  // stop the program for some time

digitalWrite(ledPin, LOW);   // turn the ledPin off

delay(val);                  // stop the program for some time}

analog input diagramProgram a flex sensor

A Flex sensor changes resistance between 10k Ohms (straight) and 40k Ohms (bent). Follow this schematic to patch a flex sensor to your Arduino board. Connect the long lead of an LED in pin 13 of your digital in/out, and the short lead in Ground.

 

For more detail: Blinking LED With analog input Using Arduino

 


A Propos De L'Auteur

Ibrar Ayyub

Je suis expérimenté, rédacteur technique, titulaire d'une Maîtrise en informatique de BZU Multan, Pakistan à l'Université. Avec un arrière-plan couvrant diverses industries, notamment en matière de domotique et de l'ingénierie, j'ai perfectionné mes compétences dans la rédaction claire et concise du contenu. Compétent en tirant parti de l'infographie et des diagrammes, je m'efforce de simplifier des concepts complexes pour les lecteurs. Ma force réside dans une recherche approfondie et de présenter l'information de façon structurée et logique format.

Suivez-Nous:
LinkedinTwitter

Laisser un Commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

fr_FRFrench
Faire défiler vers le Haut