本教程是的一部分: 伺服电机
这里列出了所有与伺服电机相关的视频。其他视频的链接在本文下方。
How to Use Continuous 360° Servo with Arduino
In this tutorial, we will learn how to control a continuous 360° servo using an Arduino. Unlike standard servos, continuous servos can rotate indefinitely in either direction, allowing for versatile applications. However, controlling their position requires understanding the commands sent to them and a bit of experimentation to find the right stopping values.
We will be developing a program that allows us to send commands via the Serial Monitor to rotate the servo left, right, or stop it. The code will include the necessary logic to interpret the ASCII values of the commands we enter. For clarification on the coding process, be sure to check the video at (in video at 12:30).
Hardware Explained
To implement this project, you will need a continuous 360° servo, an Arduino board, and a power supply capable of providing sufficient current (at least 500mA). The servo receives control signals from the Arduino, which uses pulse width modulation (PWM) to dictate the direction and speed of rotation.
The servo motor itself has three wires: power, ground, and control. The power wire connects to the power supply, the ground wire connects to both the power supply and the Arduino ground, and the control wire connects to a designated pin on the Arduino for signal transmission.
Datasheet Details
| Manufacturer | Generic |
|---|---|
| Part number | Continuous 360° Servo |
| Logic/IO voltage | 5 V |
| Supply voltage | 4.8–6 V |
| Output current (per channel) | 500 mA |
| Peak current (per channel) | 1 A max |
| PWM frequency guidance | 50 Hz |
| Input logic thresholds | High: >2.5 V, Low: <0.8 V |
| Voltage drop / RDS(on) / saturation | — |
| Thermal limits | — |
| Package | Standard servo housing |
| Notes / variants | Available in various sizes |
- Ensure a common ground between the Arduino and power supply.
- Use an external power supply for the servo to avoid overloading the Arduino.
- Experiment with stopping values to find the best performance for your servo.
- Monitor the servo temperature during operation to prevent overheating.
- Use a PWM signal to control the speed and direction of the servo.
Wiring Instructions
To wire your continuous 360° servo to the Arduino, start by connecting the servo power wire to an external power supply that provides 5V. The ground wire of the servo should be connected to the ground (GND) pin on the Arduino, ensuring that the power supply and Arduino share a common ground. The control wire of the servo will go to pin 9 on the Arduino, which is where the PWM signal will be sent from.
Double-check that your connections are secure, as loose connections can lead to erratic servo behavior. If your servo is of a type that can be powered directly from the Arduino, you may connect the power wire to the Arduino's 5V pin, but ensure the total current does not exceed what the Arduino can supply.
Code Examples & Walkthrough
The following excerpt demonstrates how to set up the servo and read commands from the Serial Monitor:
#include
Servo myservo; // create servo object to control a servo
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
In this code snippet, we include the Servo library and create a servo object called myservo. We also set up the serial communication at 9600 baud and attach the servo to pin 9.
Next, we have the main loop where we read incoming serial data and control the servo based on the commands:
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
if (incomingByte == 108) { // 'L' command
myservo.write(0); // rotate clockwise
} else if (incomingByte == 114) { // 'R' command
myservo.write(180); // rotate counterclockwise
} else if (incomingByte == 60) { // stop command
myservo.write(60); // stop servo
}
}
}
This code checks if there is any data available in the serial buffer. Depending on the ASCII value of the input (e.g., 108 for 'L' to rotate clockwise, 114 for 'R' to rotate counterclockwise), it sends the corresponding command to the servo.
For complete code and additional details, please refer to the full program loaded below the article.
Demonstration / What to Expect
When you upload the code and open the Serial Monitor, you can enter 'L' to rotate the servo left, 'R' to rotate it right, or other values to experiment with stopping the servo. Expect to find various stopping values, as the servo's behavior may vary based on its quality and design (in video at 18:45).
Be cautious of how the servo reacts to the commands; if it does not stop as expected, try different values until you find the optimal stopping command. This may require some experimentation, especially to avoid overheating the servo.
Chapters
- Introduction (0:00)
- Hardware Explained (1:30)
- Wiring Instructions (3:45)
- Code Walkthrough (5:15)
- Demonstration (18:00)
Resources
- Arduino Servo Library Documentation
- Continuous Servo Manufacturer Datasheets
本教程是……的一部分: 伺服电机
- Controlling a Servo with Push Buttons Using Arduino
- Control a Servo Motor with a Push Button: Move Servo and Return SPB-1
- Control a Servo Motor with a Push Button: Move Servo in One Direction SPB-2
- Controlling a Servo Motor with a Push Button: Move Servo While Button Is Pressed (SPB-3)
- Controlling a Servo with a Potentiometer Using Arduino
- Controlling a Servo with Potentiometer and LCD1602 using Arduino
- 使用红外遥控器和Arduino控制伺服电机
- 使用电位器控制Arduino伺服电机
- 通过手势控制Arduino的伺服位置
- Controlling Two or More Servos with Potentiometers Using an Arduino
- How to Control a 360° Servo with Three Push-Button Switches
- PCA9685 16通道12位伺服控制器V1的Arduino代码和视频
- Build an Arduino Servo Toggle Switch with a Push Button
/*
*
* Demonstration of Controlling Continuous Servo (360 servo)
* This code allows you to control a 360-degree servo by a command from the Serial Monitor.
* this 350 servo motor is a just for fun. it can't be used for real application where you need exact positioning. get stepper motor or expensive servo motor.
*
* Modified by Ahmad Shamshiri for Robojax.com
* on Sunday, July 1, 2018, at 11:09 AM in Ajax, Ontario, Canada
* Watch a video instruction of this project: https://youtu.be/b_xvu6wWafA
* Get this code from Robojax.com
*
Original code by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
Modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
int pos = 0; // variable to store the servo position
int incomingByte = 0; // for incoming serial data
void setup() {
Serial.begin(9600);
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
// send data only when you receive data:
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
Serial.print("received: ");
Serial.print (incomingByte);
if(incomingByte == 108){
Serial.println(" sent 0 Rotating CW ");
myservo.write(0);
}else if(incomingByte == 114){
Serial.println(" sent 180 Rotating CCW ");
myservo.write(180);
}else if(incomingByte == 60){
Serial.println(" sent Stopped ");
myservo.write(60);
}else{
Serial.println(" moving Randomly");
myservo.write(incomingByte);
}
}
}
资源与参考
尚无可用资源。
文件📁
没有可用的文件。