From 1f4d607c66026d13ceb9d0d86f7cbf4aa3fc19ae Mon Sep 17 00:00:00 2001 From: Engineer1999 Date: Wed, 25 Mar 2020 15:44:36 +0530 Subject: [PATCH 1/2] Added-missing-examples-of-Servo-library --- examples/AnalogInput/AnalogInput.ino | 42 ++++++++++++++ .../MultipleServoMotors.ino | 58 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 examples/AnalogInput/AnalogInput.ino create mode 100644 examples/MultipleServoMotors/MultipleServoMotors.ino diff --git a/examples/AnalogInput/AnalogInput.ino b/examples/AnalogInput/AnalogInput.ino new file mode 100644 index 0000000..bcb0775 --- /dev/null +++ b/examples/AnalogInput/AnalogInput.ino @@ -0,0 +1,42 @@ +/* +Controling multiple servo motors using attach() and detach() +by Bhargav Patel + +*/ + +#include + +Servo myservo; // create servo object to control a servo + +void setup() +{ + Serial.begin(9600); // initializing serial communication with 9600 baud rate + myservo.attach(10); // attaches the servo on pin 10 to the servo object + myservo.writeMicroseconds(500); // setting initial angle to 0 (analog value = 500 [any value less than 700]) + +} + +void loop() { + angle = myservo.read(); // read the value of the current angle on servo motor + Serial.print("Inital angle:- "); + Serial.println(angle); // print angle on servo motor + myservo.writeMicroseconds(1000); // setting angle to 45 (analog value = 1000) + delay(1000); // delay of 1 second + + angle = myservo.read(); + Serial.print("Angle at input 1000:- "); + Serial.println(angle); + myservo.writeMicroseconds(1500); // setting angle to 90 (analog value = 1000) + delay(1000); + + angle = myservo.read(); + Serial.print("Angle at input 1500:- "); + Serial.println(angle); + myservo.writeMicroseconds(3000); // setting angle to 180 (analog value = 3000 [any value greater than 2300]) + delay(1000); + + angle = myservo.read(); + Serial.print("Angle at input 3000:- "); + Serial.println(angle); + +} diff --git a/examples/MultipleServoMotors/MultipleServoMotors.ino b/examples/MultipleServoMotors/MultipleServoMotors.ino new file mode 100644 index 0000000..9a297ad --- /dev/null +++ b/examples/MultipleServoMotors/MultipleServoMotors.ino @@ -0,0 +1,58 @@ +/* +Controling multiple servo motors using attach() and detach() +by Bhargav Patel + +*/ + +#include + +Servo myservo; // create servo object to control a servo + +int angle; // variable to read the angle value of servo motor + +void setup() +{ + + + Serial.begin(9600); // initializing serial communication with 9600 baud rate + + myservo.attach(10); // attaches the servo on pin 10 to the servo object + if (myservo.attached()){ // cheack whether servo motor is attached or not + Serial.println("Servo motor attached to pin 10"); + + myservo.write(0); // setting angle of servo motor at 0 degree + delay(1000); // delay of 1 second + myservo.write(90); // setting angle of servo motor at 90 degree + delay(1000); + myservo.write(180); // setting angle of servo motor at 90 degree + delay(1000); + } else{ + Serial.println("Servo motor attachement failed"); + } + + + myservo.attach(12); // attaches the servo on pin 12 to the servo object + if (myservo.attached()){ // cheack whether servo motor is attached or not + Serial.println("Servo motor attached to pin 12"); + + myservo.write(0); + delay(1000); + myservo.write(90); + delay(1000); + myservo.write(180); + delay(1000); + } else{ + Serial.println("Servo motor attachement failed"); + } + + myservo.detach(); // detach the servo motor + if (myservo.attached()){ // cheack whether servo motor is attached or not + Serial.println("Servo motor is still attached"); + } else{ + Serial.println("Servo motor is still detached"); + } + +} + +void loop() { +} From 26ab0ca49962f3e910a25082987ae718d2b5f36e Mon Sep 17 00:00:00 2001 From: Engineer1999 Date: Thu, 26 Mar 2020 15:52:17 +0530 Subject: [PATCH 2/2] Added examples in servo library --- examples/AnalogInput/AnalogInput.ino | 42 --------- .../MultipleServoMotors.ino | 87 +++++++++---------- examples/PWMInput/PWMInput.ino | 59 +++++++++++++ 3 files changed, 101 insertions(+), 87 deletions(-) delete mode 100644 examples/AnalogInput/AnalogInput.ino create mode 100644 examples/PWMInput/PWMInput.ino diff --git a/examples/AnalogInput/AnalogInput.ino b/examples/AnalogInput/AnalogInput.ino deleted file mode 100644 index bcb0775..0000000 --- a/examples/AnalogInput/AnalogInput.ino +++ /dev/null @@ -1,42 +0,0 @@ -/* -Controling multiple servo motors using attach() and detach() -by Bhargav Patel - -*/ - -#include - -Servo myservo; // create servo object to control a servo - -void setup() -{ - Serial.begin(9600); // initializing serial communication with 9600 baud rate - myservo.attach(10); // attaches the servo on pin 10 to the servo object - myservo.writeMicroseconds(500); // setting initial angle to 0 (analog value = 500 [any value less than 700]) - -} - -void loop() { - angle = myservo.read(); // read the value of the current angle on servo motor - Serial.print("Inital angle:- "); - Serial.println(angle); // print angle on servo motor - myservo.writeMicroseconds(1000); // setting angle to 45 (analog value = 1000) - delay(1000); // delay of 1 second - - angle = myservo.read(); - Serial.print("Angle at input 1000:- "); - Serial.println(angle); - myservo.writeMicroseconds(1500); // setting angle to 90 (analog value = 1000) - delay(1000); - - angle = myservo.read(); - Serial.print("Angle at input 1500:- "); - Serial.println(angle); - myservo.writeMicroseconds(3000); // setting angle to 180 (analog value = 3000 [any value greater than 2300]) - delay(1000); - - angle = myservo.read(); - Serial.print("Angle at input 3000:- "); - Serial.println(angle); - -} diff --git a/examples/MultipleServoMotors/MultipleServoMotors.ino b/examples/MultipleServoMotors/MultipleServoMotors.ino index 9a297ad..6957cf2 100644 --- a/examples/MultipleServoMotors/MultipleServoMotors.ino +++ b/examples/MultipleServoMotors/MultipleServoMotors.ino @@ -1,58 +1,55 @@ /* -Controling multiple servo motors using attach() and detach() -by Bhargav Patel - + Example of attach() and detach() + by Bhargav Patel + + Circuit description + +-----------+--------+ +-----------+--------+ + |Servo_1 | Arduino| |Servo_2 | Arduino| + |-----------+--------| |-----------+--------| + |Ground | GND | |Ground | GND | + |Power | 5V | |Power | 5V | + |Signal | D10 | |Signal | D11 | + +-----------+--------+ +-----------+--------+ */ - -#include +#include Servo myservo; // create servo object to control a servo -int angle; // variable to read the angle value of servo motor +int angle; // variable to read the angle value of servo horn -void setup() -{ - - +void setup() { Serial.begin(9600); // initializing serial communication with 9600 baud rate - myservo.attach(10); // attaches the servo on pin 10 to the servo object - if (myservo.attached()){ // cheack whether servo motor is attached or not - Serial.println("Servo motor attached to pin 10"); - - myservo.write(0); // setting angle of servo motor at 0 degree - delay(1000); // delay of 1 second - myservo.write(90); // setting angle of servo motor at 90 degree - delay(1000); - myservo.write(180); // setting angle of servo motor at 90 degree - delay(1000); - } else{ - Serial.println("Servo motor attachement failed"); + if (myservo.attached()) { // check whether servo motor is attached or not + Serial.println("Servo motor attached to pin 10"); + myservo.write(0); // setting angle of servo horn at 0 degree + delay(1000); // delay of 1 second + myservo.write(90); // setting angle of servo horn at 90 degree + delay(1000); + myservo.write(180); // setting angle of servo horn at 180 degree + delay(1000); + } else { + Serial.println("Servo motor attachment failed"); } - - - myservo.attach(12); // attaches the servo on pin 12 to the servo object - if (myservo.attached()){ // cheack whether servo motor is attached or not - Serial.println("Servo motor attached to pin 12"); - - myservo.write(0); - delay(1000); - myservo.write(90); - delay(1000); - myservo.write(180); - delay(1000); - } else{ - Serial.println("Servo motor attachement failed"); + myservo.attach(11); // attaches the servo on pin 11 to the servo object + if (myservo.attached()) { // check whether servo motor is attached or not + Serial.println("Servo motor attached to pin 11"); + myservo.write(0); + delay(1000); + myservo.write(90); + delay(1000); + myservo.write(180); + delay(1000); + } else { + Serial.println("Servo motor attachment failed"); } - - myservo.detach(); // detach the servo motor - if (myservo.attached()){ // cheack whether servo motor is attached or not - Serial.println("Servo motor is still attached"); - } else{ - Serial.println("Servo motor is still detached"); + myservo.detach(); // detach the servo motor + if (myservo.attached()) { // check whether servo motor is attached or not + Serial.println("Servo motor is attached"); + } else { + Serial.println("Servo motor was detached"); } - -} +} void loop() { -} +} diff --git a/examples/PWMInput/PWMInput.ino b/examples/PWMInput/PWMInput.ino new file mode 100644 index 0000000..e73ffc8 --- /dev/null +++ b/examples/PWMInput/PWMInput.ino @@ -0,0 +1,59 @@ +/* + PWM input example for servo motor. + by Bhargav Patel + + Circuit description + +-----------+--------+ + |Servo | Arduino| + |-----------+--------| + |Ground | GND | + |Power | 5V | + |Signal | D10 | + +-----------+--------+ + + Mapping of pulse duration(width) to angle + +-----------------------------+-----------+ + |Pulse duration(micro second) | Angle | + +-----------------------------+-----------+ + | 500 | 0 | + | 1010 | 45 | + | 1480 | 90 | + | 2400 | 180 | + +-----------------------------+-----------+ +*/ + +#include + +Servo myservo; // create servo object to control a servo + +int angle; // variable to read the value of the angle + +void setup(){ + Serial.begin(9600); // initializing serial communication with 9600 baud rate + myservo.attach(10); // attaches the servo on pin 10 to the servo object +} +void loop(){ + myservo.writeMicroseconds(500); // setting PWM to 500 + angle = myservo.read(); // read the value of the current angle of servo horn + Serial.print("Angle at PWM value 500: "); + Serial.println(angle); // print angle of servo horn on serial monitor + delay(2000); // delay of 1 second + + myservo.writeMicroseconds(1010); // setting PWM to 1010 + angle = myservo.read(); + Serial.print("Angle at PWM value 1010: "); + Serial.println(angle); + delay(1000); + + myservo.writeMicroseconds(1480); // setting PWM to 1480 + angle = myservo.read(); + Serial.print("Angle at PWM value 1480: "); + Serial.println(angle); + delay(1000); + + myservo.writeMicroseconds(2400); // setting PWM to 2400 + angle = myservo.read(); + Serial.print("Angle at PWM value 2400: "); + Serial.println(angle); + delay(1000); +}