I think that I have come to a dead end at this project so any help would be appreciated. I've done this two projects individually and they work but I just can't put them together, something is always going wrong. My senzor is 100% accurate when his job to simply turning on and off LED diode and servo is sweeping 90 degrees back and forth like it should be but since I have to make a pretty big code im completely sure problem is in it. Principle is this: when there is something in between IR led and photodiode servo goes 90 degrees and then that "someting" disappears from range servo goes back to 0 position. When nothing is in range servo simply stays in 0 position. Tnx
#include <Servo.h>
Servo myservo;
int senRead = 0;
int limit = 850;
int photodiode = 2;
int pos = 0;
void setup()
{
myservo.attach(9);
digitalWrite(photodiode, HIGH);
Serial.begin(9600);
}
void loop()
{
int value = analogRead(senRead);
Serial.println(value);
if (value > limit)
{
for (pos = 0; pos <= 90; pos += 1)
{
myservo.write(pos);
delay(25);
delay(2000);
}
if (value < limit)
for (pos = 90; pos >= 0; pos -= 1)
{
myservo.write(pos);
delay(25);
delay(2000);
}
}
if (value < limit)
{
myservo.write(0);
delay(2000);
}
}