Tutorial: Potentiometers (POTs)

Working with potentiometers:

potentiometer.jpg 

pot.jpeg

The three legs are for different things:

Holding it with the turn knob up:

Right: Ground

Middle: attach to analog In

Left: Power

Exercise:

Remove the 10K resistor and photoresistor

Add a potentiometer

potwire.jpg 

Use A0 as your analog input.

NOTE: 

• We are powering the + row on the breadboard with 5V and also going to the A0 pin to get the value of the photoresists.

• This circuit uses a variable resistor, a fixed resistor and the measurement point is in the middle of the resistors.

Your LED should blink faster and slower based the amount of light it gets. 

int sensorPin = A0;    // select the input pin 
int ledPin = 13;      // select the internal 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);
}

Add an LED and change the pin the code references:

Do not forget that an LED needs a 220 resistor

arduino_potentiometer_led.png