Arduino Powered “Servo Bear” :: Student Project

If a bear says, “Leave me alone!”, you probably ought to get out of dodge, right?

Well, Steve Busik (a customer of PEAs), thinks otherwise, and has created a fun project that allows you to mess with a bear.

I think you’ll get a kick out of this project. And please, share this post with people who need a smile – they will get it!

Steve, why the heck did you build a “servo bear”?

I was asked by my Director to create something and bring it to work for “Bring Your Child to Work Day”.

How does your project work?

When the switch is closed by a person the “right arm” servo opens the box lid then the “left arm” servo turns off or opens the switch. The box is based on the don’t wake me, or useless machine I saw on YouTube.

What was your biggest struggle as you worked through this project?

Soldering… I’m horrible at it. I actually semi-burned the small switch causing some very erratic behavior. Finally after trouble shooting the wrong area found the issue.

Did the project end up as you expected?

Yes indeed. It was sheer luck that the bear fit so perfectly in the box I had.

Looking back on this project, what can you say you have learned about programming and/or electronics through the creation process?

The code is actually “borrowed” from an awesome website called labdomotic and is written in Italian. It is WAY above my head and I am studying it to learn more about this process of programing. [Editor’s Note: That you were able to adapt and build this project is testament to some hard work – nice job Steve! And whoa – labdomotic is an awesome site and youtube channel!]

What type of Arduino board, Arduino clone, or Arduino compatible board does your project use?

Arduino Uno

How do you power your project?

Via USB from my computer and Batteries

What components have you used for this project?

Servos and a switch

Was the training at Programming Electronics Academy able to help you build your skill?

Absolutely. I cannot stress enough how valuable the lessons and feedback are.

I started watching the many free videos from PEA and quickly realized the benefits of joining.

About Steve:

Steve

Steve is an electrician from Florida and has been into hobby electronics and programming for about 4 years.

 

 

 

 

 

 

 

 

 

Arduino Code:

/* www.labdomotic.com
Youtube channel TARTAGLIA DANIELE
*/

#include <Servo.h>                        //Inserisci libreria del servo
Servo handServo;
Servo boxServo;

int switchAnimazione = 0, action = 1, vot, randNumber = 0;
const int InterruttorePorta = 2;
const int ServoManoPin = 5;
const int ServoAperturaBoxPin = 6;


void setup()
{
  Serial.begin(9600);
  handServo.attach(ServoManoPin);
  boxServo.attach(ServoAperturaBoxPin);
  handServo.write(180);   //Posizione di partenza del servomotore Mano
  boxServo.write(70);    //Posizione di partenza del servomotore che apre la scatola
}


