Swinger

Notice how the ball stays in the middle trapezoid.

Meant to mimic “pirate ship rides” at amusement parks, this project shows a simple phenomena: despite the large swinging motion of the servo, the ball stays in the window of view. The objective was to create a gradual, repeated back and forth motion while also rotating a ball. Despite the large swinging range of the servo (45 – 135 degrees), the ball does not displace a large amount.

Image

The paper clips and tape add a DIY vibe.

The outcome of this project was a hypnotic machine that oscillates back and forth!

Code

#include <Servo.h&gt;

Servo svo;
const int SERVO_PIN = 9;

void setup()
{
  svo.attach(SERVO_PIN); // Attach servo to pin 9
}

float i = 0;
void loop()
{
  svo.write(45*sinf(i) + 90); // Allows for gradual swinging
  i += 0.005; // Can be increased/decreased to control speed of swing
  delay(1);
}

When I first started out, the servo swung way too fast. To remedy this, I used a sine function to create a slower and more controlled swing.