servo problem

3 servo’s, 3 Pushbuttons (the pushbutton is actually a contact on a relay)
When the pushbutton pin is grounded the servo is suppose to rotate 180 for a few seconds and return

I only have one servo connected right now

Sketch works fine when I ground the pin (18) of the pushbutton

As soon as I connect the Pin 18 (the first pushbutton) to the relay the servo operates and keeps operating every 30 seconds.
With a mulit meter there are no shorts between the relay contacts no grounds

Any ideas

// Include the Servo library 
#include <Servo.h> 
#include <TimerThree.h>
// Declare the Servo pins 
const byte servoPin1 = 9; 
const byte servoPin2 = 10; 
const byte servoPin3 = 11; 

const byte mosfet=22;

const byte interruptPin1 = 18; //push button 1
const byte interruptPin2 = 19; //push button 2
const byte interruptPin3 = 20; //push button 2

//flags to push buttons interrupts
volatile boolean servo1Button=false;
volatile boolean servo2Button=false;
volatile boolean servo3Button=false;

//count 30 sec variable
volatile byte count=0;

// 5 sec delay counter for each servo
volatile byte countServo1=0;
volatile byte countServo2=0;
volatile byte countServo3=0;

// Create servo objects 
Servo Servo1,Servo2,Servo3; 
void delay30Sec(){
  //counter for each element according to servo#ButtonValue
      //mosfet delay counter update
  if(count==30 && (!servo1Button) && (!servo2Button) && (!servo3Button)){
void servo1Interrupt(){
  //only start sequence if servo is at rest position (0 degrees)
  void servo2Interrupt(){
   void servo3Interrupt(){
void setup() { 
   // We need to attach the servo to the used pin number 
    //set the mode of the pins..
    //note that the buttons are used with negative logic as the internal pullup resistors are used
  pinMode(interruptPin1, INPUT_PULLUP);
  pinMode(interruptPin2, INPUT_PULLUP);
  pinMode(interruptPin3, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin1), servo1Interrupt, FALLING);
  attachInterrupt(digitalPinToInterrupt(interruptPin2), servo2Interrupt, FALLING);
  attachInterrupt(digitalPinToInterrupt(interruptPin3), servo3Interrupt, FALLING);

void loop(){ 
  if(servo1Button || servo2Button || servo3Button){
        if(servo1Button && countServo1==0){
        if(servo2Button && countServo2==0){
        if(servo3Button && countServo3==0){

If it works when the pin in grounded but not when a relay contact is connected it seems likely that the problem is in the wiring. A circuit diagram would probably help. Are the relay ground and Arduino ground connected together?


All grounds are common and I dont have the relay coil connected yet. I just short the pins on the relay to test.
Im using this relay shouldnt make a difference
Qubino Z-Wave Dry Contact Relay

Here is a diagram

IMG_20180918_0001.pdf (91 KB)

'The Qubino Flush 1D Relay has an extremely low power consumption of just 0.4 W.'
0.4W - with 5V that's 80mA. Tough to get that out of an output pin, Throw a small transistor in (2N2222), high-side loaded with about a 1k current-limiting resistor between the base and pin 18.

Thanks for the response but thats not the problem. I have no intension on driving the relay with the Arduino pin.
My problem is that as soon as I connect the pin for the push button to the NO contacts of the relay the servo motor operates every 30 seconds when It should only operate once when I close the relay contacts

Sorry, only looked at your diagram before.

Sketch works fine when I ground the pin (18) of the pushbutton

You say that it works when you ground this pin? Pin is set for INPUT_PULLUP which means it will remain HIGH until some event causes it to go LOW. it is unclear from your code or diagram what will cause pin 18 to go LOW. If it is the action of the relay and the relay is controlled by mosfet (which gets set HIGH in loop()), mosfet is only reset in delay30Sec() after 30 seconds and ONLY if none of the servo buttons are true at that point in time.

Does this sound about right?

I didn't include the pin for the mosfet because I'm not using it yet. I will eventually use pin 22 to power the mosfet and then power the servo. I only have one servo connected and was just testing it by shorting out the relay contact. So like I said without the connections to the relay connecting pin 18 to ground operates the servo like it should in the sketch. When I connect pin 18 to the relay contacts the servo will run turning 180 degrees and back like it should then idle for 30 sec and it will keep doing that without any input from me or until I remove the lead from the relay contact. I don't know what going on with the relay contacts. I have no power connected to the relay coil and I know the relay contacts are NO not NC.

op's diagram:

Sorry I dont know what op"s is

OP is the Original Poster. In this case, you.
In reply #2 you posted a link to a PDF. ChrisTenone simply posted it in a format that we could see from the forum.

Thanks Vince. Patty, sorry for the short hand. I sometimes forget that not everybody eats, sleeps and dreams forum. :\

Found the problem.
Switched out the Arduino board and everything works
I found that If I left it long enough even with the pin (pushbutton) not connected to anything the servo would all of a sudden rotate
Must have being a defective board

Get a stiff toothbrush and scrub around all the solder connections. Sometimes it's just a bit of garbage on the board. Especially bad in dusty, humid environments. Dust accumulates, gets moist from humidity and causes occasional shorts.

I now have another problem and this time it cant be the board.
Its with pin 22 (for the mosfet to power servo's)
Pin 22 is suppose to go high for 30 seconds when there is input on any of the pushbuttons then back to low
What is happening on a rest of the board
Pin 22 goes high for 30 seconds then low. Stays low for seams like a random amount of time (less then 2 min) then goes High for several min then low. Its seems to be random high and low. This is without any input.
Whats going on

New code or same?