How To Reading Potentiometer With Arduino

Required Hardware
For users who do not have Hackerspace Karachi Arduino Kit v1.0
- Arduino Board
- Breadboard
- Potentiometer (150k)
- Hook-up Wires
Circuit
For users who do not have Hackerspace Karachi Arduino Kit v1.0
Schematic
Code
1. /*
2. Reading potentiometer with Arduino
3.
4. This example shows how to read potentiometer using Arduino.
5.
6. The circuit:
7. – POT
8. Anode connected to 5v.
9. Signal/Viper connected to analog pin A2.
10. Cathode connected to Ground.
11.
12. http://hackerspacekarachi.org/
13. */
14. const int potPin = A2; //define pin of potentiometer connected to arduino
15. int value; // set vaiable to store the position of potentiometer
16.
17. void setup()
18.
19. {
20. pinMode (potPin, INPUT); //Sets the Potentiometer pin as an output
21. Serial.begin (9600); // initializing serial monitor
22. }
23.
24.
25. void loop()
26. {
27. value = analogRead(potPin); //reads and store the analogue value
28. Serial.print ( value );
29. }