2 proximity sensor and 2 servo
#include <Servo.h>
int tmp1 = 0;
int tmp2 = 0;
int sensorA = 4;
int sensorB = 5;
Servo myservoA;
Servo myservoB;
void setup() {
Serial.begin(9200);
pinMode(sensorA, INPUT);
digitalWrite(sensorA, LOW);
pinMode(sensorB, INPUT);
digitalWrite(sensorB, LOW);
myservoA.attach(9);
myservoB.attach(10);
myservoA.write(0);
myservoB.write(0);
tmp1 = myservoA.read();
tmp2 = myservoB.read();
}
void loop() {
if(digitalRead(sensorA) == HIGH){
Serial.println("NOT DETECTED (A)");
myservoA.write(0);
delay(5);
}else{
Serial.println("DETECTED (A)");
for (tmp1 = myservoA.read(); tmp1 <= 180; tmp1 += 1) {
myservoA.write(tmp1);
delay(5);
}
}
if(digitalRead(sensorB) == HIGH){
Serial.println("NOT DETECTED (B)");
myservoB.write(0);
delay(5);
}else{
Serial.println("DETECTED (B)");
for (tmp2 = myservoB.read(); tmp2 <= 180; tmp2 += 1) {
myservoB.write(tmp2);
delay(5);
}
}
}