I have made a simple circuit having an IR receiver and a Servo motor. Here is the diagram:
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?
