Arduino Tutorial: Controlling the LED’s Blinking Rates using Potensiometer

Posted on

Arduino Tutorial: Controlling the LED's Blinking Rates using Potensiometer
This is a tutorial about controlling the LED’s blinking rates using potensiometer. A potentiometer is really a simple knob that gives a adjustable resistance, which we are able to read into the Arduino board as an analog value. In this simple tutorial, you will see how the resistance value of the potensiometer will control the blinking rates of a LED

We hook up three wires to the Arduino board. The First goes to ground from one of the outer pin (left) of the potentiometer. The second goes from 5 volts towards the other outer (right) pin of the potentiometer. The third goes from analog input 2 of Arduino board to the middle pin of the potentiometer.

By turning the canal of the potentiometer, we modify the level of resistence on either side of the wiper which is hooked up towards the center pin of the potentiometer. This varies the relative “closeness” of that pin to 5 volts and ground, delivering us a various analog input. Once the canal is turned all the way in one direction, there are 0 volts getting to the pin, and we read 0. When the canal is turned all the way in the other direction, there are 5 volts getting to the pin and we read 1023. In between, analogRead() returns a range between 0 and 1023 which is proportional to the level of voltage currently being applied to the pin.

Code:

/* Analog Read to LED
* ------------------
*
* 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.
*
* Created 1 December 2005
* copyleft 2005 DojoDave <http://www.0j0.org>
* http://arduino.berlios.de
*
*/

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
}

Source: www.arduino.cc

Gravatar Image
Robotics Technology , Tutorial and News

Leave a Reply

Your email address will not be published. Required fields are marked *