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 <= 90; pos += 10) { 
        // in steps of 1 degree
        myServo.write(pos);              
        delay(15);                       
      }
      for (pos = 90; pos >= 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?

  • 8
    As many already have experienced, a 9V block can simply not deliver enough current for powering any significant load. You will have more luck with, for example, a 4- or 6- cell AA battery pack. – StarCat Jun 28 at 6:03
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.

| improve this answer | |
  • you don't like the answer on the duplicate? or why you didn't vote for it? – Juraj Jun 28 at 17:13
  • I missed the duplicate vote. You're right, that would have been better than another answer. – Duncan C Jun 28 at 18:41

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