Introduction: Arduino Basics- Using Potentiometers - I Made It at TechShop

Picture of Arduino Basics- Using Potentiometers - I Made It at TechShop

Potentiometers have a lot of uses in electronics. They are essentially a variable resistor. Combine this with the fact that an Arduino is capable of reading analog voltages, this can turn a potentiometer into something like a continuous speed control or position control. This basic control is essential understand in making more complex systems. On top of that, I made this at TechShop. Maybe you can try this after taking the electronics course.

http://techshop.ws

Step 1: Materials

Picture of Materials

Arduino Uno

Usb cable

LED

10k ohm Potentiometer

500ohm resistor

breadboard

wire

Step 2: Circuit

Picture of Circuit

This is a fairly simple circuit. The Arduino can provide power for the potentiometer and a logical high from the digital pins is high enough to run a simple led.

Connect the LED to pin 3 with a current limiting resistor of 500 ohms. Connect the long end of the led to the resistor and the short side to ground. Connect the potentiometer to power and ground and the third leg to analog pin 5. This creates a variable voltage divider. Once the Arduino is connected to a computer, the board will have power.

Step 3: Code

The following is the code for the blinking device.

-----------------------------------------------------------------

#define POT_PIN 5
#define LED_PIN 3

void setup(){
 
  //set this to output
  pinMode(LED_PIN, OUTPUT);
 
}

void loop(){
 
  int val;
 
  val=analogRead(POT_PIN);

  digitalWrite(LED_PIN, HIGH);
 
  delay(val);
 
  digitalWrite(LED_PIN, LOW);
 
  delay(val);
 
}


-----------------------------------------------------------------

So what's going on here? First the arduino needs to set the led pin to an output. Then the program loops through and does a few things. First it sets aside a little memory for the value that will be read from the potentiometer. Then it reads the voltage value from analog pin 5. This is a value from 0 to 1023 which translates to 0-5v. Once that value is determined, it sets that value as the delay for the duration of the on and off cycles of the led.

And that's it, a potentiometer used to control a blinking light.

Comments

JRV31 (author)2015-05-23

Is it all right with you if I add this instructable to my beginning Arduino collection?

https://www.instructables.com/id/Beginning-Arduino/

amandaghassaei (author)2012-08-16

another cool thing you could do is use the pot to control the brightness of the LED, replace your current loop with this:

void loop(){
int val;
val= analogRead(POT_PIN);
analogWrite(LED_PIN,(val/4);
delay(100);
}

sorry put an extra ) at the end of the analogWrite:

void loop(){
int val;
val= analogRead(POT_PIN);
analogWrite(LED_PIN,(val/4));
delay(100);
}

madebyjoe (author)amandaghassaei2012-08-16

Sure, turn that blinking light into a dimmer switch! But this is just a really really slow version of analogWrite. Turns out analogWrite doesn't change the voltage, but instead just blinks really fast. Also known as PWM'ing. Turn down the delay, the blinks start getting so fast that it just looks dim. It's a good intro to PWM though!

But if I were to make a dimmer, I would do this

void loop(){
int val;
val=analogRead(POT_PIN);
val=map(val, 0, 1023, 0, 255);
analogWrite(LED_PIN, val);
}

That way the changes are accurately mapped to the possible values analogWrite accepts and changes are instant (no delay needed).

-Joe

About This Instructable

19,141views

13favorites

License:

Add instructable to: