Advertisement
microrobotics

FEETECH FS90-FB Micro Servo with Position Feedback

Apr 21st, 2023
642
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. Here's an example code to control a FEETECH FS90-FB Micro Servo with Position Feedback using an Arduino. This code demonstrates how to move the servo to different positions and read the position feedback from the servo's built-in potentiometer.
  3.  
  4. To use this code, connect the FEETECH FS90-FB Micro Servo's signal wire to the specified pin on your Arduino board (in this case, pin 9) and the feedback wire to the analog pin A0. Upload the code using the Arduino IDE and open the Serial Monitor to see the servo's position feedback.
  5.  
  6. Remember to power the servo using an appropriate power supply, typically 4.8V to 6V, with the servo's red wire connected to the positive voltage supply and the black or brown wire connected to the ground. Connect the ground from the servo's power supply to the ground of the Arduino to ensure a common ground reference.
  7.  
  8. This example code moves the servo to 0, 90, and 180 degrees while reading and displaying the position feedback. You can modify this code to suit the specific requirements of your project or application.
  9. */
  10.  
  11. #include <Servo.h>
  12.  
  13. // FEETECH FS90-FB Micro Servo with Position Feedback example
  14.  
  15. const int servoPin = 9; // Connect the servo's signal wire to digital pin 9 (PWM capable) on the Arduino
  16. const int feedbackPin = A0; // Connect the servo's feedback wire to analog pin A0 on the Arduino
  17.  
  18. Servo fs90fb; // Create a Servo object
  19.  
  20. void setup() {
  21.   fs90fb.attach(servoPin); // Attach the Servo object to the specified pin
  22.   pinMode(feedbackPin, INPUT); // Set the feedbackPin as input
  23.   Serial.begin(9600); // Start the Serial Monitor with a baud rate of 9600
  24. }
  25.  
  26. void loop() {
  27.   // Move the servo to 0 degrees
  28.   fs90fb.write(0);
  29.   delay(1000); // Wait for 1 second to allow the servo to reach the target position
  30.   int positionFeedback0 = analogRead(feedbackPin); // Read the position feedback
  31.   Serial.print("Servo at 0 degrees. Position feedback: ");
  32.   Serial.println(positionFeedback0);
  33.  
  34.   // Move the servo to 90 degrees
  35.   fs90fb.write(90);
  36.   delay(1000); // Wait for 1 second to allow the servo to reach the target position
  37.   int positionFeedback90 = analogRead(feedbackPin); // Read the position feedback
  38.   Serial.print("Servo at 90 degrees. Position feedback: ");
  39.   Serial.println(positionFeedback90);
  40.  
  41.   // Move the servo to 180 degrees
  42.   fs90fb.write(180);
  43.   delay(1000); // Wait for 1 second to allow the servo to reach the target position
  44.   int positionFeedback180 = analogRead(feedbackPin); // Read the position feedback
  45.   Serial.print("Servo at 180 degrees. Position feedback: ");
  46.   Serial.println(positionFeedback180);
  47.  
  48.   delay(2000); // Wait for 2 seconds before repeating the loop
  49. }
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement