Go Down

Topic: servo is not working properly (Read 573 times) previous topic - next topic

lucky1993

HI ,

I am new guy in robotics . i have connected a servo with arduino and two IR leds RX ( receiver ) and TX ( transmitter ) . but the problem is the servo is moving on its own . its moving and coming back to its orginal position on its own .

this is the skech ..

#include <Servo.h>
Servo myservo;
int LedPin = 13;
int inputPin = 1;
int ir1 = 70;
int obs = 0;
int pos = 0;
int turn = 0;

void setup()
{
   myservo.attach(9);
pinMode(LedPin, OUTPUT);
Serial.begin(9600);
}

void loop()
{
if (turn == 1)
{
Serial.print("\n");
Serial.print("I am turning! :/");
digitalWrite(LedPin, HIGH);
delay(1000);
digitalWrite(LedPin, LOW);
Serial.print("I am not turning anymore! *sigh* \n");

turn = 0;
myservo.write(-90);
delay(1500);
}


int ir2 = analogRead(inputPin);


if(ir1 < ir2-10 &&   obs != 1)
{
 obs = 1;
 ir1 = ir2;
if (turn != 1)
{
myservo.write(90);
 delay(1500);
 turn = 1;
}


}

if (ir1 > ir2+10 && obs == 1)
{
 obs = 0;
 ir1 = ir2;
}

Serial.print(obs);
Serial.print("\n");
}


while serial monitering it is showing that transmitter is working on its own .. guyz plsss help me out ...  :(  :(  :(

vinceherman

#1
Oct 26, 2010, 05:23 pm Last Edit: Oct 26, 2010, 05:27 pm by vinceherman Reason: 1
Hi Lucky,
First thing, can you go back an modify your post?
Highlight the sketch and then click the # button on the editor.
This puts the sketch into a code window that makes it easier to read.

Second, your angles for the servo.write need some help.
The angle range is 0-180, not -90 to 90
90 centers the servo.
0 is full left
180 is full right
Anything less that zero is treated as zero.

AWOL

Also make sure you've got the grounds connected.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

vinceherman

Quote
Also make sure you've got the grounds connected.

Quote
I don't think you
connected the
grounds, Dave.

I still chuckle every time I read this!

Go Up