Help me!!!! Why the my 2 servo motor are not functioning properly, I only heard click sound but it didn't rotate. What is the possible problem. But the inductive proximity sensor are functioning. What do you is the problem coding or circuit?
#include <Servo.h>
// Define pins
const int proximitySensorPin = 7; // Change as per your setup
const int servoPin1 = 9; // Servo motor 1
const int servoPin2 = 10; // Servo motor 2
// Create servo objects
Servo servo1;
Servo servo2;
void setup() {
// Attach servos to pins
servo1.attach(servoPin1);
servo2.attach(servoPin2);
// Set up the proximity sensor pin as input
pinMode(proximitySensorPin, INPUT);
}
void loop() {
// Check if the proximity sensor detects metal
if (digitalRead(proximitySensorPin) == LOW) {
// Rotate the first servo motor to 180 degrees
servo1.write(180);
delay(1000); // Wait for the servo to finish rotating
// Rotate the second servo motor to 180 degrees
servo2.write(180);
delay(1000); // Wait for the servo to finish rotating
// Return both servos to the initial position
servo1.write(0);
servo2.write(0);
delay(1000); // Wait before starting the next cycle
}
// Add a delay to avoid constant triggering
delay(100);
}