Servo Blinds

Hi all,

Apologies if this is in the wrong section, first post.

Back round info on the home automation

I have a remote controlled switching relay that links up with my iPhone etc… it has two switched live terminals ‘volt free’

By using a servo I want to open my blinds when one input is triggered and close them when another is triggered.

I think i nearly have it by starting off with example sweep, but when i put 3.3V in to either one of my inputs the first always works but when i go to the other my servo goes crazy just twitching.

For example when i have the servo in open position and switch to close it works, then when i go back to open it goes crazy.

I have the Arduino uno board powered currently by usb. Below is the code I’m using . Any help is much appreciated.

/* Sweep
by BARRAGAN http://barraganstudio.com
This example code is in the public domain.

modified 8 Nov 2013
by Scott Fitzgerald

*/

#include <Servo.h>

Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0; // variable to store the servo position
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object

int val; // variable to read the value from the analog pin
}

void loop() {

if (digitalRead(PIN_A5) // read the input pin

) // goes from 0 degrees to 180 degrees ‘open’
// in steps of 1 degree
myservo.write(180); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position

if (digitalRead(PIN_A4) // read the input pin

) // goes from 0 degrees to 180 degrees ‘close’
// in steps of 1 degree
myservo.write(0); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position

}

Welcome to the forum! Please auto-ident your code in the IDE and use the code tags </> so its easy to read

I’m surprised this code even compiles given the extra ‘)’ I suspect what you are aiming for is more like

if  (digitalRead(PIN_A5) {   // opening brace starts block of code to be executed
                                             // if this statement is true
 
   // goes from 0 degrees to 180 degrees 'open'
   // in steps of 1 degree
    myservo.write(180);                // tell servo to go to position in variable 'pos'
    delay(15);
} // closing brace ends the block.

however its still not going to “go in steps of 1 degree” as your comments imply- It will move to 180 degrees as quickly as it can.

Not sure if its the same thing for you, but i remember when i was working with relays to control a outlet i had to make sure that after sending the command to turn on the relay, before moving onto the next, i had to turn off the first and then send the command to the 2nd. Basically i had insure i wasnt sending the commands at the same time if i didnt want them fighting with each over in order to accomplish my tasks..

Not sure if that helps or points you in the right direction, but it was for me..