How to Control Multiple Servo Motors Using One Potentiometer with Arduino
Learn how to control multiple servo motors using one potentiometer with Arduino. Wiring is shown, the code is explained, and it is demonstrated at the end. The code link is below the video's chapter timestamps.
350-Code using one potentiometer to control as many servos as you want
语言: C++
/*
* Original code from File->Examples->Servo->Knob
*
* This is Arduino code to use one potentiometer (variable resistor) to control multiple servo motors
* Please watch video instruction https://youtu.be/QB49Rmc96Ho
* Updated from original code by
* Ahmad Shamshiri on October 27, 2020 at 23:01 in Ajax,
* Ontario, Canada
* www.robojax.com
*
Controlling a servo position using a potentiometer (variable resistor)
by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
modified on November 8, 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Knob
* Get this code and other Arduino codes from Robojax.com.
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place.
If you found this tutorial helpful, please support me so I can continue creating
content like this.
or make a donation using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <Servo.h>
Servo myservo1; // create servo 1 object to control a servo
Servo myservo2; // create servo 2 object to control a servo
//Servo myservo3 //create servo 3 object
int potpin = A0; // analog pin used to connect the potentiometer
unsigned int servoPin[]={5,6};//watch video for details https://youtu.be/QB49Rmc96Ho
int val; // variable to read the value from the analog pin
void setup() {
Serial.begin(9600);
Serial.println("Multiple Servo");
Serial.println("Robojax.com");
myservo1.attach(servoPin[0]); // attaches the servo 1 to the servo object
myservo2.attach(servoPin[1]); // attaches the servo 2 to the servo object
//add line for more servos watch video for details https://youtu.be/QB49Rmc96Ho
}
void loop() {
//watch video for details https://youtu.be/QB49Rmc96Ho
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo1.write(val);
myservo2.write(val);
Serial.print(val);
Serial.println();
// sets the servo position according to the scaled value
delay(20); // waits for the servo to get there
//robojax.com code //watch video for details https://youtu.be/QB49Rmc96Ho
}
|||您可能需要的东西
-
亚马逊SG90 servo on Amazon Germanyamazon.de
-
亚马逊SG90 servo on Amazon Italyamazon.co.uk
资源与参考
-
外部SG90 servo on Amazon Canadaamzn.to
-
外部SG90 servo on Amazon Franceamzn.to
-
外部SG90 servo on Amazon Germanyamazon.de
-
外部SG90 servo on Amazon Italyamazon.co.uk
-
外部SG90 servo on Amazon Spainamzn.to
-
外部SG90 servo on Amazon USAamzn.to
-
外部SG90 servosamzn.to
文件📁
没有可用的文件。