Andrew Hillier
Published © GPL3+

Servo Tuning Buttons

I have a project that will require three servo positions, and I need to be able to easily go between them for system tuning.

BeginnerWork in progress15 minutes3,029
Servo Tuning Buttons

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Resistor 10k ohm
Resistor 10k ohm
×4
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Servos (Tower Pro MG996R)
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1

Story

Read more

Schematics

Wiring Diagram

This is the wiring for the push buttons, pull down resistors, and servomotor.

Code

Servo Buttons Code

Arduino
This is the code for the Arduino R3 Uno (or knock off) to allow for button presses to dictate servo position.
/* gripper test program

  This program sets up 4 buttons on pull down resistors to set 4 servo positions
  Grab lowers the magnet arm
  Hold sets the magnet arm to its home position
  Drop releases the steel ball from the magnet
  Couple sets the servo position to 180 deg. and allows for the shaft coupler
  to be attached. 
  
  *** NOTE: Disconnect power after positioning to the coupler 
  position to allow positioning of the magnet arms in the housing bore.
  After positioning of magnet arms, activate the home button and resupply power
  to the servo. Verify positions are correct and adjust angles accordingly. ***
  
 */

#include <Servo.h>

Servo gripper;  // create servo object to control the gripper servo

const int grabPin = 13; // Define the grab sequence button pin
const int holdPin = 12; // Define the hold sequence button pin
const int dropPin = 11; // Define the drop sequence button pin
const int couplePin = 10; // Define the coupling sequence button pin

// Initialize button status

int grab = 0;
int hold = 0;
int drop = 0;
int couple = 0;

// Set servo angles

int grabPos = 81;
int holdPos = 90;
int dropPos = 100;
int couplePos = 180;

void setup() {
  
  gripper.attach(9);  // Attach servo to pin 9
  
  // Setup button pins as inputs
  pinMode(grabPin, INPUT);
  pinMode(holdPin, INPUT);
  pinMode(dropPin, INPUT);
  pinMode(couplePin, INPUT);
}

void loop() {

  // Monitor for button presses
  grab = digitalRead(grabPin);
  hold = digitalRead(holdPin);
  drop = digitalRead(dropPin);
  couple = digitalRead(couplePin);

  // Go to activated position
  if (grab == HIGH){
    gripper.write(grabPos);
  }
  if (hold == HIGH){
    gripper.write(holdPos);
  }
  if (drop == HIGH){
    gripper.write(dropPos);    
  }
  if (couple == HIGH){
    gripper.write(couplePos);
  }
}

Credits

Andrew Hillier

Andrew Hillier

1 project • 6 followers
Mechanical Engineering Student at UNC Charlotte.

Comments

Add projectSign up / Login