Go Down

Topic: Rc Servo for motion controlled fan (Read 177 times) previous topic - next topic

Kroran

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
Code: [Select]
// 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

groundFungus

What is the power source for the servo?

slipstick

If it works with tiny moves (as in Sweep) but not with larger moves (as in your code) it's almost certainly a power problem.

If you'd actually said anything about how you were connecting and powering that large power-hungry servo it would have been helpful.

Steve

Kroran

was powering it through arduino uno, was that not a good choice?

TheGrislyBear

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.

meltDown

#5
Aug 12, 2019, 05:33 pm Last Edit: Aug 12, 2019, 05:46 pm by meltDown
5V is not going to cut it.
Well according to this it's 4.8 to 6.8V, so 5 volts is ok, but it's silent on the current.

Even a micro servo can draw 800mA or so at stall, so this big one will need a good couple of amps.

edit: according to my calcs, based on numbers in that link, best part of 3A.

edit edit: That link does actually give stall current, almost 2A at 5V.








slipstick

There's nothing much wrong with the code but most of those 25Kg servos have stall currents of well over 2A and work best on 6V or more.

The 5V pin on an Arduino can safely supply no more than 400mA.

5 x 1.2V NiMH batteries would work or a separate power supply of 6V and at least 2A.

Steve

vinceherman

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.

Kroran

There's nothing much wrong with the code but most of those 25Kg servos have stall currents of well over 2A and work best on 6V or more.

The 5V pin on an Arduino can safely supply no more than 400mA.

5 x 1.2V NiMH batteries would work or a separate power supply of 6V and at least 2A.

Steve
what is a stall current?
tried googling it and i cant make heads or tails of it

so I do need at least 1.5-3 amps? or is 3 amps to high?

meltDown

Stall current is the current a motor draws when it gets stuck, but it also draws that momentarily each time it starts up.

If your supply can supply more than required, there's no harm done. The motor will only draw what it needs.

Downside of a too-powerful supply is of course unnecessary cost and perhaps physical size.


Kroran

Stall current is the current a motor draws when it gets stuck, but it also draws that momentarily each time it starts up.

If your supply can supply more than required, there's no harm done. The motor will only draw what it needs.

Downside of a too-powerful supply is of course unnecessary cost and perhaps physical size.


Thank you so much for your answer it is greatly appreciated

Go Up