Go Down

Topic: servo is not working properly (Read 1 time) previous topic - next topic


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()
pinMode(LedPin, OUTPUT);

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

turn = 0;

int ir2 = analogRead(inputPin);

if(ir1 < ir2-10 &&   obs != 1)
 obs = 1;
 ir1 = ir2;
if (turn != 1)
 turn = 1;


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


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


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.


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.


Also make sure you've got the grounds connected.

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

I still chuckle every time I read this!

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131