Arduino Basics- Using Potentiometers - I Made It at TechShop
by madebyjoe in Circuits > Arduino
20089 Views, 14 Favorites, 0 Comments
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
http://techshop.ws
Materials
Arduino Uno
Usb cable
LED
10k ohm Potentiometer
500ohm resistor
breadboard
wire
Usb cable
LED
10k ohm Potentiometer
500ohm resistor
breadboard
wire
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.
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.
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.
-----------------------------------------------------------------
#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.