Controllable Swinger

Control the position of the servo!

The purpose of my project is too add intractability to my Demo 1. There are five LTH-1550 photoreflective sensors glued unto a board and the user can move their hand over the board and control the position of the servo, allowing the ball to move!

Swiping your finger across the board moves the swinger!

I initially wanted to swing the board with the servo and have it balance the ball in the middle of the board with a PD controller, but unfortunately the ball wasn’t being recognized by the sensors and I was unable to find another, less opaque ball. 🙁 Out of time and out of luck, I revamped my idea to just control the servo with swipes. And it works pretty well!

#include <Servo.h&gt;

const int SENSOR_PIN1 = 7;
const int SENSOR_PIN2 = 6;
const int SENSOR_PIN3 = 5;
const int SENSOR_PIN4 = 4;
const int SENSOR_PIN5 = 3;
const int SERVO_PIN = 9;

Servo svo;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  svo.attach(SERVO_PIN);
}

void loop() {
  short val1 = digitalRead(SENSOR_PIN1);
  short val2 = digitalRead(SENSOR_PIN2);
  short val3 = digitalRead(SENSOR_PIN3);
  short val4 = digitalRead(SENSOR_PIN4);
  short val5 = digitalRead(SENSOR_PIN5);
  
  if (val1) {
    svo.write(20);
  }
  else if (val2) {
    svo.write(50);
  }
  else if (val3) {
    svo.write(80);
  }
  else if (val4) {
    svo.write(110);
  }
  else if (val5) {
    svo.write(140);
  }
}

To improve this project, I would definitely add behaviors for the cases where multiple sensors are being activated. And maybe make a case to hide all my nasty wiring… 🙂