Go Down

Topic: servo problem (Read 454 times) previous topic - next topic

Patty0465

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

Code: [Select]
// 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
  if(servo1Button){
    countServo1++;
    }
     if(servo2Button){
    countServo2++;
    }
     if(servo3Button){
    countServo3++;
    }
    if(countServo1==5){
      Servo1.write(0);
      servo1Button=false;
      countServo1=0;
      }
      if(countServo2==5){
      Servo2.write(0);
      servo2Button=false;
      countServo2=0;
      }
        if(countServo3==5){
      Servo3.write(0);
      servo3Button=false;
      countServo3=0;
      }
      //mosfet delay counter update
        count++;
  if(count==30 && (!servo1Button) && (!servo2Button) && (!servo3Button)){
    digitalWrite(mosfet,LOW);
    count=0;
    }
  }
void servo1Interrupt(){
  //only start sequence if servo is at rest position (0 degrees)
  if(!servo1Button){
  servo1Button=true;
  }
}
  void servo2Interrupt(){
  if(!servo2Button){
  servo2Button=true;
  } 
  }
   void servo3Interrupt(){
  if(!servo3Button){
     servo3Button=true;
  }
  }
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);
  pinMode(mosfet,OUTPUT);
 
   Servo1.attach(servoPin1);
   Servo2.attach(servoPin2);
   Servo3.attach(servoPin3);
   Servo1.write(0);
   Servo2.write(0);
   Servo3.write(0);
 
  attachInterrupt(digitalPinToInterrupt(interruptPin1), servo1Interrupt, FALLING);
  attachInterrupt(digitalPinToInterrupt(interruptPin2), servo2Interrupt, FALLING);
  attachInterrupt(digitalPinToInterrupt(interruptPin3), servo3Interrupt, FALLING);

  Timer3.initialize(1000000);
  Timer3.attachInterrupt(delay30Sec);
}
void loop(){
  if(servo1Button || servo2Button || servo3Button){
        digitalWrite(mosfet,HIGH);
        if(servo1Button && countServo1==0){
           Servo1.write(180);
    }
        if(servo2Button && countServo2==0){
           Servo2.write(180);
    }
        if(servo3Button && countServo3==0){
           Servo3.write(180);
    }
    }
    }

slipstick

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?

Steve

Patty0465

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

DKWatson

'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.
Live as if you were to die tomorrow. Learn as if you were to live forever. - Mahatma Gandhi

Patty0465

DKWatson
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

DKWatson

Sorry, only looked at your diagram before.
Quote
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?
Live as if you were to die tomorrow. Learn as if you were to live forever. - Mahatma Gandhi

Patty0465

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. 

ChrisTenone

Atmosphere carries combustion vapors to places where they will do good instead of harm - Mike Faraday's 'History of a Candle': https://www.youtube.com/watch?v=6W0MHZ4jb4A

Whoops ::)

Patty0465

Sorry I dont know what op"s is

vinceherman

#9
Sep 19, 2018, 10:31 pm Last Edit: Sep 19, 2018, 10:31 pm by vinceherman
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.

ChrisTenone

Thanks Vince. Patty, sorry for the short hand. I sometimes forget that not everybody eats, sleeps and dreams forum. :\
Atmosphere carries combustion vapors to places where they will do good instead of harm - Mike Faraday's 'History of a Candle': https://www.youtube.com/watch?v=6W0MHZ4jb4A

Whoops ::)

Patty0465

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

DKWatson

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.
Live as if you were to die tomorrow. Learn as if you were to live forever. - Mahatma Gandhi

Patty0465

#13
Sep 22, 2018, 07:37 pm Last Edit: Sep 22, 2018, 07:40 pm by Patty0465
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

DKWatson

Live as if you were to die tomorrow. Learn as if you were to live forever. - Mahatma Gandhi

Go Up