For the final iteration of our project, Harsh and I were able to implement various solutions to mechanical issues we encountered for our first attempt. We used springs to make our movements more fluid and controlled and strengthened our frame to allow for more stability and longevity for the contraption in general.

As had been our goal, we used a photosensor to control the device with the idea of light being the main driver determining the position of the contraption. While we hope to clean up, optimize, and further explore this project in the future, the present functionality fulfills our short term goals and allows us to contently stare at its geometric and mechanic beauty.

To view our previous iteration, please follow this link.

Code:

// ServoSweep - move a servo along trajectories
//
// Copyright (c) 2016, Garth Zeglin.  All rights reserved. Licensed under the
// terms of the BSD 3-clause license as included in LICENSE.
//
// This program assumes that:
//
//  1. A small hobby servo is connected to pin 9.
//     Note: this sensor has +5V digital outputs can connect directly to the
//     digital input pins on the Arduino UNO.
//
//  2. The serial console on the Arduino IDE is set to 9600 baud communications speed.
//
// ================================================================================
// Import libraries.
#include <Servo.h> 

// ================================================================================
// Definitions of constant values.

// The wiring assignment.
const int SERVO_PIN = 9;
int val = 0;

// ================================================================================
// Global variable declarations.

// Create an object to control the servo by declaring it.  The Servo C++ class
// is defined in the Servo library.
Servo wiggling_servo;


// ================================================================================
// Configure the hardware once after booting up.  This runs once after pressing
// reset or powering up the board.

void setup()
{
  // Initialize the serial UART at 9600 bits per second.
  Serial.begin(9600);

  // Initialize the Servo object to use the given pin for output.
  wiggling_servo.attach(SERVO_PIN);
}

// ================================================================================
// Run one iteration of the main event loop.  The Arduino system will call this
// function over and over forever.
void loop()

{ 
  val = analogRead(0);
  Serial.println(val);
  if (val<300)
  {
    wiggling_servo.write(50);
    delay(1000);
  }
  else{
    wiggling_servo.write(120);
    delay(1000);
  }

  
  //================================================================
  // Movement template 1: perform several uncontrolled movements at maximum speed.
//    for (int i = 0; i < 100; i = i+1){
//    wiggling_servo.write(50);
//    delay(500);
//    wiggling_servo.write(20);
//    delay(500);
//    wiggling_servo.write(50);
//    delay(500);
//    }
}