Sunday, August 2, 2020

2 Servos motors for tiny robotic arm

Americans, at least Texans say you can do anything with duct tape and baling wire.  
Add Popsicle sticks for crafts. 
Tiny Robot Arm - good for first code tests
 [This a very simple robot arm. Google "Arduino Popsicle stick robotic arm" for more ideas.]

Servo Motor Overview:

Parts needed:

  • Arduino Uno
  • small breadboard
  • ~14 male to male breadboard jumpers
  • 2 servo motors
    • Tower pro micro servo 9G
    • servo motor small 2 sided attachment (screw to 2nd servo motor)
  • 2 potentiometers
    • any potentiometer with 3 pins that will go on a breadboard will work
    • may use 3 male to female breadboard jumpers to connect potentiometer to breadboard
  • 2 220 Ohm resistors
  • PNP (voltage changer)
    • Bridgold TIP 32C Tip32 PNP Bipolar(BJT) single Transistor, General Purpose, 100V/2A, TO-220AB
  • 1 9V battery
  • 2 half Popsicle sticks
  • electric tape
    • to secure servo motor to base  & half Popsicle sticks
  • base (screw bottom servo motor to)

Wiring



Observation:

The potentiometers do not always go from 0-1023 as shown in Arduino examplesservo > motorknob code, but the max value is specific to the voltage (3.3V or 5V) and something else unknown at moment. But it is repeatable. So the max for potentiometer is calculated in code below. In theory that code should not be needed.

Program

#include<Servo.h>

Servo bottom;
Servo robotArmMotor;

int delayT = 15;

// Can use constants like A0 and A1 for pin # or just 0 or 1. No difference, 
//    but analog pins actually start with pin # 14=A0
int pb  =A0; // or 0 analog pin 0 (A0) used to connect bottom servo to its potentiometer
int p_arm  = A1; // or 1 analog pin 1 (A1) used to connect robot arm  servo to its potentiometer

// measures max for potentiometers, but MUST rotated from min to max initially to work right!

// Set to 0 to measure max 
int pb_maxVal = 0; 
int p_arm_maxVal = 0; 

int val=0; // // variable to read the value from the analog pin
void setup() {
bottom.attach(9); // attaches the bottom servo on pin 9  to the Servo object bottom
robotArmMotor.attach(10);// attaches the robot arm servo on pin 10 to the Servo object robotArmMotor
Serial.begin(9600);
}

// Max from potentiometer is unknown, so when start move potentiometer knob to max 
//   then this code will return the max 
int potentioMax(int val, int p_maxVal) {  
    if (val > p_maxVal) p_maxVal = val;  // sets potentiometer read max
     Serial.println(val);
    Serial.println(p_arm_maxVal);
    return p_maxVal;
}

void loop() {
  val = analogRead(pb);
  pb_maxVal = potentioCalibrate(val, pb_maxVal);
  val = map(val, 0, pb_maxVal, 0, 180); // scale it by mapping 0-max to 0-180 
  robotArmMotor.write(val);               // moves the robotArmMotor servo to position
  delay(delayT);                                          // waits for the servo to get there  
    
  val = analogRead(p_arm);
  p_arm_maxVal = potentioCalibrate(val, p_arm_maxVal);
  val = map (val, 0, p_arm_maxVal, 0, 180);  // scale it by mapping 0-max to 0-180 
  robotArmMotor.write(val);                    // moves the robotArmMotor servo to position 
  delay(delayT);                        // waits for the servo to get there
                          
}

No comments:

Post a Comment

Arduino and pump

Motor Driver witn 9110 or 9110S  https://www.laskakit.cz/user/related_files/l9110_2_channel_motor_driver.pdf https://docs.sunfounder.com/pro...