
Reading a Potentiometer — SIK Circuit 2
Learn to read analog input from a potentiometer and use it to control LED blink speed. Turn the knob to make the LED blink faster or slower — your first step into analog sensors!
निर्देश
Parts & Introduction
Parts & Introduction
In this experiment you'll use a potentiometer (a variable resistor with a knob) to control how fast an LED blinks. This introduces analogRead() — reading voltage levels between 0 and 5V as values from 0 to 1023.
Parts Needed
- 1x Arduino Uno + USB cable
- 1x Breadboard
- 1x Potentiometer (10K)
- 1x LED (any color)
- 1x 330Ω Resistor
- 6x Jumper Wires
Hardware Hookup
Hardware Hookup
Wiring Instructions
- Place the potentiometer in the breadboard. It has three pins.
- Connect the left pin to GND and the right pin to 5V (or vice versa).
- Connect the middle pin (wiper) to Analog Pin A0.
- Place an LED in the breadboard. Connect the positive leg (longer) to Digital Pin 13.
- Connect the negative leg (shorter) through a 330Ω resistor to GND.
- Connect the 5V and GND rails on the breadboard to the Arduino.
Arduino Code
Arduino Code
Open the Arduino IDE and upload the following sketch to your Arduino board.
/*
SparkFun Inventor's Kit
Example sketch 02 — POTENTIOMETER
Measure the position of a potentiometer and use it to
control the blink rate of an LED. Turn the knob to make
it blink faster or slower!
This code is completely free for any use.
Visit http://learn.sparkfun.com/products/2 for SIK information.
*/
int sensorPin = 0; // Potentiometer on analog pin 0
int ledPin = 13; // LED on digital pin 13
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
int sensorValue;
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH);
delay(sensorValue);
digitalWrite(ledPin, LOW);
delay(sensorValue);
}Test & Experiment
Test & Experiment
What You Should See
The LED blinks faster or slower as you turn the potentiometer knob. At one extreme it blinks very fast, at the other it blinks slowly.
Troubleshooting
- Sporadically working: The potentiometer pins may not be making good contact. Press it firmly into the breadboard.
- Not working: Make sure the wiper (middle pin) goes to Analog pin 0, not Digital pin 0.
- LED not lighting: LEDs only work in one direction. Flip it around.
Experiments to Try
- Open the Serial Monitor and print the
sensorValueto see the raw numbers (0-1023). - Use
map()to convert the sensor range to a brightness range and control LED brightness withanalogWrite().
सामग्री
- •SparkFun Inventor's Kit - V3.2 - 1 kitNOK 999.20
- •Arduino Uno R3 - 1 pieceप्लेसहोल्डर
- •Breadboard - 1 pieceप्लेसहोल्डर
- •Potentiometer (10K) - 1 pieceप्लेसहोल्डर
- •5mm LED - 1 pieceप्लेसहोल्डर
- •330 Ohm Resistor - 1 pieceNOK 24.00
- •Jumper Wires - 6 piecessNOK 39.20
आवश्यक उपकरण
- Computer with Arduino IDE
CC0 पब्लिक डोमेन
यह ब्लूप्रिंट CC0 के तहत जारी किया गया है। आप बिना अनुमति माँगे इस कार्य को किसी भी उद्देश्य के लिए कॉपी, संशोधित, वितरित और उपयोग करने के लिए स्वतंत्र हैं।
उनके ब्लूप्रिंट के माध्यम से उत्पाद खरीदकर मेकर का समर्थन करें जहाँ वे मेकर कमीशन कमाते हैं जो विक्रेताओं द्वारा निर्धारित होता है, या इस ब्लूप्रिंट का नया संस्करण बनाएँ और राजस्व साझा करने के लिए इसे अपने ब्लूप्रिंट में कनेक्शन के रूप में शामिल करें।