void loop()
{
  switchAnimazione = digitalRead(InterruttorePorta);


  // ----------------------------------------------------------------------------------------------------------------------------
  // -------------------------------                  PRIMA ANIMAZIONE                -------------------------------------------
  // ----------------------------------------------------------------------------------------------------------------------------
  // ----------------------------------------------------------------------------------------------------------------------------

  if (switchAnimazione == LOW) {

    if (action == 1)
    {
      for (int i = 70; i <= 110; i++)
      {
        boxServo.write(i);
        delay(13);
      }
      for (int i = 180; i >= 35; i--)
      {
        handServo.write(i);
        delay(20);
      }
      delay(1000);
      handServo.write(26);
      delay(200);
      for (int i = 26; i <= 180; i++)
      {
        handServo.write(i);
        delay(20);
      }
      for (int i = 110; i >= 70; i--)
      {
        boxServo.write(i);
        delay(20);
      }
      action++;
    }

    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  SECONDA ANIMAZIONE                -----------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------


    else if (action == 2)
    {
      for (int i = 70; i <= 110; i++) {
        boxServo.write(i);
        delay(6);
      }
      delay(550);
      handServo.write(26);
      delay(550);
      handServo.write(180);
      delay(550);
      boxServo.write(70);
      delay(1500);
      for (int i = 70; i <= 110; i++) {
        boxServo.write(i);
        delay(6);
      }
      delay(3000);
      boxServo.write(70);
      action++;
    }

    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  TERZA ANIMAZIONE                -------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------



    else if (action == 3)
    {
      Serial.println("Action 3");
      for (int i = 70; i <= 110; i++) {
        boxServo.write(i);
        delay(6);
      }
      delay(1000);
      boxServo.write(70);
      delay(2000);
      for (int i = 70; i <= 110; i++) {
        boxServo.write(i);
        delay(6);
      }
      handServo.write(26);
      delay(550);
      handServo.write(180);
      delay(500);
      boxServo.write(70);
      action++;
    }

    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  QUARTA ANIMAZIONE                ------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------



    else if (action == 4)
    {
      Serial.println("Action 4");
      for (int i = 70; i <= 110; i++)
      {
        boxServo.write(i);
        delay(20);
      }
      for (int i = 180; i >= 35; i--)
      {
        handServo.write(i);
        delay(20);
      }
      delay(2000);
      handServo.write(26);
      delay(200);
      handServo.write(180);
      delay(400);
      boxServo.write(70);
      action++;
    }


    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  QUINTA ANIMAZIONE                ------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------


    else if (action == 5)
    {
      Serial.println("Action 5");
      for (int i = 70; i <= 110; i++) {
        boxServo.write(i);
        delay(6);
      }
      delay(2000);
      handServo.write(65);
      delay(550);
      handServo.write(40);
      delay(200);
      handServo.write(65);
      delay(200);
      handServo.write(40);
      delay(200);
      handServo.write(65);
      delay(200);
      handServo.write(40);
      delay(200);
      handServo.write(65);
      delay(200);
      handServo.write(40);
      delay(200);
      handServo.write(65);
      delay(200);
      handServo.write(40);
      delay(200);
      handServo.write(65);
      delay(2000);
      handServo.write(26);
      delay(400);
      handServo.write(180);
      delay(400);
      boxServo.write(70);
      action++;
    }


    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  SESTA ANIMAZIONE                -------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------

    else if (action == 6)
    {
      Serial.println("Action 6");

      for (int i = 70; i < 110; i++)
      {
        boxServo.write(i);
        delay(20);
      }
      delay(1000);
      for (int i = 0; i < 12; i++)
      {
        for (int j = 70; j <= 110; j++) {
          boxServo.write(j);
          delay(6);
        }
        delay(200);
      }
      for (int i = 180; i >= 35; i--)
      {
        handServo.write(i);
        delay(30);
      }
      handServo.write(26);
      delay(400);
      handServo.write(180);
      delay(400);
      boxServo.write(70);
      delay(1500);
      for (int i = 70; i <= 110; i++) {
        boxServo.write(i);
        delay(6);
      }
      delay(3000);
      boxServo.write(80);
      action++;
    }


    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  SETTIMA ANIMAZIONE                -----------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------

    else if (action == 7)
    {
      Serial.println("Action 7");
      for (int i = 70; i <= 110; i++) {
        boxServo.write(i);
        delay(6);
      }
      delay(400);
      handServo.write(26);
      delay(1000);
      for (int i = 0; i < 6; i++)
      {
        for (int j = 70; j <= 110; j++) {
          boxServo.write(j);
          delay(6);
        }
        delay(200);
      }
      delay(500);
      handServo.write(180);
      delay(400);
      boxServo.write(70);
      action++;
    }


    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  OTTAVA ANIMAZIONE                ------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------


    else if (action == 8)
    {
      Serial.println("Action 8");
      for (int i = 70; i <= 110; i++) {
        boxServo.write(i);
        delay(6);
      }
      handServo.write(26);
      delay(2000);
      for (int i = 0; i < 7; i++)
      {
        handServo.write(75);
        delay(100);
        handServo.write(40);
        delay(100);
      }
      delay(500);
      handServo.write(180);
      delay(1000);
      boxServo.write(70);
      action++;
    }


    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  NONA ANIMAZIONE                --------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------

    else if (action == 9)
    {
      Serial.println("Action 9");
      for (int i = 70; i <= 105; i++) {
        boxServo.write(i);
        delay(6);
      }
      delay(2000);
      boxServo.write(110);
      for (int i = 180; i >= 35; i--)
      {
        handServo.write(i);
        delay(40);
      }
      delay(500);
      handServo.write(26);
      delay(200);
      for (int i = 26; i <= 180; i++)
      {
        handServo.write(i);
        delay(40);
      }
      boxServo.write(70);
      delay(2000);
      boxServo.write(100);
      delay(3000);
      boxServo.write(70);
      action++;
    }


    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  DECIMA ANIMAZIONE                ------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------


    else if (action == 10)
    {
      Serial.println("Action 10");
      for (int i = 70; i <= 105; i++)
      {
        boxServo.write(i);
        delay(100);
      }
      delay(1000);
      for (int i = 0; i < 10; i++)
      {
        for (int j = 70; j <= 100; j++) {
          boxServo.write(j);
          delay(6);
        }
        delay(100);
      }
      boxServo.write(110);
      delay(100);
      handServo.write(26);
      delay(650);
      handServo.write(180);
      delay(400);
      boxServo.write(70);
      action++;
    }

    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  UNDICESIMA ANIMAZIONE                --------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------


    else if (action == 11)
    {
      Serial.println("Action 11");
      for (int i = 70; i <= 110; i++) {
        boxServo.write(i);
        delay(6);
      }
      handServo.write(26);
      delay(2000);
      for (int i = 0; i < 3; i++)
      {
        handServo.write(65);
        delay(200);
        handServo.write(40);
        delay(200);
      }
      delay(1500);
      handServo.write(180);
      delay(400);
      boxServo.write(70);
      delay(1500);
      for (int i = 70; i <= 110; i++) {
        boxServo.write(i);
        delay(6);
      }
      handServo.write(26);
      delay(3000);
      handServo.write(180);
      delay(400);
      boxServo.write(70);
      action++;
    }


    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  DODICESIMA ANIMAZIONE                -------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------


    else if (action == 12)
    {
      Serial.println("Action 12");
      for (int i = 70; i <= 110; i++)
      {
        boxServo.write(i);
        delay(50);
      }
      delay(1000);
      for (int i = 180; i >= 26; i--)
      {
        handServo.write(i);
        delay(50);
      }
      delay(2000);
      handServo.write(26);
      delay(200);
      handServo.write(180);
      delay(400);
      boxServo.write(70);
      action++;
    }

    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  TREDICESIMA ANIMAZIONE                -------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------


    else if (action == 13)
    {
      Serial.println("Action 13");
      for (int i = 70; i <= 110; i++) {
        boxServo.write(i);
        delay(6);
      }
      delay(2000);
      for (int i = 180; i >= 60; i--)
      {
        handServo.write(i);
        delay(40);
      }
      for (int i = 0; i < 3; i++)
      {
        handServo.write(60);
        delay(200);
        handServo.write(40);
        delay(800);
      }
      handServo.write(26);
      delay(2000);
      handServo.write(180);
      delay(500);
      boxServo.write(70);
      action++;
    }

    // ----------------------------------------------------------------------------------------------------------------------------
    // -------------------------------                  QUATTORDICESIMA ANIMAZIONE                ---------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------------------


    else if (action == 14)
    {
      Serial.println("Action 14");
      for (int i = 70; i <= 105; i++) {
        boxServo.write(i);
        delay(6);
      }
      delay(4000);
      boxServo.write(110);
      handServo.write(26);
      delay(650);
      handServo.write(180);
      delay(500);
      boxServo.write(100);
      delay(4000);
      boxServo.write(70);
      action++;
    }

    else if (action == 15)
    {
      Serial.println("Action 15");
      for (int i = 70; i <= 105; i++) {
        boxServo.write(i);
        delay(6);
      }
      delay(1000);
      for (int i = 0; i < 3; i++)
      {
        for (int j = 70; j <= 105; j++) {
          boxServo.write(j);
          delay(50);
        }
        for (int j = 105; j >= 70; j--)
        {
          boxServo.write(j);
          delay(50);
        }
      }
      for (int j = 70; j <= 110; j++) {
        boxServo.write(j);
        delay(50);
      }
      for (int i = 180; i >= 35; i--)
      {
        handServo.write(i);
        delay(40);
      }
      delay(1000);
      handServo.write(26);
      delay(400);
      handServo.write(180);
      delay(400);
      boxServo.write(70);
      action = 1;
    }

  }

}
installing Arduino libraries

