My Project is a ramp where the ball passes over the phototransistor and is then pushed back up the ramp by the servo. It’s a very simple mechanism that was originally supposed to work with a super ball but the phototransistor did not seem to detect it as well as it detected a ping pong ball, so I switched the ball. The general function is still the same. It is intended to have this simple oscillating motion of the ball rolling down the ramp and being sent back up only to roll down again and continue the process.

#include <Servo.h&gt;

const int IN_PIN = A3;
const int OUT_PIN = 7;

Servo s;

void setup()
{
  s.attach(7);
  s.write(130);
}

void loop()
{
  while(digitalRead(IN_PIN) != 0);
  delay(1500);
  s.write(0);
  delay(1000);
  s.write(130);
  while(digitalRead(IN_PIN) == 0);
}