For this demo, I attached the photointerruptor near the front of the base and the servo motor at the bottom of the base. The servo motor has been programmed in a way to give small jerks to the the object and thus, slowly make it move forward. The photointerruptor receives analog values through the pin A1, which is read and according to the a certain threshold value, it controls whether the servo motor stops or continues. Thus, if there is a wall or another object in front of the moving omega, it stops moving. Once there is no obstruction, the omega starts moving again. The following video demonstrates how this works.
If we look closely, the photointerruptor leads have been soldered to wires that go back to connect to a breadboard, which is then connected to the Arduino to receive inputs. The following picture shows the connections and how they look on the inside.
Here is the code I used to make this demo possible:
#include <Servo.h> Servo hi; int sensorValue=0; int sensorPin=A1; void setup() { // put your setup code here, to run once: hi.attach(9); Serial.begin(9600); pinMode(sensorPin,INPUT); } void loop() { // put your main code here, to run repeatedly: sensorValue = analogRead(sensorPin); Serial.println(sensorValue); while (1==1){ if (sensorValue>=800){ hi.write(0); delay(1000); sensorValue = analogRead(sensorPin); Serial.println(sensorValue); hi.write(75); delay(500); }else{ sensorValue = analogRead(sensorPin); Serial.println(sensorValue); hi.write(0); delay(500); } } }]]>
I designed this so that it could attach to wooden face I laser cut. The servo would be stuck to a rectangular face which acts as base and the servo would be attached to a face above it which would rotate. The measurements were hard to be precise with so the fitting is a bit lose. The following video demonstrates it.
However, I decided to experiment with the mechanism by removing the top face and just letting one face stay. What I found was simple yet amusing, and the first thought that came into my mind was that any child seeing this would appreciate it. I present you the dancing face (switch on sound for a fun rhythm):
The code I was used were simple repititions where I tried to vary the time to create the rhythm in the video.
#include <Servo.h>
Servo hi;
void setup()
{
hi.attach(9);
}
void loop()
{
hi.write(0);
delay(1000);
hi.write(180);
delay(1000);
hi.write(0);
delay(100);
hi.write(180);
delay(100);
hi.write(0);
delay(500);
hi.write(180);
delay(500);
hi.write(0);
delay(1000);
hi.write(180);
delay(1000);
for (int i=1;i<10;i++){
hi.write(0);
delay(100);
hi.write(180);
delay(100);
}
for (int i=1;i<5;i++){
hi.write(0);
delay(500);
hi.write(180);
delay(500);
}
hi.write(0);
delay(1000);
hi.write(180);
delay(1000);
hi.write(0);
delay(100);
hi.write(180);
delay(100);
hi.write(0);
delay(500);
hi.write(180);
delay(500);
hi.write(0);
delay(1000);
hi.write(180);
delay(1000);
}
]]>