#include <Servo.h>
Servo servo1; // Robotic Arm Rotation
Servo servo2; // Robotic Arm Extension
int distancePin = A0; // Distance Sensor pin
int cameraPin = 13; // Camera detection pin
int ledPin = 12; // LED pin
void setup() {
servo1.attach(9); // Pin for servo1
servo2.attach(10); // Pin for servo2
pinMode(distancePin, INPUT);
pinMode(cameraPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int distance = analogRead(distancePin);
int faceDetected = digitalRead(cameraPin);
if (faceDetected == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on LED to indicate face detection
// Activate robotic arm
servo1.write(170); // Set angle for arm rotation
delay(1000);
servo2.write(90); // Extend arm to reach the black box
// Insert stick
if (distance <= 102) { // Assuming 1 cm corresponds to distance value of 102
// Code to insert stick
delay(10000); // Wait for 10 seconds
// Remove stick
servo2.write(0); // Retract arm
servo1.write(110); // Set angle for arm rotation to place stick in white box
delay(1000);
servo2.write(90); // Extend arm to place stick in white box
delay(1000);
servo2.write(0); // Retract arm
}
} else {
digitalWrite(ledPin, LOW); // Turn off LED if no face detected
}
}