Am trying to build a motion controlled fan using PIR sensors and a beefy servo the problem is the servo dose not turn in the code, but it does in the sweep example is this a power issue or a code issue?
P.s I have used smaller servo and it works fine
servo is a ANNIMOS 25kg RC Digital Servo
code is
// Servo - Version: Latest
#include <Servo.h>
//Global variables
boolean pirStatus;// see 36
Servo servo;
int servangle = 0; // servo angle variable
int pirNo[] = {3, 4, 5, 6, 7}; // pir pin numbers
int pirPrevLow[] = {1, 1, 1, 1, 1}; // previously low flag set to true
int pirPrevUsed[] = {0, 0, 0, 0, 0}; // has pir been on used before going low
int pirPos[] = {0, 45, 90, 135, 180}; // positions for servo (0-180)
int curPosPir = 0;
int pirPin = 3;
int ledPin = 13;
void setup() { // run once
Serial.begin(9600);//serial port start
servo.attach(2); // assign servo pin
servo.write(90); // put servo at center to begin
for (int i = 0; i < 4; i++) { //local variable(i)( Initialize, condition, increment)
pinMode(pirNo[i], INPUT);
}
pinMode(ledPin, OUTPUT);
delay(10000); // calibrate for about 10 seconds
}
////////////////////////////
//Main LOOP
//////////////////
void loop() {
for (int j = 0; j < 4; j++) { // for each PIR
pirPin = pirNo[j];
pirStatus = digitalRead(pirPin);
if (pirStatus == HIGH) {
digitalWrite(ledPin, HIGH); //th sensors output pin state
if (pirPrevLow[j]) {
servo.write(pirPos[j]);
Serial.println(pirPos[j]);//********
delay(50);
curPosPir = pirPin; // keep current PIR
pirPrevUsed[j] = 1;
}
pirPrevLow[j] = 0; // pir is now not low
}
else {
digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state
pirPrevLow[j] = 1; // pir is now low
pirPrevUsed[j] = 0;
}
} // end j number of pirs loop
}// end infinite loop
It depends on the Servo and sensors. The only difference is the servo though, so the servo you are trying to use now likely has a higher power requirement. What are the specs of the new servo? 5V is not going to cut it.
Kroran:
was powering it through arduino uno, was that not a good choice?
That was a bad choice that leads to the exact behavior you described in your original post.
You want a separate power supply for the servo.
Make sure you use a common ground.