The Spinning Bow Tie

I created this spinning bow tie that will spins when there is someone near you using the servo and a motion sensor. The motion sensor goes at the back, while the bow tie at the front so that if there’s someone who walks up to you from behind, the bow tie will start to spin. The trouble is that the sensor is too sensitive and it picks up motion unless you’re sitting absolutely still.

Used my mug since it was tricky trying to shoot a decent selfie shot.

#include <Servo.h>

int servoPin = 9;
int sensorPin = 12;

Servo servo;
int angle = 0; // servo position in degrees

void setup() {
servo.attach(servoPin);
pinMode(sensorPin, INPUT);
Serial.begin(9600);
}

void loop() {
int val = digitalRead(sensorPin);
if(val == HIGH) {
Serial.println(“I AM HIGH!”);
// scan from 0 to 180 degrees
for(angle = 0; angle < 180; angle++) {
servo.write(angle);
delay(15);
}
// now scan back from 180 to 0 degrees
for(angle = 180; angle > 0; angle–) {
servo.write(angle);
delay(15);
}
}
else{
Serial.println(“I AM LOW!”);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *