I am a secondary school student who has been given a summer project. This project involves working on a robotic arm with 3 degrees of freedom (3 DOF), which is fitted with a color sensor and a magnet. The primary goal of this project is to identify the color of an object, use the magnet to pick up the object, relocate the arm, and then release the object into the appropriately colored container. While the magnet and color sensor are functioning properly, I am encountering challenges with the servo motors. Specifically, they operate too quickly, and I am facing difficulties with achieving accurate angles. I would greatly appreciate any advice or tips that could assist me in resolving these issues.
Welcome to the Forum! Read the forum guidelines to see how to properly ask a question and some good information on making a good post.
You will get faster and better help if you post all your code as requested by the forum guidelines. Also please describe what the hardware do you use.
Photos that clearly show your wiring can also be very helpful.
Indeed ensure you read the best practices for using the forum.
there is a library called VarSpeedServo that might help you control the movements and speed of your servos in a smooth way.
#include <Servo.h>
#include <Wire.h>
#include "Adafruit_TCS34725.h"
Servo Rot; // create servo object to control a servo
Servo Arm; // create servo object to control a servo
Servo Claw; // create servo object to control a servo
// twelve servo objects can be created on most boards
const int Magnet = 6;
int pos = 0; // variable to store the servo position
byte gammatable[256];
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
void setup() {
Serial.begin(9600);
Serial.println("Color View Test!");
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1); // halt!
}
Rot.attach(11) ; // attaches the servo on pin 11 to the servo object
Arm.attach(10) ; // attaches the servo on pin 11 to the servo object
Claw.attach(9) ; // attaches the servo on pin 11 to the servo object
}
void loop() {
// code for color sensor
float red, green, blue;
tcs.getRGB(&red, &green, &blue);
Serial.print("R:\t"); Serial.print(int(red));
Serial.print("\tG:\t"); Serial.print(int(green));
Serial.print("\tB:\t"); Serial.print(int(blue));
Serial.print("\n");
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
Rot.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
Rot.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
Arm.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
Arm.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
Claw.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 90; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
Claw.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
//code for magnet
pinMode(Magnet, OUTPUT);
digitalWrite(Magnet, LOW);
delay(2000);
digitalWrite(Magnet, HIGH);
delay(2000);
digitalWrite(Magnet, LOW);
delay(2000);
}
I am using the 3 servo motors (ES08MAI) they are 360 degree servos. For a board I am using the Arduino Uno with an external power supply. The color sensor is the CJMCU-34725.The magnet (also on an external power supply) uses the SRD-05VDC-SL-C relay.
So you have been given demo code for the servos and triggering the magnet
you need to come up with the algorithm for your project.
how would you solve this if you had to do the task yourself ?
Can you provide a link to the specific servo you are using? Generally 360 degree servos are continuous rotation.
In the code you posted, the speed of the servo is controlled by the delay(15). Not sure why you would be having difficulty with the angle accuracy, unless the servo is overloaded, or the mechanical linkage is causing inconsistencies. If you do in fact have a continuous rotation servo, there is no control of the angular position, for that you would need some type of external method of measuring the position.
This is the servo link
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.