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 در اَمه زون آلمانamazon.de
-
آمازونسروو SG90 در اَمه زون ایتالیاamazon.co.uk
منابع و مراجع
-
خارجیسرور SG90 در اَمه زون آمریکاamzn.to
-
خارجیسرور SG90 در اَمه زون فرانسهamzn.to
-
خارجیسرومو SG90 در اَمه زون اسپانیاamzn.to
-
خارجیسروو SG90 در اَمه زون آلمانamazon.de
-
خارجیسروو SG90 در اَمه زون ایتالیاamazon.co.uk
-
خارجیسروو SG90 در اَمه زون کاناداamzn.to
-
خارجیسرووهای SG90amzn.to
-
داخلی
-
داخلی
فایلها📁
هیچ فایلی موجود نیست.