Installing Arduino Libraries | Beginners Guide

IoT sewage project

Pumping poo! An IoT sewage project

ESP32 webOTA updates

How to update ESP32 firmware using web OTA [Guide + Code]

error message Brackets Thumbnail V1

expected declaration before ‘}’ token [SOLVED]

Compilation SOLVED | 1

Compilation error: expected ‘;’ before [SOLVED]

Learn how to structure your code

5 Comments

  1. Mel Matusz on July 4, 2019 at 9:07 pm

    I’m interested in making one of these boxes for my own; however I don’t think I’m up to the challenge of converting the Italian sketch into English. Is it possible to get a copy of Steve’s file to use as a reference?

    Additionally, I see the parts list on the labdomotic webpage but I wonder if Steve has and can provide a list of the automation components that he used in building his box.

    • Michael James on July 20, 2019 at 10:40 am

      Hi Mel,

      I pasted the code that Steve used, it mostly English aside from some comments in Italian. I hope this helps!

  2. Steve McLemore on July 16, 2019 at 3:59 pm

    Good job Steve!

  3. John on December 16, 2020 at 4:15 am

    WHOA !!! This is fantastic !
    I have started on the Arduino courses and one of the projects I had in mind was along this line, …. But Steve !, this is just way beyond what I imagined.
    This now has me thinking about how my initial idea can be improved.

    Quick question … what turns the switch back the other way when the arm comes out ? Is it the arm that changes the switch position or something else ?

  4. Trent Brown on August 26, 2022 at 12:50 pm

    Awesome job Steve!

Leave a Comment