Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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.
- 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.
- 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.
- 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.
- */
- #include <Servo.h>
- // FEETECH FS90-FB Micro Servo with Position Feedback example
- const int servoPin = 9; // Connect the servo's signal wire to digital pin 9 (PWM capable) on the Arduino
- const int feedbackPin = A0; // Connect the servo's feedback wire to analog pin A0 on the Arduino
- Servo fs90fb; // Create a Servo object
- void setup() {
- fs90fb.attach(servoPin); // Attach the Servo object to the specified pin
- pinMode(feedbackPin, INPUT); // Set the feedbackPin as input
- Serial.begin(9600); // Start the Serial Monitor with a baud rate of 9600
- }
- void loop() {
- // Move the servo to 0 degrees
- fs90fb.write(0);
- delay(1000); // Wait for 1 second to allow the servo to reach the target position
- int positionFeedback0 = analogRead(feedbackPin); // Read the position feedback
- Serial.print("Servo at 0 degrees. Position feedback: ");
- Serial.println(positionFeedback0);
- // Move the servo to 90 degrees
- fs90fb.write(90);
- delay(1000); // Wait for 1 second to allow the servo to reach the target position
- int positionFeedback90 = analogRead(feedbackPin); // Read the position feedback
- Serial.print("Servo at 90 degrees. Position feedback: ");
- Serial.println(positionFeedback90);
- // Move the servo to 180 degrees
- fs90fb.write(180);
- delay(1000); // Wait for 1 second to allow the servo to reach the target position
- int positionFeedback180 = analogRead(feedbackPin); // Read the position feedback
- Serial.print("Servo at 180 degrees. Position feedback: ");
- Serial.println(positionFeedback180);
- delay(2000); // Wait for 2 seconds before repeating the loop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement