Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Mahmoud Ahmed
Published © CC BY-NC-SA

How to Build Sauron The Lord of the Robots

A human-sized semi-humanoid robot that looks like Sauron from The Lord of the Rings movie series.

AdvancedFull instructions provided6 days10,082
How to Build Sauron The Lord of the Robots

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
1Sheeld
1Sheeld
×1
Android device
Android device
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Schematics

Sauron Fritzing File

Code

Sauron Arduino Code

Arduino
#define CUSTOM_SETTINGS
#define INCLUDE_GAMEPAD_SHIELD
#define INCLUDE_MUSIC_PLAYER_SHIELD
#define INCLUDE_TERMINAL_SHIELD
#define INCLUDE_ORIENTATION_SENSOR_SHIELD

/* Include 1Sheeld library. */
#include <OneSheeld.h>
#include <Servo.h>

Servo rightArm_Motor1;
Servo rightArm_Motor2;
Servo rightArm_Motor3;

Servo leftArm_Motor1;
Servo leftArm_Motor2;
Servo leftArm_Motor3;

Servo neckHorizontal;
Servo neckVertical;

Servo mouth;

const int modePin1 =  2;
const int modePin2 =  3;

volatile int modeState1 = LOW;
volatile int modeState2 = LOW;

volatile boolean gamepadMode_Enabled = false;
volatile boolean imitationMode_Enabled = false;

const int ledPin1 = A0;
const int ledPin2 = A1;
//------------------------------------------ void setup ---------------------------------------------------

void setup()
{
  // Start communication
  OneSheeld.begin();

  // Set some pins as output
  pinMode(modePin1, INPUT);
  pinMode(modePin2, INPUT);

  // Set Led as output and HIGH "Saurons Eye"
  pinMode(ledPin1,OUTPUT);
  pinMode(ledPin2,OUTPUT);
  digitalWrite(ledPin1,HIGH);
  digitalWrite(ledPin2,HIGH);
  
  // Digital Pins Usable For Interrupts when using Mega, Mega2560, MegaADK (2, 3, 18, 19, 20, 21)
  attachInterrupt(digitalPinToInterrupt(modePin1), gampadMode_ChangeISR, CHANGE);
  attachInterrupt(digitalPinToInterrupt(modePin2), imitationMode_ChangeISR, CHANGE);

  /* Connect signal pins(Orange) from the motors to the Arduino mega PWM pins directly
     then power the motors from the power supply NOT from the Arduino
     then connect both grounds of Arduino and power supply to each others
  */

  rightArm_Motor1.attach(4);
  rightArm_Motor2.attach(5);
  rightArm_Motor3.attach(6);

  leftArm_Motor1.attach(7);
  leftArm_Motor2.attach(8);
  leftArm_Motor3.attach(9);

  neckHorizontal.attach(10);
  neckVertical.attach(11);

  mouth.attach(12);

  // home position
  rightArm_Motor1.write(95);
  rightArm_Motor2.write(150);
  rightArm_Motor3.write(20);

  leftArm_Motor1.write(90);
  leftArm_Motor2.write(45);
  leftArm_Motor3.write(180);

  neckHorizontal.write(105);
  neckVertical.write(30);

  mouth.write(100);
}

//---------------------------------- void loop ---------------------------------------------------

void loop()
{
  modeState1 = digitalRead(modePin1);
  modeState2 = digitalRead(modePin2);

  // Always check the desired mode
  if (modeState1 == HIGH) {
    Terminal.println("GamePad Mode was selected");
    gamePadMode();
  } //Pin 12 = High --> Gamepad mode

  else if (modeState2 == HIGH) {
    Terminal.println("Imitation Mode was selected");
    imitationMode();
  } //Pin 13 = High -- > Imitation Mode

  else {
    Terminal.println("Standby Mode was selected");
    standbyMode();
  }

}//void loop


//----------------------------------------- void Standby Mode ---------------------------------------------

void standbyMode() {
  // Standby Mode
  Terminal.println("Standby mode activated");

  // home position
  Terminal.println("1st position");
  rightArm_Motor1.write(95);
  rightArm_Motor2.write(150);
  rightArm_Motor3.write(20);

  leftArm_Motor1.write(90);
  leftArm_Motor2.write(45);
  leftArm_Motor3.write(180);

  neckHorizontal.write(105);
  neckVertical.write(30);

  // Set the volume
//  MusicPlayer.setVolume(10);
  MusicPlayer.play();

  for (int i = 0; i <= 19; i++) {
    mouth.write(100);
    OneSheeld.delay(150);
    mouth.write(75);
    OneSheeld.delay(150);
  }//for

  MusicPlayer.pause();
  mouth.write(100);

  OneSheeld.delay(3000);

  //----------------------------------------------------

  // Always check the desired mode
  if (gamepadMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate GamePad Mode Now");
    gamePadMode();
  } //Pin 12 = High --> Gamepad mode

  else if (imitationMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate Imitation Mode Now");
    imitationMode();
  } //Pin 13 = High -- > Imitation Mode

  else { // Complete the rest of the sequence

    // Move head 90 --> 0 --> 180 --> 90
    Terminal.println("2nd position");
    rightArm_Motor1.write(95);
    rightArm_Motor2.write(150);
    rightArm_Motor3.write(20);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(45);
    leftArm_Motor3.write(180);

    neckHorizontal.write(105);
    OneSheeld.delay(1500);
    neckHorizontal.write(65);
    OneSheeld.delay(1500);
    neckHorizontal.write(140);
    OneSheeld.delay(1500);
    neckHorizontal.write(105);

    neckVertical.write(30);

    // Set the volume
//    MusicPlayer.setVolume(10);
    MusicPlayer.play();

    for (int i = 0; i <= 19; i++) {
      mouth.write(100);
      OneSheeld.delay(150);
      mouth.write(75);
      OneSheeld.delay(150);
    }//for

    MusicPlayer.pause();
    mouth.write(100);

    OneSheeld.delay(3000);
  }//else --> complete the rest of the sequence

  //----------------------------------------------------

  // Always check the desired mode
  if (gamepadMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate GamePad Mode Now");
    gamePadMode();
  } //Pin 12 = High --> Gamepad mode

  else if (imitationMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate Imitation Mode Now");
    imitationMode();
  } //Pin 13 = High -- > Imitation Mode

  else { // Complete the rest of the sequence

    // Move hands and head to 45 degree
    Terminal.println("3rd position");
    rightArm_Motor1.write(15);
    rightArm_Motor2.write(180);
    rightArm_Motor3.write(0);

    leftArm_Motor1.write(180);
    leftArm_Motor2.write(30);
    leftArm_Motor3.write(145);

    neckHorizontal.write(65);
    neckVertical.write(30);

    // Set the volume
//    MusicPlayer.setVolume(10);
    MusicPlayer.play();

    for (int i = 0; i <= 19; i++) {
      mouth.write(100);
      OneSheeld.delay(150);
      mouth.write(75);
      OneSheeld.delay(150);
    }//for

    MusicPlayer.pause();
    mouth.write(100);

    OneSheeld.delay(3000);
  }//else --> complete the rest of the sequence

  //-------------------------------------------------

  // Always check the desired mode
  if (gamepadMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate GamePad Mode Now");
    gamePadMode();
  } //Pin 12 = High --> Gamepad mode

  else if (imitationMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate Imitation Mode Now");
    imitationMode();
  } //Pin 13 = High -- > Imitation Mode

  else { // Complete the rest of the sequence

    // Move right hand and head to 135 degree
    Terminal.println("4th position");
    rightArm_Motor1.write(15);
    rightArm_Motor2.write(150);
    rightArm_Motor3.write(30);

    leftArm_Motor1.write(180);
    leftArm_Motor2.write(30);
    leftArm_Motor3.write(145);

    neckHorizontal.write(140);
    neckVertical.write(30);

    // Set the volume
//    MusicPlayer.setVolume(10);
    MusicPlayer.play();

    for (int i = 0; i <= 19; i++) {
      mouth.write(100);
      OneSheeld.delay(150);
      mouth.write(75);
      OneSheeld.delay(150);
    }//for

    MusicPlayer.pause();
    mouth.write(100);

    OneSheeld.delay(3000);
  }//else --> complete the rest of the sequence

  //---------------------------------------------------

  // Always check the desired mode
  if (gamepadMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate GamePad Mode Now");
    gamePadMode();
  } //Pin 12 = High --> Gamepad mode

  else if (imitationMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate Imitation Mode Now");
    imitationMode();
  } //Pin 13 = High -- > Imitation Mode

  else { // Complete the rest of the sequence

    // Move head to the center
    Terminal.println("5th position");
    rightArm_Motor1.write(15);
    rightArm_Motor2.write(150);
    rightArm_Motor3.write(30);

    leftArm_Motor1.write(180);
    leftArm_Motor2.write(30);
    leftArm_Motor3.write(145);

    neckHorizontal.write(105);
    neckVertical.write(30);

    // Set the volume
//    MusicPlayer.setVolume(10);
    MusicPlayer.play();

    for (int i = 0; i <= 19; i++) {
      mouth.write(100);
      OneSheeld.delay(150);
      mouth.write(75);
      OneSheeld.delay(150);
    }//for

    MusicPlayer.pause();
    mouth.write(100);

    OneSheeld.delay(3000);
  }//else --> complete the rest of the sequence

  //----------------------------------------------------

  // Always check the desired mode
  if (gamepadMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate GamePad Mode Now");
    gamePadMode();
  } //Pin 12 = High --> Gamepad mode

  else if (imitationMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate Imitation Mode Now");
    imitationMode();
  } //Pin 13 = High -- > Imitation Mode

  else { // Complete the rest of the sequence

    // Move hands up
    Terminal.println("6th position");
    rightArm_Motor1.write(110);
    rightArm_Motor2.write(0);
    rightArm_Motor3.write(45);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(180);
    leftArm_Motor3.write(145);

    neckHorizontal.write(105);
    neckVertical.write(30);

    // Set the volume
//    MusicPlayer.setVolume(10);
    MusicPlayer.play();

    for (int i = 0; i <= 19; i++) {
      mouth.write(100);
      OneSheeld.delay(150);
      mouth.write(75);
      OneSheeld.delay(150);
    }//for

    MusicPlayer.pause();
    mouth.write(100);

    OneSheeld.delay(3000);
  }//else --> complete the rest of the sequence

  //-------------------------------------------------

  // Always check the desired mode
  if (gamepadMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate GamePad Mode Now");
    gamePadMode();
  } //Pin 12 = High --> Gamepad mode

  else if (imitationMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate Imitation Mode Now");
    imitationMode();
  } //Pin 13 = High -- > Imitation Mode

  else { // Complete the rest of the sequence

    /* Move hands to sides        o
                               -- | --
                                  ^
    */

    Terminal.println("7th position");
    rightArm_Motor1.write(110);
    rightArm_Motor2.write(80);
    rightArm_Motor3.write(60);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(115);
    leftArm_Motor3.write(140);

    neckHorizontal.write(105);
    neckVertical.write(30);

    // Set the volume
//    MusicPlayer.setVolume(10);
    MusicPlayer.play();

    for (int i = 0; i <= 19; i++) {
      mouth.write(100);
      OneSheeld.delay(150);
      mouth.write(75);
      OneSheeld.delay(150);
    }//for

    MusicPlayer.pause();
    mouth.write(100);

    OneSheeld.delay(3000);
  }//else --> complete the rest of the sequence

  //---------------------------------------------------

  // Always check the desired mode
  if (gamepadMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate GamePad Mode Now");
    gamePadMode();
  } //Pin 12 = High --> Gamepad mode

  else if (imitationMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate Imitation Mode Now");
    imitationMode();
  } //Pin 13 = High -- > Imitation Mode

  else { // Complete the rest of the sequence

    // Strike right hand
    Terminal.println("8th position");
    rightArm_Motor1.write(0);
    rightArm_Motor2.write(0);
    rightArm_Motor3.write(45);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(45);
    leftArm_Motor3.write(180);

    OneSheeld.delay(500);

    rightArm_Motor1.write(180);
    rightArm_Motor2.write(0);
    rightArm_Motor3.write(45);

    OneSheeld.delay(1000);

    rightArm_Motor1.write(95);
    rightArm_Motor2.write(150);
    rightArm_Motor3.write(20);

    neckHorizontal.write(105);
    neckVertical.write(30);

    // Set the volume
//    MusicPlayer.setVolume(10);
    MusicPlayer.play();

    for (int i = 0; i <= 19; i++) {
      mouth.write(100);
      OneSheeld.delay(150);
      mouth.write(75);
      OneSheeld.delay(150);
    }//for

    MusicPlayer.pause();
    mouth.write(100);

    OneSheeld.delay(3000);
  }//else --> complete the rest of the sequence

  //--------------------------------------------------

  // Always check the desired mode
  if (gamepadMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate GamePad Mode Now");
    gamePadMode();
  } //Pin 12 = High --> Gamepad mode

  else if (imitationMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate Imitation Mode Now");
    imitationMode();
  } //Pin 13 = High -- > Imitation Mode

  else { // Complete the rest of the sequence

    // Strike left hand
    Terminal.println("9th position");
    rightArm_Motor1.write(95);
    rightArm_Motor2.write(150);
    rightArm_Motor3.write(20);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(180);
    leftArm_Motor3.write(110);

    OneSheeld.delay(500);

    leftArm_Motor1.write(0);
    leftArm_Motor2.write(180);
    leftArm_Motor3.write(110);

    OneSheeld.delay(1000);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(45);
    leftArm_Motor3.write(180);

    neckHorizontal.write(105);
    neckVertical.write(30);

    // Set the volume
//    MusicPlayer.setVolume(10);
    MusicPlayer.play();

    for (int i = 0; i <= 19; i++) {
      mouth.write(100);
      OneSheeld.delay(150);
      mouth.write(75);
      OneSheeld.delay(150);
    }//for

    MusicPlayer.pause();
    mouth.write(100);

    OneSheeld.delay(3000);
  }//else --> complete the rest of the sequence

  //-----------------------------------------------------

  // Always check the desired mode
  if (gamepadMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate GamePad Mode Now");
    gamePadMode();
  } //Pin 12 = High --> Gamepad mode

  else if (imitationMode_Enabled == true) {
    Terminal.println("System Was Interrupted And It Will Activate Imitation Mode Now");
    imitationMode();
  } //Pin 13 = High -- > Imitation Mode

  else { // Complete the rest of the sequence

    // Play Music Player and move the robot's mouth
    Terminal.println("Return to the home position");
    rightArm_Motor1.write(95);
    rightArm_Motor2.write(150);
    rightArm_Motor3.write(20);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(45);
    leftArm_Motor3.write(180);

    neckHorizontal.write(105);
    neckVertical.write(30);

    // Set the volume
//    MusicPlayer.setVolume(10);

    MusicPlayer.play();

    for (int i = 0; i <= 49; i++) {
      mouth.write(100);
      OneSheeld.delay(150);
      mouth.write(75);
      OneSheeld.delay(150);
    }//for

    MusicPlayer.pause();
    mouth.write(100);

    Terminal.println("Done");
  }//else --> complete the rest of the sequence

}// void standby mode

//----------------------------------------- void Gamepad Mode ---------------------------------------------

void gamePadMode() {

  Terminal.println("Gamepad mode activated");

  // Always check the status of gamepad buttons
  if (GamePad.isUpPressed())
  { // Move both hands up
    Terminal.println("Up is pressed");

    rightArm_Motor1.write(110);
    rightArm_Motor2.write(0);
    rightArm_Motor3.write(45);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(180);
    leftArm_Motor3.write(145);

    neckHorizontal.write(105);
    neckVertical.write(30);

    mouth.write(100);
  }//Up is pressed

  if (GamePad.isDownPressed())
  { // Move both hands up
    Terminal.println("Down is pressed");

    rightArm_Motor1.write(110);
    rightArm_Motor2.write(170);
    rightArm_Motor3.write(45);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(20);
    leftArm_Motor3.write(145);

    neckHorizontal.write(105);
    neckVertical.write(30);

    mouth.write(100);
  }//Down is pressed

  if (GamePad.isRightPressed())
  { // Move right hand side
    Terminal.println("Right is pressed");

    rightArm_Motor1.write(110);
    rightArm_Motor2.write(80);
    rightArm_Motor3.write(60);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(20);
    leftArm_Motor3.write(145);

    neckHorizontal.write(105);
    neckVertical.write(30);

    mouth.write(100);
  }//Right is pressed

  if (GamePad.isLeftPressed())
  { // Move left hand side
    Terminal.println("Left is pressed");

    rightArm_Motor1.write(110);
    rightArm_Motor2.write(170);
    rightArm_Motor3.write(45);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(115);
    leftArm_Motor3.write(140);

    neckHorizontal.write(105);
    neckVertical.write(30);

    mouth.write(100);
  }//Left is pressed



  if (GamePad.isRedPressed())
  { // Combo 1
    Terminal.println("Red is pressed");

    rightArm_Motor1.write(180);
    rightArm_Motor2.write(45);
    rightArm_Motor3.write(100);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(180);
    leftArm_Motor3.write(110);

    neckHorizontal.write(105);
    neckVertical.write(30);

    mouth.write(100);
  }//Red is pressed

  if (GamePad.isOrangePressed())
  { // Combo 2
    Terminal.println("Orange is pressed");

    rightArm_Motor1.write(15);
    rightArm_Motor2.write(100);
    rightArm_Motor3.write(0);

    leftArm_Motor1.write(180);
    leftArm_Motor2.write(100);
    leftArm_Motor3.write(180);

    neckHorizontal.write(105);
    neckVertical.write(30);

    mouth.write(100);
  }//Orange is pressed

  if (GamePad.isGreenPressed())
  { // Combo 3
    Terminal.println("Green is pressed");

    rightArm_Motor1.write(95);
    rightArm_Motor2.write(45);
    rightArm_Motor3.write(120);

    leftArm_Motor1.write(90);
    leftArm_Motor2.write(135);
    leftArm_Motor3.write(60);

    neckHorizontal.write(105);
    neckVertical.write(10);

    mouth.write(100);
  }//Green is pressed

  if (GamePad.isBluePressed())
  { // Combo 4
    Terminal.println("Blue is pressed");

    rightArm_Motor1.write(90);
    rightArm_Motor2.write(0);
    rightArm_Motor3.write(90);

    leftArm_Motor1.write(180);
    leftArm_Motor2.write(45);
    leftArm_Motor3.write(180);

    neckHorizontal.write(105);
    neckVertical.write(30);

    mouth.write(100);
  }//Blue is pressed

}// Gamepad mode


//----------------------------------------- void Imitation Mode -------------------------------------------

void imitationMode() {
  // Imitation mode
  Terminal.println("Imitation mode activated");

  if (OrientationSensor.getY() > -90 && OrientationSensor.getY() <= 90) {
    leftArm_Motor1.write(map(OrientationSensor.getY(), -90, 90, 0, 180));
  }

  if (OrientationSensor.getZ() > -70 &&  abs(OrientationSensor.getZ()) <= 70) {
    leftArm_Motor2.write(map(OrientationSensor.getZ(), 0, 60, 100, 160));
    leftArm_Motor3.write(map(OrientationSensor.getZ(), 0, 60, 160, 100));
  }

}// void imitation mode

//-----------------------------------------------------------------------------------------------------------
//-------------------------------------------- Modes ISR ----------------------------------------------------
//-----------------------------------------------------------------------------------------------------------

void gampadMode_ChangeISR() {
  if (gamepadMode_Enabled && !imitationMode_Enabled) {
    gamepadMode_Enabled = false;
    imitationMode_Enabled = false;
  }
  else {
    gamepadMode_Enabled = true;
    imitationMode_Enabled = false;
  }

}//gampadMode_ChangeISR

//------------------------------------------------------------------------------------------------------------

void imitationMode_ChangeISR() {
  if (imitationMode_Enabled && !gamepadMode_Enabled) {
    gamepadMode_Enabled = false;
    imitationMode_Enabled = false;
  }
  else {
    gamepadMode_Enabled = false;
    imitationMode_Enabled = true;
  }
}//imitationMode_ChangeISR

Credits

Mahmoud Ahmed

Mahmoud Ahmed

6 projects • 46 followers
Building new products is my favourite hobby :D
Thanks to Kareem Lucilius.

Comments