![]() |
| × | 1 | |||
| × | 1 |
Components and supplies
About this project
The soft potentiometer is made of fabric and works like a normal potentiometer. It has a metal ring that you can slide and change the value that you Arduino reads.
2. Connect the potentiometer to the power supplyConnect the two ends of the potentiometer to the power supply. One to ground and the other to 5 V.
3. Connect the potentiometer to the boardConnect the moving part of the potentiometer to the analog input A5 of Arduino Lilypad.
4. How to read the potentiometer valueThe Arduino can read the potentiometer value using the analogRead
function. It will read a value between 0 and 1024 that depends on the position of the metal ring along the potentiometer. The value of the potentiometer will change the frequency of the LED blinking.
Here is the code:
int sensorPin = A5; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}