Pages: [1]   Go Down
Author Topic: servo is not working properly  (Read 444 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ...  smiley-sad  smiley-sad  smiley-sad
Logged

Ohio
Offline Offline
Full Member
***
Karma: 0
Posts: 227
Arduino Hexapod
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: October 26, 2010, 10:27:29 am by vinceherman » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25807
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"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.

Ohio
Offline Offline
Full Member
***
Karma: 0
Posts: 227
Arduino Hexapod
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Pages: [1]   Go Up
Jump to: