Blinds controlled by Servo

Hi,
Very new at arduino. I'm trying to control my blinds using a servo and a Zwave relay. Everything works great except I get a hum from the servo (futaba 3003) I was using a basic switch code found on this forum. I want to turn power off to the servo once the blinds Open (button held down) have power come back on when blinds close (button) release. Seems I have to use detatch? Any example code out there? Thank you for your help

Example code for what Zwave ?

Example code to
Press button servo turns 180 the power to servo is off. Release button servo powers up and goes in opposite direction then powers off. Just assume I would have to use detatch..

http://playground.arduino.cc/ComponentLib/Servo

Below is the code I'm using. Works great except the servos buzz. Anyway to insert the detach servo code in this loop to cut power to the servo? Thanks for your help again.

//zoomkat servo button test 7-30-2011
#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
pinMode(button1, INPUT);
servo1.attach(7);
digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
press1 = digitalRead(button1);
if (press1 == LOW)
{
servo1.write(160);
}
else {
servo1.write(20);
}
}

Some servo test code that includes attach and detach to see how the servo responds.

// zoomkat 12-25-13 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// Send an a to attach servo or d to detach servo
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include <Servo.h> 
String readString; //String captured from serial port
Servo myservo;  // create servo object to control a servo 
int n; //value to write to servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7, 500, 2500);  //the pin for the servo control, and range if desired
  Serial.println("servo all-in-one test code 12-25-13"); // so I can keep track of what is loaded
  Serial.println();
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 

      // attach or detach servo if desired
    if (readString == "d") { 
      myservo.detach(); //detach servo
      Serial.println("servo detached");
      goto bailout; //jump over writing to servo
    }
    if (readString == "a") {
      myservo.attach(7); //reattach servo to pin 7
      Serial.println("servo attached");
      goto bailout;
    }    

    n = readString.toInt();  //convert readString into a number

    // auto select appropriate value
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n); 
    }

bailout: //reenter code loop
    Serial.print("Last servo command position: ");    
    Serial.println(myservo.read());
    Serial.println();
    readString=""; //empty for next input
  }
}

thanks for the help so far below is some code I modified. so far it ignores the detach command. If I takeout the delays it runs the detach command servo dies and won't power back on. Please point me in the right direction to get this working. thanks

//zoomkat servo button test

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
pinMode(button1, INPUT);

digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
press1 = digitalRead(button1);
if (press1 == LOW)
{
servo1.attach(7);
servo1.write(160);
delay (1000);
servo1.detach();
}
else {
servo1.attach(7);
servo1.write(20);
delay (1000);
servo1.detach();
}
}

Very new at arduino. I'm trying to control my blinds using a servo and a Zwave relay. Everything works great except I get a hum from the servo (futaba 3003) I was using a basic switch code found on this forum. I want to turn power off to the servo once the blinds Open (button held down) have power come back on when blinds close (button) release. Seems I have to use detatch? Any example code out there? Thank you for your help

Do you still have a relay in your servo setup? If it is on the servo ground wire, it might result in your servo acting strangly, getting hot, and possibly being damaged.

I haven't put the relay in yet right now I've been testing by grounding pin 4 to the ground on the arduino.

Probably 90% of servo problems posted on the forum come from trying to power a servo directly from the arduino or from a 9v battery. Could this be you?

Guilty, I'm powering the servo by the arduino. Do you think I I got an external power supply for the servo that the code would work?

Do you think I I got an external power supply for the servo that the code would work?

Typical arduino/servo external power supply setup.

Thanks for your help and guidance. I will try a external power supply tomorrow and report back. The code does look right to you?

Same problem with external power source :frowning:
Anybody have any idea why the detach command is not working? Or the delay? If I set delay to 15 the detach command works but servo won't attach anymore if I set delay to 1000 the detach command is ignored. Please any help at all?

//zoomkat servo button test

#include <Servo.h>
int button1 = 4; //button pin, connect to ground to move servo
int press1 = 0;
Servo servo1;

void setup()
{
pinMode(button1, INPUT);

digitalWrite(4, HIGH); //enable pullups to make pin high
}

void loop()
{
press1 = digitalRead(button1);
if (press1 == LOW)
{
servo1.attach(7);
servo1.write(160);
delay (1000);
servo1.detach();
}
else {
servo1.attach(7);
servo1.write(20);
delay (1000);
servo1.detach();
}
}

Why are you using attach() and detach() like that? Why not just attach() in setup() and not bother with detach() ?

Detach doesn't depower the servo - it just stops the Arduino sending signals to the servo.

What external power source do you have?

...R

When I use detach it stops the signals which accomplished two things, stopped the servo for making a buss noise and allowed me to open/close blinds manually because the servo at least appears to not have power going to it. These are just Window blinds so precise control of the servo is not required. I used the servo attach because I figured that's how you brought them back from a detach. Like I said I'm very new at this and looking for clues on what I'm doing wrong? Maybe I'll need to accomplish this with a relay? Just seemed detach would do it. External supply is a 12v wall wart type.

OK that use of attach() and detach() makes sense. Just so long as you know the servos are still consuming power - but less than if they are moving a load.

You can't power servos with 12v. They usually only need 5v or 6v. And you don't say how many amps your power supply produces.

...R

Ok I'll go out and get a proper power supply. Do you really think a proper power supply will make the code work?
Thanks for any help you can provide... This seemed like a simple task I've been trying to figure out for a week

The more I look at this the more it seems like the detach command makes arduino lose the value of the pin? It No longer knows if it's HIGH or Low? Comments? Suggestions?

The code you posted tries to detach and reattach the servo, but it's got a design fault which means it won't do what you intend: it attaches the servo every time round loop(), not just when the servo needs to be moved to a different position, with the result that the servo would be attached almost all the time. If you added a bit of code as shown in the state change detection example sketch to detect when the switch state changed and only do the attach/move/delay/detach sequence when it changed, I think that would do what you want.