So, I had the inital idea of making a wall clock that detects when a person is looking at it and if the person is, then the clock would function normally but as soon as he/she looks away it would go haywire and start moving around.
This proved to be difficult to implement as it is almost impossible to detect a person looking at the clock with simple sensors and without using some sort of computer vision. Therefore, I turned to the next best thing with the advice from our professor: A wristwatch which detected to tilt movement as you read the watch.
I used a servo coupled with a tilt sensor and some code to make it work.
Here is a video of it working:
Here’s the code I used:
#include <Servo.h> Servo myClockServo; int pos = 0; int lightSensor = A0; int tiltPin=2; int maxLight=0; int reading; int previous = LOW; long time = 0; long debounce = 50; void setup() { pinMode(tiltPin,INPUT); digitalWrite(tiltPin,HIGH); myClockServo.attach(9); Serial.begin(9600); } void loop() { boolean crazy=false; int switchstate; int inPin=tiltPin; reading = digitalRead(inPin); if (reading != previous) { time = millis(); } if ((millis() - time) > debounce) { switchstate = reading; if (switchstate == HIGH) crazy = false; else crazy = true; } previous = reading; int delayVal=10; if(crazy){ myClockServo.write(101); } else { myClockServo.write(180); delay(500); myClockServo.write(0); delay(500); } }