Videos

Rocker moving with original path
Rocker moving with curved path

Description

My project for Demo 2 is a rocker that moves two balls back and forth, using a photoreflector to sense the ball bearing’s location to know when to rock. The top wooden piece with the balls’ “paths” on it is removable so the user can replace it with different paths depending on what motion they want to play with.

The user can choose between three paths for the rocker

Plans & Changes

My original plan was pretty over-ambitious: I wanted to create a similar rocker as the one shown above, with four marbles and four sensors that would play music depending on each marbles’ location. In fact, on the photo above, you can see the rocker actually does have four sensors because I reused that part from my original idea.

The original plans actually look similar to the final project

However, I didn’t predict two major problems:

  1. I did not know how to use speakers with the photoreflector
  2. The wires on three out of four photoreflectors snapped off last minute

My main goal of this project was to make a fun toy, and I did not want to redo the parts I already made. So, I made the customization aspect the main focus since it was fun to play around with and did not require redoing many parts of the project .

In the future, I definitely want to pursue the music idea again as well as do something more creative with the photoreflector and it’s ability to sense the distance of an object as well as if an object is on top of it or not.

Code

#include <Servo.h&gt; 
Servo baby;

const int photopin1 = A0;

void setup() {
  // put your setup code here, to run once:
  baby.attach(2);
  pinMode(13, OUTPUT);
  Serial.begin(115200);
  while (! Serial);
  Serial.println("TEST");

}
int photo1 = 0;
int tilt = 70;

void loop() {
  //put your main code here, to run repeatedly:
  // First, make the servo run continuously
  photo1 = analogRead(photopin1);
  Serial.println(photo1);

  while (photo1 &gt; 600) {
  baby.write(100);
  delay(1000);
  photo1 = analogRead(photopin1);
  tilt = 70;
  }

  
  while (photo1<600 &amp;&amp; tilt &gt; -40){

  baby.write(tilt);
  delay(1000);
  photo1 = analogRead(photopin1);
  tilt = tilt - 50;

  }
  delay(500);
}