This is a simple pivot hinge created with laser cut acrylic which is used to open the lid when your hand gets near the infrared sensor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | // Import libraries. #include <Servo.h> // The wiring assignment. const int SERVO_PIN = 9; int isObstaclePin = 7; // This is our input pin int isObstacle = HIGH; // HIGH MEANS NO OBSTACLE Servo wiggling_servo; void setup() { // Initialize the serial UART at 9600 bits per second. Serial.begin(9600); // Initialize the Servo object to use the given pin for output. wiggling_servo.attach(SERVO_PIN); wiggling_servo.write(0); //Infrared setup pinMode(isObstaclePin, INPUT); Serial.begin(9600); } void loop() { checkSensor(); } void checkSensor() { isObstacle = digitalRead(isObstaclePin); Serial.print( "is obstacle" ); Serial.println(isObstacle); if (isObstacle == HIGH){ wiggling_servo.write(0); } if (isObstacle == LOW){ wiggling_servo.write(45); } } |
Leave a Reply
You must be logged in to post a comment.