View My Stats

Wednesday, February 3, 2010

A motor is not a potentiometer… the more you know.

In IED we have been experimenting with Arduinos and physical computers. For one exercise my colleague Jordan Goldstein and I attempted to work a motor with a potentiometer and pulse width modulation. After some confusion between what was a motor, what was a servo, and what was a potentiometer we eventually were able to get a servo responding to the potentiometer.

Controlling a servo with the Arduino (sweep)

Since we first had difficulty with the potentiometer, labouring under the assumption that the motor was actually the potentiometer, we first experimented with controlling the Servo directly with a programming language.

We had : a Servo
Arduino
Arduino software
Breadboard
several jumper wires

Taking the servo, we connected the red wire (positive wire) to the 5V Analog pin on the Arduino, the white (input) wire to the 9 pwm pin, the black to the GND Analog pin. Then we uploaded this code to the Arduino:

// Sweep
// by BARRAGAN

#include

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

int pos = 0; // variable to store the servo position

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}


void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}


This code can be found in the Arduino Program, under Examples, then under Servo. It is called Sweep. If you do this then the Servo begins to rotate back and forth from one position to another.

Controlling the Servo with the Arduino (Knob)

Having figured this out we played with the length of the delay by changing the value of delay(15). We also experimented by changing the value of pos, and pos+ and played with the speed of the servo.

Once we understood this, and had found an appropriate potentiometer, we attached the potentiometer and servo to the breadboard, and used the potentiometer to control the movement of the servo.

First we attached the potentiometer to the breadboard, then ran one wire to the Analog 0 pin on the Arduino. Then we attached the positive wire to the positive input on the breadboard, and the negative to the negative output on the same breadboard.

Then we attached the servo to the breadboard. The white (input wire) from the servo was connected to 9 PWM pin on the Arduino. Then the positive was connected to the positive input on the breadboard, and the negative to the negative. Then we connected the breadboard to the Arduino, running a wire from the positive input to the 5v Analog pin on the Arduino, and the negative output to the GND Analog pin.

Then we uploaded this code:

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott

#include

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
}

This code is found again in the examples, under servo, as Knob. This allowed us to turn the servo by turning the potentiometer.

In the end this is what the set up looked like.




This is another step in our understanding of the importance of physical computing as a potential tool for interactive and active history.

Thanks to Lucky Larry for a very useful tutorial.

2 comments:

  1. Potentiometers are widely used as user controls, and may control a very wide variety of equipment functions. The widespread use of potentiometers in consumer electronics declined in the 1990s, with digital controls now more common.

    potentiometer

    ReplyDelete
  2. Potentiometers are innovated to catch up the transition.

    ReplyDelete