element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Twist, Turn and Move Design Challenge with TE Robotics
  • Challenges & Projects
  • Design Challenges
  • Twist, Turn and Move Design Challenge with TE Robotics
  • More
  • Cancel
Twist, Turn and Move Design Challenge with TE Robotics
Blog Blog #2: TTM Design challenge - Creating a Robot Arm with Scavenged Parts
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Leaderboard
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: hitesh.boghani
  • Date Created: 28 Sep 2022 12:07 AM Date Created
  • Views 869 views
  • Likes 7 likes
  • Comments 4 comments
  • robots
  • te connectivity
  • Twist Turn and Move Robotics Design Challenge
Related
Recommended

Blog #2: TTM Design challenge - Creating a Robot Arm with Scavenged Parts

hitesh.boghani
hitesh.boghani
28 Sep 2022

Let's meet the arm (or rather arm joint) of the robot that doesn't exist as of yet!

Mechanical assembly of robot arm

I had some printer parts (motors, gears, sheet metal parts) that I wanted to use to create this robot. Also, I had thought of using the scanner (moving bit) to use as an arm/leg but that didn't work out very well. This is because after experimenting, I found that the power supplied to the motor wasn't enough to generate enough torque to overcome the inertia of the whole part.

image image image

So, I had to use slightly bigger motor and make the arm from other parts. I found a DC motor, metal brackets, and plastic gears. I had bought some encoders and potentiometers to use as angular sensors in this project so that came in handy when I wanted to build this arm.

image image

So anyways, after spending a few hours, I made an assembly that looks like shown in the pictures below. The spoon kind of thing in the pitcure is meant to be an arm which is also sourced from one of the dismantled printers! Smiley

image image

Now, let's talk about the code.

Code for controlling the arm

I used Arduino Uno as the main control computer for the robot arm and used the shield DFR0502 provided in the kit. Details for the shield are here: https://wiki.dfrobot.com/Gravity_IO_Expansion_%26_Motor_Driver_Shield_V1.1_SKU__DFR0502

There was some inconsistency regarding the motor function which I had to debug and now corrected in my code below. The wiring is quite straight forward as shown in their link and additionally, I hooked up the potentiometer to A0 on Arduino Uno.

I had tried to use PID controller for this arm. However, after much debugging on why it didn't perform as it should, I found that the motor didn't respond very well with PWM output of lower than 220 (out of scale 0 - 255 on Arduino Uno). This made it difficult for me to implement variable power input into the motor as per the error given by the difference between the setpoint (set angle) and actual point (angle). So finally, I ended up using just a bang bang control structure with a band where the motor was kept idle. I used band of inactivity to avoid motor hunting around the setpoint when it doesn't quite reach there and overshoots above and below it with the given power to the motor. Anyways, here is the code which I will explain below.

/*
* Project: element14 community - twist, turn and move design challenge
  Author: Hitesh Boghani
*/

#define POT1 0

int potVolts;
int error;
int setPoint = 800;

void motor_c(char motor_n, char direction_m, int speed_m) /* motor_n: the motor number to drive(0 stands for M1;1 stands for M2)*/
/* direction_m : the motor rotary direction(0 is clockwise and 1 is counter-clockwise).*/
/* speed_m: to control the motor rotation speed(from 0 to 255 ), the speed_m value is larger, the rotation speed is faster;*/
{
  if (motor_n == 0) {
    if (direction_m == 1) {
      digitalWrite(4, HIGH);    // pin 4 controls M1 rotary direction
      analogWrite(5, speed_m);  //pin 5 controls M1 rotation speed
    } else {
      digitalWrite(4, LOW);
      analogWrite(5, speed_m);
    }
  } else {
    if (direction_m == 1) {
      digitalWrite(7, HIGH);    // pin 7 controls M2 rotary direction
      analogWrite(6, speed_m);  //pin 6 controls M2 rotation speed
    } else {
      digitalWrite(7, LOW);
      analogWrite(6, speed_m);
    }
  }
}

void setup() {
  Serial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    setPoint = Serial.parseInt();
    Serial.println(setPoint);
  }

  potVolts = analogRead(POT1);
  error = setPoint - potVolts;
  Serial.print("Error is: "); Serial.println(error);

  if (error < -10) {
    motor_c(0, 0, 255); // go backwards
    Serial.println(". So, going backwards");
  }
  if (error > 10) {
    motor_c(0, 1, 255); // go forwards
    Serial.println(". So, going forwards");
  }
  if (error <= 10 && error >= -10) {
    motor_c(0, 1, 0);
  }

  delay(1);

}

After the usual definitions and declarations, I have copied DFRobot's function to control the motor. It makes things easier because it handles the direction, speed and output pins. You will notice that I have changed line 16 from

if (motor_n == 1) {
to
if (motor_n == 0) {

This basically made sure that motor 1 outputs were getting activated correctly as per the board markings as opposed to motor 2.

In line 40 - 43, the program is looking at the input given via serial comms and parsing integer from it to use as setpoint. There should be caution provided here that if you are using Arduino IDE's serial monitor then 'No Line Ending' should be selected. This is because, in my experience, I found that the integer parser was getting 0 because of line ending and it was setting the setpoint to 0 in the next sampling period. So, choosing the 'No Line Ending' option will avoid this issue.

Line 49 - 59 is effectively the bang bang type controller where if the error is negative, full effort (PWM 255, in direction 0) is applied to drive the error down to zero. If the error is positive, full effort (PWM 255, in direction 1) is applied. So, one can imagine that because of motor+gear+arm inertia, delays in the system and full power, the position will overshoot the desired postion and suddenly the program will apply the opposite direction full force, and so on. This is not desirable. This is why I have put a band in line 57 - 59 where the motor does nothing. This is illustrated with a doodle below where without the hysteresis band, the motor starts hunting around the setpoint and with the band, does not.

image

Of course, it won't be accurate because the motor will stop either too late or too early. Ideally, if precise positioning is desired, PID or other advanced control algorithms should be used. In this scenario though, I didn't have a problem using this controller because it didn't matter if the arm was a couple of degrees off the desired position as this was only intended to show position of the arm in Yoga posture. Please note that I had total increments of 750 from the analogRead for 180 degrees.

OK so now that is enough explanation of the code and reasoning, let's get to action! Here is the video of this arm where I am positioning the arm in several different positions using keyboard entry into the serial monitor.

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

This is for the demonstration purposes only and in future, this will be coordinated movement with other parts of the robot. Additionally, I should mention here that I am going to implement the code in freeRTOS for arduino so that simultaneous movements of the robot joints can be realised.

Stay tuned for more robot limbs and joints! ;)

Previous

  • Sign in to reply
  • DAB
    DAB over 2 years ago

    Nice build, I love reuse projects.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 2 years ago

    Looking good!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • hitesh.boghani
    hitesh.boghani over 2 years ago in reply to dougw

    Thank you! I have drawers full of them especially to make something interesting out of them. :) 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • dougw
    dougw over 2 years ago

    Nice use of scavenged parts.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube