Tutorial.Knob History

Show minor edits - Show changes to markup

November 16, 2011, at 04:39 AM by Scott Fitzgerald -
Changed line 42 from:
to:
September 24, 2010, at 05:50 AM by Tom Igoe -
Changed lines 42-68 from:
to:
September 23, 2010, at 10:53 PM by Christian Cerrito -
Changed lines 3-6 from:

Knob

Description

to:

Knob

September 20, 2010, at 03:36 PM by Christian Cerrito -
Changed lines 79-82 from:
  • Sweep? - sweep the shaft of a servo motor back and forth.

to:
  • Sweep - sweep the shaft of a servo motor back and forth.

September 20, 2010, at 03:36 PM by Christian Cerrito -
Added lines 73-77:
Changed lines 79-82 from:
to:
  • Sweep? - sweep the shaft of a servo motor back and forth.

September 20, 2010, at 03:31 PM by Christian Cerrito -
Changed lines 7-8 from:

Control the position of a RC (hobby) servo motor using Arduino's 'servo library and a potentiometer.

to:

Control the position of a RC (hobby) servo motor with your Arduino and a potentiometer.

This example makes use of the Arduino servo library.

September 20, 2010, at 03:27 PM by Christian Cerrito -
Changed lines 7-8 from:

Uses a potentiometer to control the movement of the shaft of a servo motor.

to:

Control the position of a RC (hobby) servo motor using Arduino's 'servo library and a potentiometer.

September 20, 2010, at 03:22 PM by Christian Cerrito -
Changed lines 71-72 from:
to:
September 20, 2010, at 03:21 PM by Christian Cerrito -
Changed lines 26-27 from:

click the image to enlarge

to:

click the images to enlarge

September 20, 2010, at 03:21 PM by Christian Cerrito -
Added lines 25-27:

click the image to enlarge

Added lines 30-32:

images developed using Fritzing. For more circuit examples, see the Fritzing project page

Changed lines 36-37 from:

image developed using Fritzing. For more circuit examples, see the Fritzing project page

to:
September 20, 2010, at 03:19 PM by Christian Cerrito -
Added lines 26-28:

Schematic

September 20, 2010, at 03:16 PM by Christian Cerrito -
Changed lines 25-26 from:
to:
September 20, 2010, at 03:15 PM by Christian Cerrito -
Changed lines 9-10 from:

Circuit

to:
Added lines 25-30:
September 20, 2010, at 03:13 PM by Christian Cerrito -
Changed lines 17-18 from:

[@

to:
Changed lines 41-42 from:

@]

to:
October 13, 2008, at 09:07 PM by David A. Mellis -
Changed lines 1-2 from:

Examples > Analog I/O

to:

Examples > Servo Library

Changed lines 5-16 from:

A potentiometer is a simple knob that provides a variable resistance, which we can read into the Arduino board as an analog value. In this example, that value controls the rate at which an LED blinks.

We connect three wires to the Arduino board. The first goes to ground from one of the outer pins of the potentiometer. The second goes from 5 volts to the other outer pin of the potentiometer. The third goes from analog input 2 to the middle pin of the potentiometer.

By turning the shaft of the potentiometer, we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.

Circuit

Code

to:

Description

Uses a potentiometer to control the movement of the shaft of a servo motor.

Circuit

Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board. The signal pin is typically yellow or orange and should be connected to pin 9 on the Arduino board.

The potentiometer should be wired so that its two outer pins are connected to power (+5V) and ground, and its middle pin is connected to analog input 0 on the Arduino.

Code

Changed lines 18-47 from:

/* Analog Read to LED

 * ------------------ 
 *
 * turns on and off a light emitting diode(LED) connected to digital  
 * pin 13. The amount of time the LED will be on and off depends on
 * the value obtained by analogRead(). In the easiest case we connect
 * a potentiometer to analog pin 2.
 *
 * Created 1 December 2005
 * copyleft 2005 DojoDave <http://www.0j0.org>
 * http://arduino.berlios.de
 *
 */

int potPin = 2; // select the input pin for the potentiometer int ledPin = 13; // select the pin for the LED int val = 0; // variable to store the value coming from the sensor

void setup() {

  pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT

}

void loop() {

  val = analogRead(potPin);    // read the value from the sensor
  digitalWrite(ledPin, HIGH);  // turn the ledPin on
  delay(val);                  // stop the program for some time
  digitalWrite(ledPin, LOW);   // turn the ledPin off
  delay(val);                  // stop the program for some time

} @]

to:

// Controlling a servo position using a potentiometer (variable resistor) // by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

  1. include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin

void setup() {

  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 

}

void loop() {

  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023) 
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180) 
  myservo.write(val);                  // sets the servo position according to the scaled value 
  delay(15);                           // waits for the servo to get there 

} @]

See also

February 03, 2007, at 03:03 PM by David A. Mellis -
Added lines 1-47:

Examples > Analog I/O

Knob

A potentiometer is a simple knob that provides a variable resistance, which we can read into the Arduino board as an analog value. In this example, that value controls the rate at which an LED blinks.

We connect three wires to the Arduino board. The first goes to ground from one of the outer pins of the potentiometer. The second goes from 5 volts to the other outer pin of the potentiometer. The third goes from analog input 2 to the middle pin of the potentiometer.

By turning the shaft of the potentiometer, we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.

Circuit

Code

/* Analog Read to LED
 * ------------------ 
 *
 * turns on and off a light emitting diode(LED) connected to digital  
 * pin 13. The amount of time the LED will be on and off depends on
 * the value obtained by analogRead(). In the easiest case we connect
 * a potentiometer to analog pin 2.
 *
 * Created 1 December 2005
 * copyleft 2005 DojoDave <http://www.0j0.org>
 * http://arduino.berlios.de
 *
 */

int potPin = 2;    // select the input pin for the potentiometer
int ledPin = 13;   // select the pin for the LED
int val = 0;       // variable to store the value coming from the sensor

void setup() {
  pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
}

void loop() {
  val = analogRead(potPin);    // read the value from the sensor
  digitalWrite(ledPin, HIGH);  // turn the ledPin on
  delay(val);                  // stop the program for some time
  digitalWrite(ledPin, LOW);   // turn the ledPin off
  delay(val);                  // stop the program for some time
}

Share