Here's the Arduino "sketch" (program) for the Pendulum Behavior If you get, or have an Arduino and the free Arduino IDE (the program development program), you can cut and paste what follows to create the "sketch" and run it. The only other thing you need to know is that the servo's "control wire" connects to the Arduino's "pin" 9, its red wire connects to the Arduino's 5V pin and the servo's black wire connects to the Arduino's "GND" pin.

// Pendulum Behavior program
//
// Set Servo to 90 degrees
// a modification to
// BARRAGAN http://barraganstudio.com
// SWEEP program / Sketch
#include <Servo.h> //include the servo libary
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 90; // variable to store the servo position
// in this case the position is 90 degrees
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop()
{
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(1000); // waits 15ms for the servo to reach the position
}


// PENDULUM1 SKETCH
//
// From a User specified initial pendulum angle, this program calculate
// the pendulum's angle at any time "t" after the pendulum is released
// usng the following equation:
// thetatd = theta0d x cos( sqrt( (g/lfeet) * t )
//
// the time for the pendulum to swing left to right and back again
// is its PERIOD, with units in SECOONDS.
// PERIOD = 2* PI * (sqrt(Pendulum Length In Feet / Gravitational Constant in Feet/Second^2)
//
#include <Servo.h> //include the servo libary
Servo myservo; // create servo object to control a servo and call it myservo
// a maximum of eight servo objects can be created

// CONSTANTS USED IN CALCULATING SERVO POSITION ANGLE
//
// these constants are identitifed as FLOATing point numbers (have a decimal point
// and can have numbers to the right of that decimal point)
?? INT variables art INTeger variables – WHOLE numbers – NO decimal point
float g = 32.2; // Gravitational Constant in ft/sec/sec
float rad2deg = 0.017; // radians per degree
float deg2rad = 57.926; // degrees per radian
float twopi = 6.283; // 2 x Pi

// initialize the pendulum's timer
//
float t = 0; // time when the pendulum is released from its initial position
// and begins swinging
float i = 0.005; // time increment between calculations of the pendulum’s location
// as an angle


// USER'S TWO VARIABLES TO PLAY WITH TO CHANGE THE PENDULUM'S BEHAVIOR
// - the pendulum's LENGTH in inches
// - the pendulums initial angle in degrees, relative to Vertical (90 degrees)
//
int theta0d = -30; // USER SPECIFIED
// pendulum's initial angle at release in integer degrees
// - aka WHOLE NUMBER - no decimal point
// the servo positioning routines in the Servo Library
// can cause the servo arm to “twitch” if given a
// a f;oating point value for an angle
// By limiting the angle value to an integer, the pendulum
// is moved in discrete “steps” of whole degrees

float theta0r = theta0d * 0.017; // converts the pendulum's initial angle at release in degrees
// to its release angle in RADIANS
// because the COSine function uses RADIANS
int linch = 14000; // USER SPECIFIED
// pendulum length in INCHES
// INCREASE to slow down the pendulum's “out and back” swing time
// DECREASE to speed up the pendulum's “out and back” swing time
float lfeet = linch/12; // converts the USER specified pendulum length in INCHES
// to FEET - used in calculations of the pendulum’s angle
// at any time “t” after it was released to being swinging
int thetatd = theta0d; // pendulum angle at any time t - in iINTeger degrees (whole number)
float thetatr = thetatd / 57.926; // pendulum angle at any time "t" in Degrees converted to-RADIANS
// Calculate the pendulum's PERIOD (the time it takes to swing "out" and "back" once
//
float period = twopi * sqrt( lfeet / g ); // this is the time in seconds
// for the pendulum to swing "out" and "back"

// HARDWARE SET UP
// Identifies what hardware is connected to what pin on the Arduino micro controller
//
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
// Serial.begin(9600); // open serial port to send information from the micro controller
// to your computer screen.
// for use in debugging the program
// comment out when no longer needed
myservo.write(90+theta0d);
}
// BEGIN THE CONTROL OF THE SERVO
// this area will repeat until the power to the controller is turned off
//
void loop()
// set servo to the User Specified Initial Release Angle (in degrees)
//

{
t = t + i; // start the timer and begin incrementing it
// by the USER SPECIFIED “step” i
thetatd = 90 -( theta0d * cos( (sqrt ( g / lfeet ) * t ) )); // Calculate pendulum's angle at time "t"
// and "add" to the vertical position
// at angle = 90 degrees
// A POSITIVE angle will be to the “left”
// of Vertical
// A NEGATIVE angle will be to the “right”
// of Vertical
// If you want to display the calculated angles on your computer display
// while debugging changes you make to this “sketch”
// remove the “//” at the beginning of the next two lines
// Serial.print(thetatd);
// Serial.println(" ";
myservo.write(thetatd); // move pendulum to angle thetatd
delay(10);
}

<-------- to the previous page