can some one give the code for controlling a servo motor with ir sensor with digital read. I mean when the ir sensor reads as "HIGH" servo angle should move from 0 to 90 and when the ir sensor reads LOW the servo should be back to 0.
This is the code i have done.
#include<Servo.h>
Servo myservo;
int ir=5;
int val;
void setup() {
myservo.attach(7);
pinMode(ir,INPUT);
pinMode(val,OUTPUT);
Serial.begin(9600);
// put your setup code here, to run once:
}
void loop() {
val = digitalRead(ir);
if(ir==HIGH)
{
myservo.write(50);
}
else
{
myservo.write(120);
}
}