Connect a motor control board directly to Photon without external power source

Hi,

Without too much thinking involved, I just ordered two of these from eBay

I’m wondering whether I can run these motors directly from pins on the Photon without any other hardware (other than a jumper cable) since they come with a driver board included? Also, can I run them using the ‘servo’ control library? Below is the code I’d like to use, if possible. What do we think?

Thanks!

Tim

Code Starts Here

// ** NOTES
// ** posStatus1 -> Reed switch for openServo -> HIGH=DISENGAGED, LOW=ENGAGED
// ** posStatus2 -> Reed switch for twistServo -> HIGH=DISENGAGED, LOW=ENGAGED
// ** openServo -> Operates string that moves blinds apart -> HIGH=CLOSED
// ** twistServo -> Operates beaded cord that turns blinds -> HIGH=FLUSH
// ** 
// ** 


int servoPin1 = D0; // ToggleOpen servo
Servo openServo;


int servoPin2 = D1; // ToggleTwist servo
Servo twistServo;


int posDetector1 = D2; // ToggleOpen switch input
int posDetector2 = D3; // ToggleTwist switch input


int servoPos = 0; // Reset servo position
int posStatus1 = 0; // Position status variable ToggleOpen
int posStatus2 = 0; // Position status variable ToggleTwist


void setup() {

 
openServo.attach( servoPin1 ); // Attach Toggle servo to D0
Particle.function("toggleBlinds", toggleBlinds);


twistServo.attach( servoPin2 ); // Attach Twist servo to D1
Particle.function("twistBlinds", twistBlinds);


pinMode(posDetector1, INPUT_PULLDOWN); // Check status of ToggleOpen switch
pinMode(posDetector2, INPUT_PULLDOWN); // Check status of ToggleTwist switch


Particle.variable("posStatus1", &posStatus1, INT); // Declare status variable to check ToggleOpen position status
Particle.variable("posStatus2", &posStatus2, INT); // Declare status variable to check ToggleTwist position status


}
 


//  ToggleOpen blinds open/closed

int toggleBlinds(String command) {
    
    
    posStatus1 = digitalRead(posDetector1); // Status of ToggleOpen switch
    posStatus2 = digitalRead(posDetector2); // Status of ToggleTwist switch

 
    if (posStatus1 == LOW, posStatus2 == LOW)  // If OPEN and NOT FLUSH to window then this closes and aligns them
        openServo.write( -360 ), // Pulls curtains together
        delay(500), // Half second pause
        twistServo.write( 180 ); // Twists to close flush to window
        
        
    else if (posStatus1 == LOW, posStatus2 == HIGH) // If OPEN and FLUSH to window then this closes them
        openServo.write( -360 ); // Pulls curtains together
        
        
    else if (posStatus1 == HIGH, posStatus2 == LOW) // If CLOSED and NOT FLUSH to the window, this opens them
        openServo.write( 360 ); // Pulls curtains apart


    else if (posStatus1 == HIGH, posStatus2 == HIGH) // If CLOSED and FLUSH to the window, this opens and aligns them
        twistServo.write( -180 ), // Twists so perpendicular to window
        delay(500), // Half second pause
        openServo.write( 360 ); // Pulls curtains apart
    
    else return (-1);


}


// ToggleTwist blinds open/closed

int twistBlinds(String command) {
    
    
     posStatus2 = digitalRead(posDetector2); // Status of ToggleTwist switch
 
 
    if (posStatus2 == LOW) // If FLUSH TO WINDOW
        twistServo.write( 180 );
 
        
    else
        twistServo.write( -180 );
       

}




// Ignore

void loop() {
}

You might want to look up the power consumption of those motors to see if they don’t surpass the limits of the Photon. If they do, you might need an external source.

It says 5v, which is the output from the VIN pin.

Voltage is (literally) only part of the power equation. More interesting would be the current draw of a motor like this. Any chance you could find those out?

This could be it… although I have almost no idea what it’s saying…

https://grahamwideman.wikispaces.com/Motors-+28BYJ-48+Stepper+motor+notes

I think it’s the first row of the table as that’s the 5v rated one.

or… I think this is likely to be clearer…

Taking the first page into consideration, it’s mentioning 330mA. Vin should be able to provide that, given that you don’t draw huge amounts of power for other applications as well.
A second opinion wouldn’t hurt though :wink:

Thanks Moors7!

Do you have any thoughts on the other question I raised? I either need to run these as ‘Servos’ or I could really do with some guidance on how to run a stepper motor. I’m struggling to find a lot of info out there.

You could definetly do with some extra 47~100µF + 10~100nF caps to reduce the noise these steppers might introduce to the Vin pin when hooking these up to the Photon direct.
You’d also need to have a good USB supply - especially if running more than one of these.
330mA x Steppers + 250mA would be the minimum requirement, I’d say - amd that’s definetly more than a USB port will give you.

As it seems, unlike servos these steppers don’t use PWM signals but you need to control the individual stepper coils direct.
So you’d rather need something like this library
https://build.particle.io/libs/567357bf401a14230f000a22/tab/Stepper.h