Go Down

Topic: Continuous Servo/Relay issue (Read 947 times) previous topic - next topic

RobinB

Hi Guys!

Been watching these forums a long time. But now I've got a problem myself that I cannot solve..
I have been trying to make my own automated curtain system for a while now, so I have 1 continuous rotation servo that I let rotate for a while until my curtains are closed. Now this al works, but I wanted to make my servo stop for real, not just by writing angle 90 to the servo. So first I tried to make a switch with use of a transistor, result, I lost a lot of power on the servo.

But I had an relay laying around, so I put that in between. Now I can turn on and off my servo by this relay. Only problem is that once the servo is powered, then turned off by the relay, I't won't turn on again. Only after I disconnect the battery pack from the relay/servo and connect it again it works. But just for one time.

So once I toggled the servo by the relay, It wont toggle on again.

I tried to use a LED instead of the servo to test whether there is something wrong with my batterypack and/or relay, but this works just fine. So I'm really stuck right now, and would really appreciate some help!

Code see below, Fritzing see attachment.

Code: [Select]

#include <Servo.h>
int servoPin = 9;
int incomingByte;
Servo servo;
void setup()
{
Serial.begin(9600);
pinMode(8,OUTPUT);
}
void loop()
{
if(Serial.available()){
incomingByte = Serial.read();
}
digitalWrite(8, HIGH);
if (incomingByte == 49){
digitalWrite(8, LOW);
}
if (incomingByte == 50){
digitalWrite(8,HIGH);
}
servo.attach(servoPin); //Start the servo library on the servoPin
servo.write(95); //left
}


groundfungus

Shouldn't servo.attach be in setup()?

MarkT

You mustn't turn off power to the servo while it is still being sent PWM signals, you risk damaging it or the Arduino.

First detach() the servo from that pin, then digitalWrite (servoPin, LOW), then turn off the power to the servo.
[ I won't respond to messages, use the forum please ]

kf2qd

This is an application for a motor and a couple switches. The when it gets to the end you just turn off the motor.

zoomkat

Setups that might work for curtains.



Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

RobinB

Thanks for you replies and sorry for the late answer, have been away this weekend.
So I tried what you said, I alterd the code to this:

Code: [Select]

#include <Servo.h>
int servoPin = 9;
int incomingByte;
Servo servo;
void setup()
{
  Serial.begin(9600);
  pinMode(8,OUTPUT);
  servo.attach(servoPin); //Start the servo library on the servoPin
}
void loop()
{
  if(Serial.available()){
    incomingByte = Serial.read();
  }
  digitalWrite(8, HIGH);
  if (incomingByte == 49){
    servo.detach();
    digitalWrite(servoPin, LOW);
    digitalWrite(8, LOW);
  }
  if (incomingByte == 50){
    servo.attach(servoPin);
    digitalWrite(servoPin, HIGH);
    digitalWrite(8,HIGH);
  }
  servo.write(95); //left
}



Unfortunately this doesn't change a thing, besides that it would be less harmfull. I tried to understand the schematics above, but I wonder why something that should be so simpel, has to be so difficult. Why can't I just cut the power to the servo, and put it back on?

zoomkat

Quote
Why can't I just cut the power to the servo, and put it back on?


You can, I don't think anybody here is going to stop you.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

RobinB

Yes, I get that. But why do I have to manually reset my servo, by pulling off the batteries, before it can run again?

JB_AU

Zoomkat's Schematics nailed it.

Go Up