Robotics & Arduino
Lesson 3 · Hands on

Project 02

Read the potentiometer

The code.

//Declare
const int POT_PIN = A0; 		// Potentiometer connected to Analog Pin A0

//Setup
void setup() {
  Serial.begin(9600);       	// Init serial comm at 9600 bits per second
  pinMode(POT_PIN, INPUT);  	//Setup pot-pin

}

//Run
void loop() {
void loop() {
  int potValue = analogRead(POT_PIN);   // Read pot value (Analog : 0 to 1023)
  printPotVal(potValue);                // Print value to Serial Monitor
  delay(100);                           // Delay for visibility
}

//Logic
void printPotVal(int potVal){
  Serial.print("Pot Value: ");
  Serial.println(potVal);
}
Potentiometer wiring: Arduino 5V to pot VCC, GND to pot GND, and pot output to A0.