hello everyone,
I am working on the objective of using IR sensor to control the movement of a servo motor.
The motor responds to the value but not every time.
It moves on random signals but most of the time does not respond. It continuously produces knocking/clicking sounds without any movement of the gear.
The servo independently has been tested and works totally fine.
Any ideas why i am facing this problem ? I am also thinking of timing the signals for better monitoring . How can I do that?
Here are the components :
-
IR sensor - Sharp IR sensor
-
servo motor - tower pro 996R
here is the code :-
#include<Servo.h>
Servo servo1;
int analogPin = 3 ;
int dist = 0 ;
int i =0 ;
void setup() {
Serial.begin(9600);
servo1.attach(9);
// digitalWrite(A3, INPUT_PULLUP);
}
void loop() {
dist = analogRead(analogPin);
dist = map (dist,0,1023,0,20);
Serial.println(dist);
{
for (i=0;i<20;i++)
{
if (dist==i)
servo1.write(dist*10);
}
}
delay(2000);
}