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