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.
#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
}
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:
#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?