ARID ZONE JOURNAL OF ENGINEERING, TECHNOLOGY & ENVIRONMENT AZOJETE, March, 2019. Vol. 15(1):67-76 Published by the Faculty of Engineering, University of Maiduguri, Maiduguri, Nigeria. Print ISSN: 1596-2490, Electronic ISSN: 2545-5818 www.azojete.com.ng 67 ORIGINAL RESEARCH ARTICLE MODEL DESIGN, SIMULATION AND CONTROL OF A ROBOTIC ARM USING PIC 16F877A MICROCONTROLLER A. B. Buji, Y. P. Mshelia, A. G. Ibrahim and M. A. Sarki Department of Electrical and Electronics Engineering, University of Maiduguri, Maiduguri, Nigeria *Corresponding Author: babuji@unimaid.edu.ng ARTICLE INFORMATION Submitted 28 March, 2018 Revised 15 December, 2018 Accepted 19 December, 2018 Keywords: Microcontroller Programmable Integrated Circuit Servo Motor Pulse Width Modulation Robotic ABSTRACT This paper focuses on model design, simulation and control of a five degree of freedom (DoF) robotic arm using servo motors. The robotic arm is controlled by a PIC 16F877A microcontroller and its main function is to generate pulse width modulation (PWM) signals which are applied to the servo motors for achieving the desired rotation angle. A PWM signal could have different effects on various servo motors depending on their specifications. Thus, it is important to apply the exact PWM signals to achieve the rotation angle desired. The main advantage of controlling the servo motors with PWM signals is that they can be programmed to have an initial position and to rotate with an exact degree with respect to the requirements. A general formula is derived for finding the pulse width required to achieve the desired rotation in each servo motor. The main advantage of this formula is that it can be used for any servo motor with different specification. Simulation results presented showed that for PWM signal (P) a difference of 0.45 µ s to 1.45µs and angle rotation difference of 0.04º to 0.11º were obtained. The results obtained from the derived equation is found to have 98% accuracy compared to the simulation results. © 2019 Faculty of Engineering, University of Maiduguri, Nigeria. All rights reserved. 1.0 Introduction Robot is an automatically controlled material handling unit that is widely used in the manufacturing industry. It is generally used for high volume production and better quality. The word 'robot' first appeared in 1921 in the Czech playwright Karel Capek's play "Rossum's Universal Robots'. The word is linked to Czech words Robota (meaning work) and Robotnik (meaning slave) (Rao et al., 2001) International Organization for Standardization (ISO) defines a robot as an automatically controlled, reprogrammable, multipurpose, manipulative machine with several reprogrammable axes, which is either fixed in place or mobile for use in industrial automation application. Robots are indispensable in many manufacturing industries. The reason is that the cost per hour to operate a robot is a fraction of the cost of human labor needed to perform the same function. More than this, once programmed, robots repeatedly perform functions with a high accuracy that surpasses that of the most experienced human operator. However, human operators are far more versatile. Humans can switch job tasks easily. Robots are built and programmed to be job specific but as robots evolve, they will become more versatile, emulating the human capacity and ability to switch job tasks easily (Ishak S.H., 2011). The robots play important roles in our lives and are able to perform the tasks which cannot be done by humans in terms of speed, accuracy and difficulty. (Lin et al,2011) stated that robots can be employed to imitate human behaviors and then apply these behaviors to the skills that allow the robot to achieve a certain task. Robotics is applied in different forms and fields to simulate human behavior and motions (Nikku S., 2011), and this fact allows the workers to have more free time to spend on skilled professions including the programming, maintenance and operation of the robots which are essential (Robotics, 2017). In this paper, servo motors are used for robotic arm joint actuators and are controlled by using PWM signals generated by the PIC 16F877A microcontroller. Mikro C PRO is used to program the microcontroller and control switches are used to command PIC microcontroller which is connected to robotic arm. Robotic arm movement can be done by moving to the left or right. The robotic arm will be controlled via the controller and it will be able to grab, pick up, move and place objects according to their weights and shape in different places. The manipulator design is mostly expected to pick up cubes and the geometric shapes like a box. This robotic arm operates using 5 servo motors thus it has 5 Degree of Freedom. 2. Materials and Methods 2.1 Design of Robotic Arm The Robotic arm design involves mathematical modeling of the kinematics, structure design, electronic design and software design (Nones, 2003). Inverse kinematics is used for the kinematic modeling analysis algorithm and plastic sheets are recommended for the structure design. 2.1.1 Mathematical model of the kinematics mailto:babuji@unimaid.edu.ng http://www.azojete.com.ng Buji et al: Model Design, Simulation and Control of a Robotic Arm using PIC 16F877A Microcontroller. AZOJETE, 15(1):67-76. ISSN 1596- 2490; e-ISSN 2545-5818, www.azojete.com.ng 68 Robot arm kinematics deals with the analytical study of geometry motion of robot arm from fixed reference of co-ordinate system as a function of time without regard to movements that cause the motion. Articulated 5-DOF robotic arm is designed by direct and inverse kinematic analysis methods (Patil and Lakshminarayan, 2012). 2.1.2 Direct kinematic analysis Direct kinematics usually refers to home position of geometric link parameters. It is used to find the position and orientation of end effector with respect to the base with the help of Denavit-Hartenberg algorithm used to obtain modeling equations (Patil. and Lakshminarayan, 2012). This method is not discussed in this paper. 2.1.3 Inverse kinematics analysis Inverse kinematics usually refers to position and orientation of end effector. It helps to find joint variables to achieve correct position of source location part. In order to control the position and orientation of end effector of a robotic arm to reach its object, the inverse kinematic solution is more important. In this paper, inverse kinematics problem is solved by geometric approach method (Patil. and Lakshminarayan, 2012).. This method provides more insight to solving simple manipulators with rotary joints. The robotic arm has a total of five axes. Three major axes which correspond to the base, shoulder and elbow are needed to move the arm to the desired spot and two minor axes which correspond to the gripper pitch and gripper spin. The design has six rotary joints. Although we consider the number of joints as five because two joints that move the shoulder, rotate in the same direction with the same speed. Therefore, they are counted as one joint. Figure 1.0 shows the precise link coordinate diagram of axes and joints (Seki et al, 2012). Figure 1. Link coordinates of axes and joints of the proposed robot design. The parameters and kinematic equations of the robotic arm can be written as follows; L0 to L5 – Six unit frames 5 – Gripper length 1to 5 – Joint variables ( = ) – Gripper spin 1 – Height of shoulder from base x0 to x5 – Motion of base, shoulder elbow, gripper pitch and spin in x direction y0 to y5 – Motion of base, shoulder elbow, gripper pitch and spin in y direction z0 to z5 – Motion of base, shoulder elbow, gripper pitch and spin in z direction 1,2, … ,5 – Rotary joints 2, 3, 4 – Link lengths Base: 1= 1 (1) where: θ1= tan−1 y0 x0 and [−2 ≤ θ1≤ 2 ] for full clockwise and counter clockwise rotation. Shoulder: xshoulder = (x1)2 + (y1)2 (2) zshoulder = z1 − d1 (3) yshoulder = xshoulder − d2 (4) h = (xshoulder)2 + (zshoulder)2 (5) http://www.azojete.com.ng Arid Zone Journal of Engineering, Technology and Environment, March, 2019; Vol. 15(1):67-76. ISSN 1596-2490; e-ISSN 2545-5818; www.azojete.com.ng Corresponding author’s e-mail address: gbengailori@unilag.edu.ng 69 θ2 = tan−1 zshoulder xshoulder − cos−1 Ll 2+ Lu 2−h2 2LlLuh and [π 6 ≤ θ2 ≤ 2π 3 ] For: (Ll=Lower Link, Lu= Upper Link, ℎ = Height of shoulder from base) for the rotation from 30° to 120°. Elbow: θ3 = cos−1 (Ll)2+ Lu2 − h2 2LlLuh (6) Where [ 7π 6 ≤ θ3 ≤ π 3 ] , for the rotation from 60o to 120o. Gripper Pitch: θ4 =− θ2 − θ3 (7) Where: [− π 4 ≤ θ4 ≤ π 4 ], for the rotation from − 45o to 45o. Gripper Spin: θ5 = cos−1 Ll 2+ (Lu)2−h2 2LlLuh (8) Where: [− π 4 ≤ θ5 ≤ π 4 ], for the rotation from − 45o to 45o. A model design of the robotic arm structure according to the schematic and kinematic presentation was carried out using Auto CAD design software. The model design is shown in Figure 2. Figure 2: Model Design of Robotic Structure as carried out using Auto CAD Electrical Circuit Design The electrical circuit of a static robotic arm consists mainly of the Joint Actuators (RC servo motors), the Controller (this is achieved by PIC 16F877A microcontroller) and the power supply. A block diagram of the robotic circuit is shown in Figure 3. Figure 3: Block diagram of robotic circuit 2.3.1 Servo Motors Servo refers to an error sensing feedback control which is used to correct the performance of a system. Servo or Radio Controlled Servo Motors are DC motors equipped with a servo mechanism for precise control of angular position. The RC servo motors usually have a rotation limit from 90° to 180°. Servo motor is a geared DC motor with positional feedback that allows rotor to be positioned accurately (Ibrahim, 2006). Internally, a servo consists of DC motor, potentiometer and control circuit as shown in Figure 4. file:///C:/Users/user/Downloads/azojete143/www.azojete.com.ng Buji et al: Model Design, Simulation and Control of a Robotic Arm using PIC 16F877A Microcontroller. AZOJETE, 15(1):67-76. ISSN 1596- 2490; e-ISSN 2545-5818, www.azojete.com.ng 70 Figure 4: Servo Motor and its components The control circuitry compares an angular position, determined by a control signal, to the current position of the motor shaft as shown in figure 5. The motor shaft’s angular position is often determined by a potentiometer, which is rotated by the motor shaft. A potentiometer is a three terminal resistor, whose center connection has variable resistance, usually controlled by a slider or dial. The potentiometer acts as a variable voltage divider. The voltage from the center connection of the potentiometer represents the angular position the motor shaft is in. The built-in controller generates an internal signal from the voltage controlled by the potentiometer, compares it to the control signal, and then provides power to the dc motor to rotate the shaft in the appropriate direction to match the two. Figure 5: Signal flow diagram of the control circuitry of a servo motor 2.3.2 PIC 16F877A Microcontroller PIC 16F877A microcontroller has 40 pins and is a popular microcontroller capable of doing complex tasks. This microcontroller has 8192 × 14 flash program memory which consists of 368 bytes of RAM and 256 bytes of non-volatile EEPROM memory. 33 pins are dedicated for input/output pins and 8 multiplexed analog/digital converters with 10 bits resolution. This microcontroller also has specifications such as PWM generator, 3 timers, analog capture and comparator circuit, universal synchronous receiver transmitter (USART), internal and external interrupt capabilities. The operating voltage for the microcontroller is 2.0V to 5.56V DC and operates at an external oscillator frequency in the range of 0Hz to 20Hz. Figure 6 and 7 shows the pin configuration of the PIC 16F877A microcontroller and the pins which are used for PWM generation are marked (Ibrahim, 2006). PIC 16F877A was chosen for this design because it size of 368 bytes and additional 256 bytes of non-volatile EEPROM. It also has high clock speed of up to 4MHz, and it is cheap. Figure 6: PIC 16F877A Microcontroller http://www.azojete.com.ng Arid Zone Journal of Engineering, Technology and Environment, March, 2019; Vol. 15(1):67-76. ISSN 1596-2490; e-ISSN 2545-5818; www.azojete.com.ng Corresponding author’s e-mail address: gbengailori@unilag.edu.ng 71 Figure 7: PIC 16F877A pin configuration Software Design There are variety of programming languages and compilers such as Assembly, BASIC, PASCAL, C and C++. In this paper, Mikro C PRO for PIC compiler (C language) is used to generate HEX files for programming the microcontroller. When the HEX code is ready, it can be written on the EPROM of the microcontroller. Implementation Each servo motor was operated manually with two buttons for rotation and automatically controlled with two buttons and each input control button causes the microcontroller to generate the necessary PWM signal and send it to the corresponding servo motor, all these are shown in the figure below. The servo motor which was responsible for the rotation of the base (S1) was connected to Port D.0 of the microcontroller. Two servos which are responsible for the motion of the shoulder (S2 and S3) were connected to Port D.1 of the microcontroller. The servo motor responsible for the rotation of the elbow (S4) was connected to Port D.2 of the microcontroller. The servo motor for the gripper pitch (S5) is connected to Port D.3 of the microcontroller. The corresponding servo motor for the gripper spin (S6) was connected to the Port D.4 and the gripper servo (S7) was connected to Port D.5 which was responsible for opening and closing the end-effector. Figure 8: Schematic diagram of user controlled robotic arm circuit Simulation Results Proteus simulation software was used to design a virtual circuit containing PIC 16F877A microcontroller and the servo motors used to design the robotic arm (Tower-pro SG-90 and Futaba S3003). This was done to simulate and analyze the results on the effects of Pulse Width Modulation (PWM) signals on the servo motors for adequate and optimum control as shown in figure 9. file:///C:/Users/user/Downloads/azojete143/www.azojete.com.ng Buji et al: Model Design, Simulation and Control of a Robotic Arm using PIC 16F877A Microcontroller. AZOJETE, 15(1):67-76. ISSN 1596- 2490; e-ISSN 2545-5818, www.azojete.com.ng 72 Figure 9: Virtual implementation of Robotic Circuit in Proteus. Since there are two types of servos with different specifications in the robotic arm design, the results obtained from the simulation on Proteus differ in terms of pulse width, angle and the general servo motor behavior. The simulation considers the rotation angle with respect to the generated pulses with the pulse width ranges from 600µs to 2400µs for Futaba S3003 and from 400µs to 2400µs for Tower- Pro SG-90 servo. 4.0 Simulation and Calculation results for TOWER-PRO SG-90 Table 1: Simulation and calculation results for Tower Pro SG-90 servo motor Table 2: Simulation and Calculation results for Futaba S3003 Servo motors Simulation Result in progression Simulation Results in Random Results obtained from Derived Equation PWM (μs) ANGLE (°) PWM (μs) ANGLE(°) PWM (μs ) from Angle Angle( °) from PWM 800 -53.9 450 -85.4 451.11 -85.50 810 -53.0 570 -74.6 571.11 -74.70 820 -52.1 675 -65.2 675.55 -65.25 830 -51.2 891 -45.7 892.22 -45.81 840 -50.3 1287 -10.1 1287.77 +10.17 850 -49.4 1576 +15.9 1576.66 +15.84 860 -48.5 2070 +60.4 2071.11 +60.30 870 -47.6 2222 +74.1 2223.33 +73.98 Simulation Result in progression Simulation Results in Random Results obtained from Derived Equation PWM (μs) Angle (°) PWM (μs) Angle (°) PWM( μs ) from Angle Angle( °) from PWM 800 -69.9 600 -89.9 601 -90.0 810 -68.9 653 -84.6 654 -84.7 820 -67.9 675 -82.4 676 -82.5 830 -66.9 891 -60.8 892 -60.9 840 -65.9 1287 -21.2 1288 +21.3 850 -64.9 1576 +7.70 1577 +07.6 860 -63.9 2070 +57.1 2071 +57.0 http://www.azojete.com.ng Arid Zone Journal of Engineering, Technology and Environment, March, 2019; Vol. 15(1):67-76. ISSN 1596-2490; e-ISSN 2545-5818; www.azojete.com.ng Corresponding author’s e-mail address: gbengailori@unilag.edu.ng 73 Observations From Table 4.1, the comparison between calculated and simulation results for SG-90 servo shows that: For PWM signal (P) a difference of 0.45μs to 1.45μs was presented. For rotation Angle (θ) of the servo motor a difference of 0.04° to 0.11° was presented. From Table 4.2, the comparison between calculated and simulation results for S3003 shows that: For PWM signal (P) a difference of 1μs was presented. For rotation Angle (θ) of the servo motor a difference of 0.1° was presented. As seen in the Table 4.1 and 4.2, both servos have a stable response to their PWM signals. Thus, rotation angle of the servo motors increases proportionally to increase of the PWM signals. By considering the accuracy and comparisons of the equation results and simulation results, a general formula for any servo can be derived to find the required PWM input signal. Px = θ+ ε 2 ε Pm − Po − PO For: − 90 < θ <+ 90 where: Px is the Pulse Width signal required, θ is the Angle required, ε is the maximum rotation angle range of servo. Pm is the maximum Pulse width required by servo motor, Pois the minimum Pulse width required by servo motor. Conclusion In this paper, the procedure of designing and simulating an articulated robotic arm using a microcontroller and servo motors with the help of PWM was shown. The effect of pulses on the servo motors using software simulation were shown and discussed. A general formula which facilitates the design and motion control of the robotic arm has also been proposed. The accuracy of the proposed formula can be obtained as almost 98%, this means that the rotation of the servo can possibly have 2% error comparing to the expectations. References http://www.robotics.org/content-detail.cfm/Industrial-Robotics-FeaturedArticles/How-Robots-Will- Affect-Future Generations/content_id/834 Ibrahim, D. 2006. “30 Projects Using PIC Basic and PIC Basic Pro”, UK: MPG books Ishak, SH. 2011. Design of Robotic Arm Controller Using Matlab, Malaysia. Lin, IH., Liu, CY. and Chen, LC. 2011 "Evaluation of Human-Robot Arm Movement Imitation", Proceedings of 8th Asian Control Conference (ASCC), pp.287-292. Nikku, S. 2011. “Introduction to Robotics”, USA: John Wiley & Sons. Nones, YA. 2003. “Heterogeneous Modeling & Design of a Robot Arm Control System”, Illinois Tech Robotics (ITR), pp.1-6. Rao, PN., Ahmad, A., Omar, AR. And Ayub, MA. 2001. Design and Fabrication of a Robotic Arm for Material Handling,Malaysia. Seki, K., Yokoi, H. and Iwasaki, M. 2012. “Experimental Evaluations of Friction Behavior in Micro- Displacement Region Positioning for Servo Motor with Air Bearings” Proceeding of IEEE International Conference on Advanced Intelligent Mechatronics, pp.731-736. Patil, S. and Lakshminarayan, S. 2012. “Position Control of Pick and Place Robotic Arm”, EIE 2nd International Conference on Computers, Energy, Networking, Robotics and Telecom LAO. 2008. Thermal properties of guna seed. International Agrophysics, 22: 291-297. 870 -64.3 2222 +72.3 2223 +72.2 http://www.robotics.org/content-detail.cfm/Industrial-Robotics-FeaturedArticles/How-Robots-Will-Affect-Future%20Generations/content_id/834 http://www.robotics.org/content-detail.cfm/Industrial-Robotics-FeaturedArticles/How-Robots-Will-Affect-Future%20Generations/content_id/834 file:///C:/Users/user/Downloads/azojete143/www.azojete.com.ng Buji et al: Model Design, Simulation and Control of a Robotic Arm using PIC 16F877A Microcontroller. AZOJETE, 15(1):67-76. ISSN 1596- 2490; e-ISSN 2545-5818, www.azojete.com.ng 74 Bamgboye, AI. and Adejumo, OI. 2010. Thermal properties of roselle seeds. International Agrophysics, 24: 85-87. Cansee, S., Watyotha, C., Thivavarnvongs, T., Uriyapongson, J. and Varith, J. 2008. Effect of temperature and concentration on thermal properties of cassava starch solutions. Songklanakarin Journal of Science and Technology, 30(3): 405 - 411. Donsi, G., Ferrari, G and Nigro, R. 1996. Experimental determination of thermal conductivity of apple and potato at different moisture contents. Journal of Food Engineering, 30: 263-268. Enwere, JN. 1998. Foods of plant origin. Afro-Orbis Publications, Nsukka, Nigeria. 64-124. Njie, DN., Rumsey, TR. and Singh, RP. 1998. Thermal properties of cassava, yam and plantain. Journal of Food Engineering, 37(1): 63-76. Odebunmi, EO., Oluwaniyi, OO., Sanda, AM. and Kolade, BO. 2007. Nutritional compositions of selected tubers and root crops used in Nigerian food preparations. International Journal of Chemistry, 17(1): 37-43. Odeku, OA., Awe, OO., Popoola, B., Odeniyi, MA. and Itiola, OA. 2005. Compression and mechanical properties of tablet formulations containing corn, sweet potato, and cocoyam starches as binders. Pharmaceutical Technology, 29(4): 82-90. Onwuka, NO. and Eneh, OC. 1998. The potentials of cocoyam (Colocasia) in stout beer brewing. Journal of Science and Technology, 4: 78-80. Onyeka, J. 2014. Status of cocoyam (Colocasia esculenta and Xanthosoma spp) in West and Central Africa: Production, household importance and the threat from leaf blight, Lima (Peru). CGIAR Program on Roots, Tubers and Bananas (RTB). www.rtb.cgiar.org Singh, KK. and Goswami, TK. 2000. Thermal properties of cumin seed. Journal of Food Engineering, 45:181-187. Taiwo, KA., Akanbi, CT. and Ajibola, OO. 1996 Thermal Properties of Ground and Hydrated Cowpea. Journal of Food Engineering 29: 249-256 Yang, W., Sokhansanj, S., Tang, J. and Winter, P. 2002. Determination of thermal conductivity, specific heat and thermal diffusivity of borage seeds. Biosystems Engineering, 82(2): 169–176. Zhu, S., Ramaswamy, HS., Marcotte, M., Chen, C., Shao, Y. and Le Bail, A. 2007. Evaluation of thermal properties of food materials at high pressures using a dual-needle line-heat-source method. Journal of Food Science, 72: 49–56. http://www.rtb.cgiar.org http://www.azojete.com.ng