Webotricks
Published

How to assemble and control a robot arm with an Arduino

In this tutorial, we will learn how to assemble and control a robotic arm with an Arduino.

BeginnerProtip1 hour256
How to assemble and control a robot arm with an Arduino

Things used in this project

Hardware components

Arduino Uno
×1
Servo Motor (SG90)
×1
Jumper Wires
×1

Story

Read more

Code

Code

Arduino
/*Robot arm control with Arduino
   Home Page
*/
 
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
 
Adafruit_PWMServoDriver webotricks = Adafruit_PWMServoDriver();
 
#define servo1 0
#define servo2 1
#define servo3 2
#define servo4 3
 
 
void setup() {
  Serial.begin(9600);
  webotricks.begin();
  webotricks.setPWMFreq(60);
  webotricks.setPWM(servo1, 0, 330);
  webotricks.setPWM(servo2, 0, 150);
  webotricks.setPWM(servo3, 0, 300);
  webotricks.setPWM(servo4, 0, 410);
  delay(3000);
}
 
void loop() {
 
  for (int S1value = 330; S1value >= 250; S1value--) {
    webotricks.setPWM(servo1, 0, S1value);
    delay(10);
  }
 
  for (int S2value = 150; S2value <= 380; S2value++) {
    webotricks.setPWM(servo2, 0, S2value);
    delay(10);
  }
 
  for (int S3value = 300; S3value <= 380; S3value++) {
    webotricks.setPWM(servo3, 0, S3value);
    delay(10);
  }
 
  for (int S4value = 410; S4value <= 510; S4value++) {
    webotricks.setPWM(servo4, 0, S4value);
    delay(10);
  }
  ////////////////////////
  delay(2000);
  for (int S4value = 510; S4value > 410; S4value--) {
    webotricks.setPWM(servo4, 0, S4value);
    delay(10);
  }
 
  for (int S3value = 380; S3value > 300; S3value--) {
    webotricks.setPWM(servo3, 0, S3value);
    delay(10);
  }
 
  for (int S2value = 380; S2value > 150; S2value--) {
    webotricks.setPWM(servo2, 0, S2value);
    delay(10);
  }
 
  for (int S1value = 250; S1value < 450; S1value++) {
    webotricks.setPWM(servo1, 0, S1value);
    delay(10);
  }
  //////////////////////
  for (int S2value = 150; S2value <= 380; S2value++) {
    webotricks.setPWM(servo2, 0, S2value);
    delay(10);
  }
 
  for (int S3value = 300; S3value <= 380; S3value++) {
    webotricks.setPWM(servo3, 0, S3value);
    delay(10);
  }
 
  for (int S4value = 410; S4value <= 510; S4value++) {
    webotricks.setPWM(servo4, 0, S4value);
    delay(10);
  }
 
  for (int S4value = 510; S4value > 410; S4value--) {
    webotricks.setPWM(servo4, 0, S4value);
    delay(10);
  }
  ///////////////////
  for (int S3value = 380; S3value > 300; S3value--) {
    webotricks.setPWM(servo3, 0, S3value);
    delay(10);
  }
 
  for (int S2value = 380; S2value > 150; S2value--) {
    webotricks.setPWM(servo2, 0, S2value);
    delay(10);
  }
 
  for (int S1value = 450; S1value > 330; S1value--) {
    webotricks.setPWM(servo1, 0, S1value);
    delay(10);
  }
}

Credits

Webotricks
28 projects • 9 followers
Contact

Comments

Please log in or sign up to comment.