How to Connect a Potentiometer with your Arduino !

How to Connect a Potentiometer with your Arduino !

Time : 15 – 20 minutes

Level : Basic

Using a potentiometer, you will be able to control the resistance of an LED. Turning the knob will increase and decrease the frequency the LED blinks.

You’ll need :

  • Arduino Uno.
  • USB Cable.
  • Breadboard.
  • LED 5mm.
  • Resistor : 220 Ω .
  • Potentiometer (10k Trimpot).
  • Jumper Wires.

Project Diagram :

Project 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
Submit your review
1
2
3
4
5
Submit
     
Cancel

Create your own review

Arduino with Potentiometer
Average rating:  
 0 reviews

Post Author: Electronic Project YEP

Ahmed Amorri

Leave a Reply