Power consumption

Hi guys,

sorry for stupid post, im pretty knew to the whole electronics/robotics scene. I've built a bot which has 3 hxt900 servo's 2 hacked for continous rotation. Also a HC-SR04 ping sensor. when i plug in a 9v battery into it, it doesnt really do anything, the servos twitch and thats about it.

I thought this was due to lack of power, but everything works as it should when plugged into usb..

What am i missing?

Thanks, Craig

How are you creating the servo control signal? Read here http://www.arduino.cc/playground/ComponentLib/servo

all my code is wrote(using what you linked), it works when on usb just not via a brandnew 9v battery.

code below…

#include <Ultrasonic.h>
#include <Servo.h>

Ultrasonic ultrasonic(13,12);

const int RForward = 0;
const int RBackward = 180;
const int LForward = 180;
const int LBackward = 0;
const int RNeutral = 93;
const int LNeutral = 92; //constants for motor speed

const int TrigPin = 13;
const int EchoPin = 12;  //Echo pin

const int dangerThresh = 10; //threshold for obstacles (in cm)
int leftDistance = 0;
int rightDistance = 0; //distances on either side

Servo HeadServo; 
Servo LeftServo;
Servo RightServo; //declare servos

long duration; //time it takes to recieve PING))) signal

void setup()
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
  HeadServo.attach(6); //attach servo to proper pins
  HeadServo.write(90); //centre head servo

void loop()
  int distanceFwd = (ultrasonic.Ranging(CM));
  Serial.begin( 9600 );
Serial.print( ultrasonic.Ranging(CM) );
Serial.println( "cm" );

  if (distanceFwd>dangerThresh) //if path is clear
    RightServo.write(RForward); //move forward
  else //if path is blocked
    rightDistance = ultrasonic.Ranging(CM); //scan to the right
    leftDistance = ultrasonic.Ranging(CM); //scan to the left
    HeadServo.write(90); //return to center

void compareDistance()
  if (leftDistance>rightDistance) //if left is less obstructed
    RightServo.write(RForward); //turn left
  else if (rightDistance>leftDistance) //if right is less obstructed
    RightServo.write(RBackward); //turn right
   else //if they are equally obstructed
    RightServo.write(RBackward); //turn 180 degrees

long ping()
  // Send out PING))) signal pulse
  pinMode(TrigPin, OUTPUT);
  digitalWrite(TrigPin, LOW);
  digitalWrite(TrigPin, HIGH);
  digitalWrite(TrigPin, LOW);
  //Get duration it takes to receive echo
  pinMode(TrigPin, INPUT);
  duration = pulseIn(TrigPin, HIGH);
  //Convert duration into distance
  return duration / 29 / 2;

Moderator edit: code tags

What is your power consumption? Measure it with a multimeter on usb and compare to on a 9v, if its too high the onboard regulator of the uno will not be able to provide enough power

tmcraig: all my code is wrote(using what you linked), it works when on usb just not via a brandnew 9v battery.

9V batteries are not designed for high current use. Running any kind of motor off of them is going to result in problems. You need to get a real source of current like a LiPo or a bank of 6 AA's.

thanks for the responce guys. ill buy a multimeter over the weekend to test. and 6 pack of AA's.

as i said totally new to electronics, so it confused me when usb powered the arduino and the 3 servos and ping sensor. any tutorials on basics on working out power needed