0

I have made a simple circuit having an IR receiver and a Servo motor. Here is the diagram:

arduino circuit

Red wire: power

Black wire: ground

Orange wire: digital signal

And here's the code:

#include <Servo.h>
#include <IRremote.h>
int receiver = 13;
IRrecv irrecv(receiver);
decode_results results;
Servo myServo;
int pos = 0;
void setup() {
  // put your setup code here, to run once:
  myServo.attach(9);
  Serial.begin(9600);
  irrecv.enableIRIn();
  myServo.write(0);
  delay(200);
}

void loop() { // put your main code here, to run repeatedly: if (irrecv.decode(&results)){

if (results.value== 0xC0000C){
  for (pos = 0; pos &lt;= 90; pos += 10) { 
    // in steps of 1 degree
    myServo.write(pos);              
    delay(15);                       
  }
  for (pos = 90; pos &gt;= 0; pos -= 10) { 
    myServo.write(pos);             
    delay(15);                       
  }
}

} irrecv.resume(); delay(100); }

It rotates the motor 90 degree and back when a button on a remote is clicked.

Here comes the problem: This is working perfectly when connected to my PC, but it doesn't when I connect it with my 9-volt (cuboid shaped) battery. The lights on the Arduino board still light up, but the circuit does nothing when I press the remote button.

I have also observed that the servo vibrates a little bit, but doesn't move.

Is this a problem in my circuit, or is it just that my battery power is low?

DeathVenom
  • 105
  • 4

1 Answers1

1

A 9V battery has both low peak current and low total power (low mAh rating). It is not a good choice for any circuit that draws more than ≈100 mA. (I pulled that number out of thin air, but it's probably a decent guess)

Build a battery pack from 6 AA alkaline cells instead. That will provide enough peak current. Or for much longer run-time, use 6 D sized cells.

Duncan C
  • 5,752
  • 3
  • 19
  • 30