Useless Box project: can't get servo moving

Hi,

I am trying to build a useless box. I followed these instructions: Useless Box - Arduino Project Hub

Got my parts build the circuit according the project, uploaded the code and test.
Code copied and paste from that site in a new sketch. Compiled and uploaded (no errors).

Nothing happens when I flip the switch.

To give an idea of my setup: I attached a photo. More photo’s can be added if needed.
I use an Arduino UNO

Tips and advice is much appreciated.

I am quite new to arduino, btw.

Have you been able to get the servo working in another simpler program?

Post the code for your Useless Box program.

And please use the code button </>so your code looks like thisand is easy to copy to a text editor

…R

The code is used:

// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.

#include <Servo.h>

const int  buttonPin = 2;
int buttonState = 0;

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
int pos;        // variable to store the servo position
long timeDelay;

void setup()
{
  pinMode(buttonPin, INPUT);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop()
{
  buttonState = digitalRead(buttonPin);  
                            // Read the button position
  if (buttonState == HIGH) {
     for(pos = myservo.read(); pos >=20; pos -= 1) { 
                            // goes from 90 degrees to 20 degrees in 1 step                                   
       myservo.write(pos);  // tell servo to go to position in variable 'ONpos'
       timeDelay = random(15, 30);
       delay(15);           // randomize wait time for the servo to reach the position
     }
  }
  else {
     timeDelay = random(1, 4);
     for(pos = myservo.read(); pos <=90; pos += timeDelay) {
                            // goes from 20 degrees to 90 degrees in 1 step                            
       myservo.write(pos);  // tell servo to go to position in variable 'OFFpos'                
       delay(15);           // randomize wait time for the servo to reach the position
     }
  }
}

Try:
pinMode(buttonPin, INPUT_PULLUP);

Power the servo from it's own power supply, at least use the power jack to power the Arduino.

Edit:
Try the simple Servo example sketch here:

.

Hi Larry,

Thanks for your suggestions.

I will test it this evening, when I am back home :slight_smile:

I will try suggestion no.2 as well. Curious about the outcome.

You are trying to power a ~1A inductive device from the logic 5V supply of the Arduino - that's
never going to go well.

Power servos separately with a 5 or 6V supply capable of at least 1A per servo, more for
high torque servos.

MarkT:
You are trying to power a ~1A inductive device from the logic 5V supply of the Arduino - that's
never going to go well.

Power servos separately with a 5 or 6V supply capable of at least 1A per servo, more for
high torque servos.

Hi MarkT

What are you trying to say? I do not fully understand.

Do I understand correctly that my servo needs a different way to get it's power? And that the 5v arduino power is not sufficient?
Could you please explain?

@LarryD,

Your suggestions did not work. Tried the simple servo setup and also nothing happens.

Servos are motors, motors are inductive loads, they are not suitable for powering from a
logic supply rail, you risk damaging the ICs on the logic rail if inductive spikes get out.

Logic chips need safe clean power, motors generally prevent this.

Also servos draw perhaps an amp or so, more than most Arduino's can provide, leading to the
5V rail dipping and the processor reseting - 95% of questions here on servos seem to be by
people wondering why their sketch keeps crashing and restarting - becuase they power their
servo(s) from the Arduino 5V rail.

It won't work!

Hi MarkT,

Thanks for your answer. If I understand correctly; I can't provide power to the servo from the Arduino. I need another power source for the servo.

Just add a battery pack to the breadboard and connect the servo to that.

Found a nice source on servos: youtube

Have to get myself additional hardware :slight_smile:

1 more question though. I started to google to get to know how many batteries I needed. How do I know how many AA batteries I need to power (in this case a servo) my hardware?

For the servo 4 AA batteries is sufficient? Or would 3 AA also do?

You look up the rated voltage for your servo. Many are 4.8V to 6V. Some are different.

Tested with a extra battery holder (4x AA) and it works. My servo is functioning.

This topic can be closed.

Hi, I have a similar problem, I have tried connecting a 4AA battery pack to the servo and powering the arduino from the computer but it still won't work, any ideas why?

Do you have a sketch of your layout?

The setup I used can be found here: Useless Box - Arduino Project Hub

With the change, there is no power between the arduino and breadboard.
There is a 9v battery plugged to the arduino. And an battery holder (4x AA batteries) connected to the breadboard.

On which I have an additional question: How to "properly" power the arduino with 1 battery holder.
I now use an extra battery holder AND a 9v to power the arduino. I want to use only 1 battery holder. But how to connect it? Perhaps I need a battery holder to connect directly to the arduino? But then, how many AA batteries would be sufficient.