Emax ES08A and Miuzei Micro 9g Servos not going to the correct angle?

1 week ago 4
ARTICLE AD BOX

I'm attempting to angle the servos 90 degrees and they always go to the edge of their operating range and just wiggle back in forth, any reason this would happen? I have 5 servos connected to an Arduino Uno through a breadboard. The inputs are coming from a pixy2. Attempting to rotate the servos 90 degrees and hold until the signal is not being received anymore.

//Include necessary libraries #include <Pixy2.h> #include <Servo.h> // <-- We need this library //Initialize Pixy2 object Pixy2 pixy; // --- Servo Pin Setup --- // We need to create a separate Servo object for each pin Servo servo1; Servo servo2; Servo servo3; Servo servo4; Servo servo5; // --- Servo Position Setup --- const int START_POSITION = 45; const int DETECTED_POSITION = 135; //Initialize variables to store outputs for signatures 1-5 int signature1Detected = 0; int signature2Detected = 0; int signature3Detected = 0; int signature4Detected = 0; int signature5Detected = 0; //Setup function void setup() { //Initialize serial communication Serial.begin(9600); //Initialize Pixy2 communication pixy.init(); // --- Attach all 5 Servos to their pins --- servo1.attach(3); // Pin 3 for Signature 1 servo2.attach(5); // Pin 5 for Signature 2 servo3.attach(6); // Pin 6 for Signature 3 servo4.attach(9); // Pin 9 for Signature 4 servo5.attach(10); // Pin 10 for Signature 5 // --- Set all Servos to the starting position --- servo1.write(START_POSITION); servo2.write(START_POSITION); servo3.write(START_POSITION); servo4.write(START_POSITION); servo5.write(START_POSITION); } //Main loop void loop() { //Get blocks from Pixy2 pixy.ccc.getBlocks(); //Check if there are any blocks detected if (pixy.ccc.numBlocks > 0) { //Loop through all detected blocks for (int i = 0; i < pixy.ccc.numBlocks; i++) { //Check for signature 1 (Red) if (pixy.ccc.blocks[i].m_signature == 1) { signature1Detected = 1; } //Check for signature 2 (Green) else if (pixy.ccc.blocks[i].m_signature == 2) { signature2Detected = 1; } //Check for signature 3 (Yellow) else if (pixy.ccc.blocks[i].m_signature == 3) { signature3Detected = 1; } //Check for signature 4 (Blue) else if (pixy.ccc.blocks[i].m_signature == 4) { signature4Detected = 1; } //Check for signature 5 (White) else if (pixy.ccc.blocks[i].m_signature == 5) { signature5Detected = 1; } } } // --- NEW SERVO LOGIC --- // This logic uses .write() to set a position (angle) // Control servo on pin 3 based on signature 1 if (signature1Detected == 1) { servo1.write(DETECTED_POSITION); } else { servo1.write(START_POSITION); } // Control servo on pin 5 based on signature 2 if (signature2Detected == 1) { servo2.write(DETECTED_POSITION); } else { servo2.write(START_POSITION); } // Control servo on pin 6 based on signature 3 if (signature3Detected == 1) { servo3.write(DETECTED_POSITION); } else { servo3.write(START_POSITION); } // Control servo on pin 9 based on signature 4 if (signature4Detected == 1) { servo4.write(DETECTED_POSITION); } else { servo4.write(START_POSITION); } // Control servo on pin 10 based on signature 5 if (signature5Detected == 1) { servo5.write(DETECTED_POSITION); } else { servo5.write(START_POSITION); } // --- END OF SERVO LOGIC --- //Print outputs in simple English if (signature1Detected == 1) { Serial.println("Red (Signature 1)"); } if (signature2Detected == 1) { Serial.println("Yellow (Signature 2)"); } if (signature3Detected == 1) { Serial.println("Green (Signature 3)"); } if (signature4Detected == 1) { Serial.println("Blue (Signature 4)"); } if (signature5Detected == 1) { Serial.println("White (Signature 5)"); } if (signature1Detected == 0 && signature2Detected == 0 && signature3Detected == 0 && signature4Detected == 0 && signature5Detected == 0) { Serial.println("No blocks detected from signatures 1-5"); } //Reset variables for next loop signature1Detected = 0; signature2Detected = 0; signature3Detected = 0; signature4Detected = 0; signature5Detected = 0; //Delay to match 60 fps delay(16); }
Read Entire Article