5

just want to give a back story first. So i saw this video on youtube about the useless box, and i thought that it would make a great gift for my 7 year old. So i went out and bought everything that the guy posted in his description box. Just want to say that i am very new to Arduino and how these things work. I actually just want to build this as a gift to my son. I know on Stack platforms that before you ask questions you need to try yourself, i have been trying to get this thing working for the past 36 hours, and im not getting anywhere.

So here is a list of the things i have tried so far.

  1. Firstly i bought everything exactly the same as what the guy had, imported it so i know its the same stuff.
  2. I downloaded the code and schematic.
  3. I wired the little board 4 times, to make sure i did it correctly.
  4. I have redrawn the schematic in tinkercad to make sure all the wires are going to the correct places.

Here is the link to my tinkercad drawing the code is in there as well. Please note that on tinkercad i cant get the arduino board not to be plugged in by usb, it is supposed to get power from the external power supply (4AA battries).

https://www.tinkercad.com/things/43WIrlmR1K3-project1

Here is a link to the youtube video: https://www.youtube.com/watch?v=cpdjQ0gheDQ&t=311s

Here is the schematic he provided:

enter image description here Here is the Code he provided:

 #include <Servo.h>                        

Servo handServo;                          
Servo boxServo;

int switchStatus=0, action=1, vot, randNumber=0;                 
const int ledPin = 13;                    
const int frontSwitchPin = 2;
const int handServoPin = 5;
const int boxServoPin = 6;


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

  pinMode(ledPin, OUTPUT);                  
  digitalWrite(ledPin,HIGH);

  handServo.attach(handServoPin);              
  boxServo.attach(boxServoPin);
  handServo.write(180);                        
  boxServo.write(70);

  //randomSeed(analogRead(0));
}


void loop()
{
  switchStatus = digitalRead(frontSwitchPin); 
  //action = random(1,16);

  if (switchStatus == LOW){                   

    if (action == 1)
    {
      Serial.println("Action 1");          
      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(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++;
    }


    else if (action == 2)
    {
      Serial.println("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++;
    }

    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++;
    }

    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++;
    }

    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++;
    }

    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++;
    }

    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++;
    }

    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++;
    }

    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++;
    }


    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++;
    }

    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++;
    }

    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++;
    }

    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++;
    }

    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;
    }

  }

}

So in my tinkercad when i run the simulation everything works (exept for the motors breaking but i know it because of the extra power its getting from the usb which i can turn off). When you look in the Serial Monitor it runs through all the "Actions" and when you simulate the button that gets pressed by the servo everthing stops and wait until you toggle the switch again and it goes to the next action.

I have done exactly the same and like i said i wired the board 4 times to make sure its exactly the same. When i switch on the project on my board the servos keep spinning and does not stop and wait for the switch, but when i toggle the switch it actually plays the next "Action", but in the times where it is suppose to wait or stop when the switch is in the off position the servos keep rotating looks like in an anti-clockwise rotation.

Please any help would be greatly appreciated. If you need more info or if anything is unclear please ask me to provide more and i will. I tried to make it as clear as possible. Thanks

5
  • The schematic looks OK to me. Unfortunately I don't have an Arduino at hand, so I can't be more specific. You might like to try another sketch from the examples which demonstrates the usage of a servo. You will adapt that sketch to the servo output you use, and this way you can check whether the servos work at all. Dec 11, 2019 at 7:53
  • @thebusybee thanks i have tried that the servos worked. I wired the swipe example that arduino gives you and its working 100%. So no issue with the servos. Thanks for the reply
    – PeterJoe
    Dec 11, 2019 at 8:06
  • Good to know! Then the next experiment will check the switch. For this you need a sketch which reads the switch and sets the LED on pin 13 to the read value. This should show whether the switch works. Dec 11, 2019 at 8:12
  • 1
    Oh, and when you say "the servos keep rotating" does that mean the servos turn their levers all around 360° in endless circles without stopping? Dec 11, 2019 at 8:16
  • @thebusybeei i also tested the toggle switch. I deleted all the code and only used the switch, So the i did a if statement to check if it HIGH or LOW and that worked perfectly as well. Yes they turn 360 and when you toggle the switch it does the "Action" that its suppose to do and then go back to turning 360 again until the next Action runs. So basically it does not 'stop' and wait for the switch even if the if statement states only trigger servo if its LOW.
    – PeterJoe
    Dec 11, 2019 at 8:29

1 Answer 1

3

Yes they turn 360

Normal servos turn between 0 and 180° (or a bit more or less). On these servos you can set the angle through Servo.write(). But if the servo spins 360° and more, it is a continuous rotation servo. Here the Servo.write() value sets the rotation speed, not the angle. A value of 90 let's it stand still. Values below 90 means rotation backwards, above 90 forward. The higher the distance from 90, the higher the rotation speed will be.

In the video the servos are mounted in a way, that they cannot spin 360°, so they must be normal servos (that also fits with the code). If your servos spin more, you unfortunately bought the wrong servo type.

The code sets the idle position of the boxservo to 70 and of the handservo to 180. That means, that with a continuous rotation servo both servos would spin in idle state, the handservo being way faster than the boxservo.

So you would need to buy normal servos for this project.

9
  • Ah ok i see. I will check out my servos again i know its MG996R Digital Servo towerpro servos. But i see now that you get one that says "DIGI HI TORQUE" and one that say "360 Rotatable". So what you are saying is if its the 360 rotatable servo then it cant work with this project?
    – PeterJoe
    Dec 11, 2019 at 8:50
  • this is the exact servo i bought from this place. communica.co.za/products/bsk-cont-rotat-servo-mg996-11kg
    – PeterJoe
    Dec 11, 2019 at 8:51
  • Will that servos work? i see they say its Tower Pro Continuos Rotation Metal Gear Servo Motor 11KG Torque Vin 4.8~ 6.6V 360°
    – PeterJoe
    Dec 11, 2019 at 8:52
  • You might get away with this servo by rewriting your code, but honestly I don't think, that you will get happy that way. Directly buying a servo that is not a continuous rotation servo would create a lot less stress for you
    – chrisl
    Dec 11, 2019 at 8:59
  • 1
    If you think, that my answer is good, you can accept is as correct. And always be welcome to ask more questions.
    – chrisl
    Dec 11, 2019 at 9:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.