A Potentiometer is a commonly used variable resistor. Turning the knob, you vary the output voltage between 0 and 5V. This value is sent through the middle pin of the pot.
Output: This module outputs 5v when turned in one direction, and 0v when turned in the opposite way. When connected to an input on the Arduino using the TinkerKit Shield, you can expect to read values between 0 and 1023.
Module Description: This module features a 4k7 Ohm linear potentiometer, a signal amplifier, the standard TinkerKit 3pin connector, a green LED that signals that the module is correctly powered and a yellow LED whose brightness changes according to the position of the potentiometer.
This module is a SENSOR. The connector is an OUTPUT which must be connected to one of the INPUT connectors on the TinkerKit Shield.
/*
Analog input, analog output, serial output
Reads an analog input pin, and T000140 Rotary Potetiometer
Analog Sensor connected to I0, and uses the result to set
the brightness on a T010111 LED Module connected on O0.
Also prints the results to the serial monitor.
created 29 Dec. 2008
Modified 4 Sep 2010
by Tom Igoe
modified 7 dec 2010
by Davide Gomba
modified on Ded 2011
by Federico Vanzati
This example code is in the public domain.
*/
#include <TinkerKit.h>
// creating the object ‘button’ that belongs to the ‘TKButton’ class
// and giving the value to the desired input pin
TKPotentiometer pot(I0);
// creating the object ‘led’ that belongs to the ‘TKLed’ class
// and giving the value to the desired output pin
TKLed led(O0);
int potValue = 0; // value read from the pot
void setup() {
// initialize serial communications at 9600 bps
Serial.begin(9600);
}
void loop() {
// read the analog in value:
potValue = pot.get();
// set the led brightness
led.brightness(potValue);
// print the results to the serial monitor:
Serial.print("potValue = " );
Serial.println(potValue);
// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}
